Repository navigation
fix: generated media completions retry for hours when the requester refuses the handoff - #199575
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Security-sensitive guard clearedCurrent revision: This PR no longer changes files in the maintainer security-review tier. Separate CODEOWNERS requirements still apply to security policy and enforcement files. |
… waits Treat typed Gateway INVALID_REQUEST and FORBIDDEN refusals as permanent completion delivery failures. The agent handler now sends the existing retryable fact for transient work-start blocks, so a pending workspace still retries. Queue-owned media completions keep re-waking for the follow-up turn, but stop 10 minutes after the first attempt and settle as blocked with the media retained. Co-authored-by: obviyus <[email protected]>
94ade81 to
da73f1d
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR stops completion retries on permanent Gateway refusals while preserving retries for transient session blocks. Example: A generated-image completion receives INVALID_REQUEST with retryable false.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR provides a useful shared retry fix, resolves the earlier queue-ownership finding, and introduces no concrete defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGenerated-media and subagent completions enter the announcement delivery owner, which submits requester turns through the Gateway and translates their results into delivery, retry, or terminal failure. flowchart TD
A[Generated media or subagent completion] --> B[Announcement delivery]
B --> C[Gateway requester turn]
C --> D[Session work-start policy]
D --> E[Typed response and retryability]
E --> F[Shared error classifier]
F --> G[Retry or settle completion]
Technical reviewBest possible solution: Keep refusal classification in the shared announcement owner and preserve the existing session policy’s retryability through Gateway responses. Do we have a high-confidence way to reproduce the issue? Source tracing establishes the failure path: unrecognized Gateway refusals become retryable, and a previously queued media completion keeps observing without the unconfirmed-handoff deadline; no target code was executed during this review. Is this the best way to solve the issue? The patch uses the existing classification and session-policy owners, updates their consumers together, and preserves durable queue ownership without adding another timeout or state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b09f4a04c8ff. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +32, Tests +30. Total +62 across 8 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 15, 2026, 6:59 AM ET / 11:59 UTC (Revision 2). |
A queued completion does not mean the files were delivered; the durable queue can legitimately hold it longer than ten minutes. Refusals now end after one attempt, which is what stopped the incident, so drop the queued-wait cap. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed. A refused generated-media completion handoff ( |
…efuses the handoff (openclaw#199575) ## What Problem This Solves Fixes: a generated image or video completion retries every 1-2 seconds for hours after the requesting run has ended, when the Gateway refuses the completion handoff. In production, two generated-image completion handoffs retried for 4.5 hours. Every attempt got the same `INVALID_REQUEST` refusal from the Gateway. ## User Impact User impact: a refused media completion stops after one attempt instead of retrying every 1-2 seconds until the Gateway restarts. Transient blocks such as a workspace that is not ready yet still retry. ## Why This Change Was Made - **Refusals are terminal.** Completion delivery now treats a typed Gateway `INVALID_REQUEST` or `FORBIDDEN` refusal as a permanent failure. It reads the typed `gatewayCode`, not the message text. `UNAVAILABLE`, transport errors and the existing transient cases still retry. - **Transient work-start blocks stay retryable.** The agent handler returned some short-lived session states as non-retryable `INVALID_REQUEST`, for example "workspace is not ready" or "still initializing". These states already carry a `retryable` fact. The handler now sends that fact in the Gateway error, so completion delivery can tell a transient block from a refusal. Archived and other permanent blocks are unchanged. - **Queued delivery stays under queue ownership.** An earlier revision capped the `queued` wait at 10 minutes; review showed `queued` can legitimately outlast that, so the cap was dropped. Refusals ending after one attempt is what stops the incident. ## Evidence Focused tests (`ocx test`, vitest from source): - New: `subagent-announce-delivery-retry.test.ts`. A typed `INVALID_REQUEST`, alone or as a cause, is permanent. A retryable `UNAVAILABLE` is not. - Updated: the gateway agent handler test now checks that the pending-workspace refusal is `retryable: true` and the archived refusal is `retryable: false`. The direct-delivery test fixture for a pending workspace now uses that retryable shape and still expects `retryable`. - Passing (17 files, 6 shards): the `src/agents/subagents/announce` delivery and media tests, `media-generate-review-delivery.test.ts`, `src/gateway/server-methods/agent.test.ts`, and the gateway agent admission, session persist and session reuse tests. Gates run locally: `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm check:test-mock-exports`, `pnpm check:max-lines-ratchet`, `pnpm check:line-cap-ratchet`, `pnpm check:assertion-safety`, and oxlint plus format on the changed files. Not run: the full build and the packed smoke. The change is limited to TypeScript runtime modules and tests, and it changes no build, packaging or public SDK surface. Hosted CI covers the full build. No live Gateway reproduction was run. The behavior is proven at the retry classifier and at the completion loop with fake timers. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: a generated image or video completion retries every 1-2 seconds for hours after the requesting run has ended, when the Gateway refuses the completion handoff.
In production, two generated-image completion handoffs retried for 4.5 hours. Every attempt got the same
INVALID_REQUESTrefusal from the Gateway.User Impact
User impact: a refused media completion stops after one attempt instead of retrying every 1-2 seconds until the Gateway restarts. Transient blocks such as a workspace that is not ready yet still retry.
Why This Change Was Made
INVALID_REQUESTorFORBIDDENrefusal as a permanent failure. It reads the typedgatewayCode, not the message text.UNAVAILABLE, transport errors and the existing transient cases still retry.INVALID_REQUEST, for example "workspace is not ready" or "still initializing". These states already carry aretryablefact. The handler now sends that fact in the Gateway error, so completion delivery can tell a transient block from a refusal. Archived and other permanent blocks are unchanged.queuedwait at 10 minutes; review showedqueuedcan legitimately outlast that, so the cap was dropped. Refusals ending after one attempt is what stops the incident.Evidence
Focused tests (
ocx test, vitest from source):subagent-announce-delivery-retry.test.ts. A typedINVALID_REQUEST, alone or as a cause, is permanent. A retryableUNAVAILABLEis not.retryable: trueand the archived refusal isretryable: false. The direct-delivery test fixture for a pending workspace now uses that retryable shape and still expectsretryable.src/agents/subagents/announcedelivery and media tests,media-generate-review-delivery.test.ts,src/gateway/server-methods/agent.test.ts, and the gateway agent admission, session persist and session reuse tests.Gates run locally:
pnpm tsgo:core,pnpm check:test-types,pnpm check:test-mock-exports,pnpm check:max-lines-ratchet,pnpm check:line-cap-ratchet,pnpm check:assertion-safety, and oxlint plus format on the changed files.Not run: the full build and the packed smoke. The change is limited to TypeScript runtime modules and tests, and it changes no build, packaging or public SDK surface. Hosted CI covers the full build. No live Gateway reproduction was run. The behavior is proven at the retry classifier and at the completion loop with fake timers.