Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/contribution-check.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/contribution-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
contents: read
pull-requests: read
issues: read
max-turns: 3
max-turns: 4
concurrency:
group: "contribution-check-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/secret-digger-codex.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions containers/api-proxy/guards/common-guard-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ function buildCommonGuardChecks(deps, model) {
{
block: getMaxRunsBlockState(),
isBlocked: block => block && block.maxExceeded,
// Terminal hard cap — non-retryable (see effective-tokens guard above).
statusCode: 403,
// Terminal hard cap: 429 signals the agent has exhausted its allowed
// turns. Unlike transient rate-limits, the Retry-After is absent so
// well-behaved clients won't retry indefinitely.
statusCode: 429,
eventName: 'max_runs_exceeded',
Comment on lines +83 to 87

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schemas updated in eb4fed8.

buildError: buildMaxRunsExceededError,
buildLogFields: block => ({
Expand Down
5 changes: 3 additions & 2 deletions containers/api-proxy/server.token-guards.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('proxyRequest max-runs guard', () => {
jest.restoreAllMocks();
});

it('returns 403 with structured payload when max runs limit is exceeded', async () => {
it('returns 429 with structured payload when max runs limit is exceeded', async () => {
const cycle = createMockUpstreamCycle(https);

// First request completes successfully — consumes the single allowed run
Expand All @@ -251,11 +251,12 @@ describe('proxyRequest max-runs guard', () => {
await flushPromises();

expect(cycle.spy).toHaveBeenCalledTimes(1);
expect(res2.writeHead).toHaveBeenCalledWith(403, expect.objectContaining({
expect(res2.writeHead).toHaveBeenCalledWith(429, expect.objectContaining({
'Content-Type': 'application/json',
}));
const payload = JSON.parse(res2.end.mock.calls[0][0]);
expect(payload.error.type).toBe('max_runs_exceeded');
expect(payload.error.message).toMatch(/Maximum LLM invocations exceeded/);
expect(payload.error.max_runs).toBe(1);
expect(payload.error.invocation_count).toBe(1);
});
Expand Down
4 changes: 2 additions & 2 deletions containers/api-proxy/server.websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ describe('proxyWebSocket security guards', () => {
jest.restoreAllMocks();
});

it('blocks with 403 when max-runs limit is exceeded', () => {
it('blocks with 429 when max-runs limit is exceeded', () => {
process.env.AWF_MAX_RUNS = '1';
applyMaxRunsInvocation(); // consume the single allowed run

const socket = makeMockSocket();
wsProxy(makeUpgradeReq(), socket, Buffer.alloc(0), 'api.openai.com', {}, 'openai');

expect(socket.write).toHaveBeenCalledWith(expect.stringContaining('HTTP/1.1 403 Forbidden'));
expect(socket.write).toHaveBeenCalledWith(expect.stringContaining('HTTP/1.1 429 Too Many Requests'));
expect(socket.write).toHaveBeenCalledWith(expect.stringContaining('"max_runs_exceeded"'));
expect(socket.destroy).toHaveBeenCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion docs/awf-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"maxTurns": {
"type": "integer",
"minimum": 1,
"description": "Maximum number of LLM invocations allowed for a run. When reached, the API proxy rejects subsequent requests with HTTP 403 and error type 'max_runs_exceeded'. See spec §11."
"description": "Maximum number of LLM invocations allowed for a run. When reached, the API proxy rejects subsequent requests with HTTP 429 and error type 'max_runs_exceeded'. See spec §11."
},
"maxRuns": {
"type": "integer",
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/contribution-check-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('contribution-check workflow', () => {
it('has conservative turn limit and appropriate model', () => {
const source = fs.readFileSync(sourcePath, 'utf-8');

expect(source).toContain('max-turns: 3');
expect(source).toContain('max-turns: 4');
expect(source).toContain('model: gpt-5.4-mini');
});
});
2 changes: 1 addition & 1 deletion src/awf-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"maxTurns": {
"type": "integer",
"minimum": 1,
"description": "Maximum number of LLM invocations allowed for a run. When reached, the API proxy rejects subsequent requests with HTTP 403 and error type 'max_runs_exceeded'. See spec §11."
"description": "Maximum number of LLM invocations allowed for a run. When reached, the API proxy rejects subsequent requests with HTTP 429 and error type 'max_runs_exceeded'. See spec §11."
},
"maxRuns": {
"type": "integer",
Expand Down
Loading