Skip to content

fix(platform): back off workflow model-capacity failures - #5107

Closed
tale-code-bot wants to merge 5 commits into
mainfrom
fix/workflow-model-capacity-backoff
Closed

tale-code-bot wants to merge 5 commits into
mainfrom
fix/workflow-model-capacity-backoff

Conversation

@tale-code-bot

@tale-code-bot tale-code-bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

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.failed sentence Selected model is at capacity. Please try a different model., the provider has refused the model, not the account. On main (9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2), #4952 had already done part of this for workflow agent steps:

  • continueOrSettle in backend/core/automations/agent_host.ts settles the parser's typed providerErrorKind as model_capacity. Since fix(platform): back off terminal Codex model capacity #4529 the shared turnEndSchema keeps that kind across exec checkpoints.
  • The stepper holds the re-kick for MODEL_CAPACITY_REKICK_DELAY_MS (60 s). It does this through the existing held start: notBefore, then the automation.v2.agent_turn job's startAfter.

Two gaps remained.

  1. The retry burned the healthy account. planWorkflowAgentRetry (agent_retry.ts) handled model_capacity like any failure, so mergeBurnedHashes added the account the model refused. The re-kick's vend then stepped past that account. The task lane never does this: resolveTaskKickStartArgs in kick-plan.ts excludes no model_capacity run's account.
  2. A held start did not recheck the run's current claim. Its gate, 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_capacity stays 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_error and 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 that claimEpoch. workflowTurnStartRefusal lets such a start run only in two cases:

    • its run is parked on it (the cursor names its exec, with no result), or
    • the walker that held it still holds the run: same claim_epoch and 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: readAgentCursor also returns claimEpoch and leased, the claim and lease as claimRun and heartbeatRun judge 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 in tests/manual/reference/automation/automations.md. domains/automations/spec.md keeps 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 main source (9be5cadac plus 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:
    • holds the re-kick a minute after the model was at capacity, resuming the conversation on the same account;
    • keeps a resumed conversation and its account when the model refuses the resume too;
    • hands its claim to the start it holds.
  • agent_host.start_gate.test.ts:
    • is refused once the walker that held it lost the run without parking it there;
    • cuts a held start whose walker lost the run before any side effect.
  • 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 main since #4952, now pinned for the workflow lane). agent_host.model_capacity.test.ts feeds the pinned Codex JSONL through the real drive window, drain and parser. Only the sandbox transport, harvest and ctx are replaced. It covers:

  • initial and resumed refusals: model_capacity, the conversation handle, no apiErrorStatus, no recordBrokerFailureInternal;
  • a checkpoint written by a real first window and restored by a second window that replays nothing;
  • assistant or tool text carrying the sentence plus another terminal failure: still harness_error;
  • a transient error event followed by a completed turn: no failure.

The stepper suite also pins that exhaustion fails the step (harness_error on 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 in backend:integration. It uses the shim's exec-fenced settle, the real automation.step handler (stepper plus real kick, with a fixed subscription serving and no provider call), real pg-boss jobs and the real automation.agent_turn handler. It records:

  1. stale and duplicate settles are refused, and one settle wakes the run once;
  2. one held start about 60 s out, on the same conversation and account, attempt 1, carrying the walker's claim; the op row deadline runs past the hold;
  3. a duplicate step parks and kicks nothing;
  4. a resumed retry, launched on the same account and refused again, gets attempt 2 with the account still kept;
  5. a run cancelled during the hold refuses its held start: op cancelled, no session, no launch stamp;
  6. a held start whose walker lost the run is refused, and the new walker's run is untouched;
  7. an ordinary harness_error still 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 --noEmit for @tale/platform: exit 0.
  • oxlint --type-aware for @tale/platform: exit 0.
  • vitest (--project server): backend/core/automations, backend/domains/automations, backend/jobs, backend/core/chat/external_turn_shared*, lib/harnesses and backend/core/tasks: 187 files, 2306/2306 tests.
  • Guards: integration-scope, domain-specs, legacy agent flow and fixture, integration-skips.
  • bun run lint:manual, bun run lint:links, and oxfmt --check on the changed files.

Not done, and limits

  • Backend integration was not run locally. This worker has no Docker daemon and no PostgreSQL. Since ci: run the heavy suites only in the merge queue #4607, Backend integration runs 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.
  • A whole-backend/ and lib/ 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.ts needs a browser this worker lacks, and golden-errors.test.ts expects Node 22 (the platform image's pin), while this worker runs Node 24, which accepts regex modifiers. This branch changes nothing under lib/. The PR's Unit check runs the whole suite.
  • Since fix(platform): back off harness rate limits #4952, the 429 envelope exceeded retry limit, last status: 429 also settles as model_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.
  • Immediate starts keep their lenient gate; this change does not alter the first-kick path.
  • Legacy automation upgrade coordination: fix(cli): fence legacy automation runtime cutovers #4579 (fence legacy automation runtime cutovers) closed unmerged, and its content landed on main as 0ee5fd965 ("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

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.
@yannickmonney

Copy link
Copy Markdown
Contributor

The autonomous cycle now lands each task through the merge train instead of its own pull request (.agents/repo.md on train), so this pull request closes. The branch fix/workflow-model-capacity-backoff stays and the task goes on with it: the Reviewer reviews the branch's head on the task and squashes accepted work onto train.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(platform): back off workflow model-capacity failures

2 participants