Repository navigation
fix(platform): back off workflow model-capacity failures - #5107
Closed
tale-code-bot wants to merge 5 commits into
Closed
tale-code-bot wants to merge 5 commits into
tale-code-bot wants to merge 5 commits into
Conversation
A workflow agent step that Codex ended on its terminal "Selected model is at capacity" refusal already settled as model_capacity and held its re-kick for a minute (#4952), but the retry plan still burned the account the model refused, so the re-kick vended past a healthy account. The plan now counts the failure as before and keeps the account in the pool, as the task lane does. The held start re-checked only the run's status and cursor, and accepted a cursor that still named the settled predecessor. A walker that lost the run between its kick and its park left a start that launched an unwaited turn once the hold ended. The kick now hands its walker's claim to a held start, readAgentCursor answers the run's claim and lease, and a held start runs only while its run is parked on it or that claim still holds the run. Starts at once keep the lenient gate.
A backend integration lane drives the persisted retry path of a workflow agent step the model refused for capacity: the shim's exec-fenced settle, the real stepper's re-kick through the real kick (with a fixed serving, so no provider is walked or called), the held start in the protocol queue, and the start job's own refusal. It checks one stored refusal and one wake, one start held a minute that keeps the conversation and the account and counts its attempt, a duplicate step that kicks nothing, a resumed retry refused again, a run cancelled during the hold, a held start whose walker lost the run, and an ordinary failure that still burns its account. The four automation queues are fenced off the harness's workers while the lane runs, so no fixture turn ever launches.
The automation run docs (EN/DE/FR) now say that an agent step the provider ended because the selected model is at capacity retries a minute later, uses one of its three retries, and keeps the previous account eligible. The manual reference names the specs and the backend integration lane that hold it.
Contributor
|
The autonomous cycle now lands each task through the merge train instead of its own pull request ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task: TALE-90 on the Development board, from #4530 (follow-up N1 of the review of #4529).
What was wrong
When Codex ends a turn on its terminal
turn.failedsentenceSelected model is at capacity. Please try a different model., the provider has refused the model, not the account. Onmain(9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2), #4952 had already done part of this for workflow agent steps:continueOrSettleinbackend/core/automations/agent_host.tssettles the parser's typedproviderErrorKindasmodel_capacity. Since fix(platform): back off terminal Codex model capacity #4529 the sharedturnEndSchemakeeps that kind across exec checkpoints.MODEL_CAPACITY_REKICK_DELAY_MS(60 s). It does this through the existing held start:notBefore, then theautomation.v2.agent_turnjob'sstartAfter.Two gaps remained.
planWorkflowAgentRetry(agent_retry.ts) handledmodel_capacitylike any failure, somergeBurnedHashesadded the account the model refused. The re-kick's vend then stepped past that account. The task lane never does this:resolveTaskKickStartArgsinkick-plan.tsexcludes nomodel_capacityrun's account.workflowTurnStartRefusal, is lenient. It accepts a cursor that still names the settled predecessor, because an immediate start can run before its walker's park commits. A held start runs a minute later. If the walker that kicked it lost the run in between (taken over before its park, its park refused by the epoch fence, or dead before parking), the start launched a turn nobody waits on. Effects of that turn's first window were possible before the drive's orphan check cut it.What changes
agent_retry.ts:model_capacitystays counted. The attempt number grows, the progress reset still applies, and a credential-rotation streak ends. The burned-hash list is carried unchanged, so the account the model refused stays in the pool. Real account failures (harness_errorand the rest) still burn their account, and the broker cooldown that a real 429 records stays as it is.stepper.ts: the walker's claim epoch (RunContext.claimEpoch) goes with the retry kick.agent_host.ts: a start the kick holds (startDelayMs > 0) carries thatclaimEpoch.workflowTurnStartRefusallets such a start run only in two cases:claim_epochand a live lease.Otherwise it is refused with
the walker that held it no longer holds the run, before any session, staging, mint or exec. Its op row is finalized as cancelled, and the session is left to the live run. Immediate starts, and payloads without the field, keep the lenient gate.domains/automations/shim.ts:readAgentCursoralso returnsclaimEpochandleased, the claim and lease asclaimRunandheartbeatRunjudge them.automationAgentHost(ctx, org, { resolveServing }): an optional stand-in for the provider walk. Only the integration lane passes one, so the lane runs the real kick without a provider.Docs: one sentence in the agent-retry paragraph of
docs/{en,de,fr}/platform/automations/execution-logs.md. A row intests/manual/reference/automation/automations.md.domains/automations/spec.mdkeeps agent retries under Not yet, so no rule card changes.Unchanged: the 3-retry budget and progress reset, the run's execution guard, the deadline, spend admission at mint, the effect ledger (agent steps park on their cursor), the protocol queue (
automation.v2.*), the writer marker and the lease and epoch fences, the 60 s hold through the existing queue (no second scheduler), and legacy holds. A quarantined run's start is refused because the run is not live, and the onlyIdle release spares non-terminal runs, so a hold is never released.Proof
Old fails, new passes (unit, run locally). I ran the new tests against unchanged
mainsource (9be5cadacplus only the test files). 7 failed and 62 passed (--reporter=verbose). All of them pass on this branch:agent_retry.test.ts: counts a model-capacity failure but keeps the account the model refused in the pool.stepper.agent-retry.test.ts:agent_host.start_gate.test.ts:agent_host.model_capacity.test.ts: the re-kick holds its start with the conversation, the accounts to step past and the walker's claim.Regression locks (pass on
mainsince #4952, now pinned for the workflow lane).agent_host.model_capacity.test.tsfeeds the pinned Codex JSONL through the real drive window, drain and parser. Only the sandbox transport, harvest and ctx are replaced. It covers:model_capacity, the conversation handle, noapiErrorStatus, norecordBrokerFailureInternal;harness_error;errorevent followed by a completed turn: no failure.The stepper suite also pins that exhaustion fails the step (
harness_erroron the wire, the refusal plus(after 4 attempts)as its detail).Real PostgreSQL. The new lane
checkWorkflowModelCapacityRetry(backend/domains/automations/model-capacity.integration.ts) is registered inbackend:integration. It uses the shim's exec-fenced settle, the realautomation.stephandler (stepper plus real kick, with a fixed subscription serving and no provider call), real pg-boss jobs and the realautomation.agent_turnhandler. It records:harness_errorstill burns its account and starts at once.The four automation queues are fenced off the harness's workers while the lane runs.
Local gates on head
229ac726f45a3fd938953c66ceef69e50c994145(its last commit touches only the integration lane, which vitest does not run):tsc --noEmitfor@tale/platform: exit 0.oxlint --type-awarefor@tale/platform: exit 0.--project server):backend/core/automations,backend/domains/automations,backend/jobs,backend/core/chat/external_turn_shared*,lib/harnessesandbackend/core/tasks: 187 files, 2306/2306 tests.bun run lint:manual,bun run lint:links, andoxfmt --checkon the changed files.Not done, and limits
Backend integrationruns only in the merge queue, so the new lane's first real-PostgreSQL run is the queue's. Its records name the run, job and op facts they compare.backend/andlib/vitest sweep did not finish within 20 minutes on this worker, so it left no summary. Before the cut it printed only failures outside this change:render_fetch.test.tsneeds a browser this worker lacks, andgolden-errors.test.tsexpects Node 22 (the platform image's pin), while this worker runs Node 24, which accepts regex modifiers. This branch changes nothing underlib/. The PR's Unit check runs the whole suite.exceeded retry limit, last status: 429also settles asmodel_capacity. Following the task lane, it now keeps its account in the stepper's soft exclusion, while the broker cooldown for that 429 is recorded as before.mainas0ee5fd965("fix: complete safe managed release upgrades", 2026-10-09). On 2026-10-29 I found no open pull request that repairs the legacy upgrade or touches these files. This change leaves the quarantine, protocol queues and writer fence as they are.Closes #4530