Repository navigation
fix: keep gateway running when native completions hit database contention - #158286
fuller-stack-dev merged 19 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 25, 2026, 7:50 PM ET / 23:50 UTC (Revision 7). ClawSweeper reviewWhat this changesThe branch moves Codex native subagent completion reads and persistence through database workers, retains completion custody through retries, and updates Plugin SDK guidance and regression coverage. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 6 items remain The earlier replacement-during-read finding is addressed, and the linked SQLite observations support the contention repair. A receipt-free completion from a cold registry can still adopt a replacement task before its first worker snapshot, so the public SDK authority rule needs resolution before merge. Priority: P1 Review scores
Verification
How this fits togetherCodex app-server sends child completion events to OpenClaw's bundled Codex plugin. The plugin checks and persists the associated task in SQLite, then asks the Plugin SDK to announce the result to the parent session. flowchart LR
A[Codex child completion] --> B[Native completion monitor]
B --> C[SQLite task worker]
C --> D{Original assignment current?}
D -- Yes --> E[Persist delivery status]
E --> F[Parent announcement]
D -- No --> G[Reject stale completion]
Decision needed
Why: The branch knowingly preserves a best-effort legacy route, while requiring a receipt could affect existing public SDK callers; contributor discussion does not settle the authority and compatibility tradeoff. Before merge
Findings
Agent review detailsSecurityNeeds attention: A cold receipt-free completion can derive task authority from a successor before final announcement; no dependency, credential, or supply-chain changes were found. PR surfaceSource +368, Tests +1128, Docs +14. Total +1510 across 28 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Bind persisted completion results to a producer-held assignment receipt, retain a documented compatibility path for existing SDK callers, and reject stale assignments at the final announcement effect. Do we have a high-confidence way to reproduce the issue? Yes. The linked baseline trace shows the SQLite contention exception escaping the old completion claim path, which remains in current main; this reviewer did not execute the fixture. Is this the best way to solve the issue? No. Worker-backed persistence addresses the blocking read, but the receipt-free cold path still needs producer-bound authority or an explicit, documented compatibility decision. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 52c7502c8613. LabelsLabel changes: No label changes. Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
The P1 receipt-free assignment race is fixed in The unchanged production path reproduced an incorrect replacement delivery. Both complete SDK test files now pass 44/44, and independent source-blind validation passes seven clauses across eight private-SQLite scenarios through the public SDK and actual announcement dispatcher. Allowed calls deliver the exact payload once; replacement and inserted tasks receive zero transport calls and remain unchanged. Only the final transport is synthetic. Independent review is clean through P2. The updated PR Evidence section links the executable fixture, red/green output, raw final-effect observations and SHA-256 manifest, all fetched and verified after publication: https://gist.github.com/fuller-stack-dev/7fb9d6e7c8eb81c581abcbadd40a3221 @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Addressed the cold-assignment finding on The unchanged public SDK/private-SQLite reproduction delivered an old payload after a cold same-run replacement. The automated red failed replacement/removal/insertion and passed four allowed controls. Final SDK tests pass 49/49, native snapshot tests 4/4, and the integrated lifecycle fixture passes. Independent review is clean through P2. The linked evidence now includes all seven cold delivery scenarios at the real SDK/announcement boundary, including a never-created database. Two initial validator deadline failures and their cleanup/diagnostic evidence are retained honestly in the report. Legacy cold calls use their first authoritative SQL observation. They cannot reconstruct a producer identity replaced before that observation; callers needing that stronger guarantee already carry Final source hashes, contract, raw observations and review. The full staged/published tree and canonical ancestry were verified. Previous head CI passed; the corrected head has its own running CI. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer decision for the completed review of The review correctly identifies the compatibility limit: an initially unloaded, receipt-free call can select a same-run replacement committed before its first SQL observation. We explicitly accept that limit for this legacy API. The first observation is the selection point; this PR does not claim invocation-time producer identity without a producer receipt. The PR body and source comment already document it. Native Codex completion passes its retained The review confirms the earlier replacement-during-preparation finding is addressed. Its remaining request for zero delivery after an unknown pre-snapshot reassignment would impose a stronger contract than the chosen legacy compatibility policy. That request is declined for this PR; no claim is made that the pre-snapshot window is closed. The published real-SQLite proof and its original validator-timeout qualifications remain unchanged. |
|
Merged via squash.
|
…tion (openclaw#158286) * fix: keep native completions alive through task database contention * test: await native completion persistence in custody fixtures * fix: preserve completion retries during receipt validation * fix: release replaced native completion assignments * test: observe native completion through call-through spies * test: preserve thread metadata in SQLite cleanup fixture * test: order session read revocation after authority capture * chore: align SQLite fixture for canonical merge * fix: retain implicit completion assignment across async reads * Align overlapping test fixtures for upstream integration * fix: retain cold task selections before completion preparation
What Problem This Solves
Fixes a gateway exit when a Codex native subagent completion encounters task-database contention.
User Impact
Completion persistence waits without blocking the gateway event loop. Temporary failures retain the result for recovery, and an accepted delivery is not sent again when its acknowledgement fails.
Why This Change Was Made
The error handler queried the same unavailable store again, allowing its recovery attempt to reject detached work. Completion attempts now retain ownership through persistence and retries, including acknowledgement after retry exhaustion. Callers without an explicit assignment receipt retain the first usable assignment before waiting for read preparation. Cold state takes one asynchronous snapshot, and genuinely absent state remains a supported empty discovery result. Current assignment checks still run before delivery. Metadata changes and unrelated activity do not block completion. Changes that precede a cold caller's first observation require an explicit producer receipt to distinguish; legacy callers remain best effort. Default task reads and exact-assignment writes use existing database workers. Late receipts and retired owners are rechecked after awaited writes. If an assignment is replaced during persistence, its old completion attempt releases custody promptly. Temporary failures on an unchanged assignment still retry; asynchronous lifecycle transitions preserve the existing assignment-receipt rules.
Evidence
Final published head:
e5ab1ae8361215e708b91fe0775375d00b8ed143, incorporating canonical main8681a848844a05afd0f944c1ad1900332d5d80bc. The final tree matches the independently reviewed correction and preserves shared history.Final source-blind report, raw observations, executable fixture and SHA-256 manifest.
Manifest, raw baseline failure, original reproduction recovery, final runtime results and executable fixture.
sessions.createreturning false without the RPC reason. The group had passed 162/162 on the preceding run. The one same-group, two-worker local replay on481ecd09finished with 160 passed, one failed and one platform skip in 1029.55s. Both original failures passed, in 10.569s and 13.087s. A different WebChat startup-recovery fixture failed at line 214 because only one of two started turns had reached its followup queue before cancellation/recovery release. The existing IPv4-alias case skipped because 127.0.0.2 is unavailable on this Mac. The replay used macOS/Node 24.20.0, while CI used Linux/Node 24.19.0. No root cause or repair is established, and the original cases passing locally is not claimed as a fix. No retries, assertion changes or timeout increases were made. These RPC paths do not call the new SDK resident-capture helpers. The final candidate has a new substantive SDK correction and awaits its own hosted CI.bc55bbpassed CI36199624948; final corrected-head hosted CI is pending. Scoped type-aware lint, formatting and diff checks pass.Validation limitations:
pnpm buildand the repository type-check wrapper reject this host's required canonical pnpm shared-store compiler links before compiling the candidate. Direct pinned TypeScript checks reach an existingResponsesWSClientOptions/headerserror inpackages/ai/src/transports/openai-responses-websocket.ts. That path and its dependencies are unchanged. Live gateway deployment has not been performed.Test audit and scope
Audited the entire contents of these files, including fixtures, helpers, imports, assertions and cleanup:
extensions/codex/src/app-server/native-subagent-completion-delivery.contention.test.tsextensions/codex/src/app-server/native-subagent-monitor.test.tsextensions/codex/src/app-server/native-subagent-monitor.completion-delivery.test.tsextensions/codex/src/app-server/native-subagent-monitor.custody.test.tsextensions/codex/src/app-server/native-subagent-monitor.history-owner.test.tsextensions/codex/src/app-server/run-attempt.native-followup-custody.test.tsextensions/codex/src/app-server/native-subagent-monitor.close.test.tsextensions/codex/src/app-server/native-subagent-monitor.rotated-parent.test.tsextensions/codex/src/app-server/native-subagent-monitor.submission-recovery.test.tssrc/plugin-sdk/agent-harness-task-runtime.test.tssrc/plugin-sdk/agent-harness-task-runtime.selection.test.tssrc/plugin-sdk/agent-harness-task-runtime.worker.test.tssrc/tasks/task-registry-snapshot-read.test.tssrc/agents/agent-harness-native-custody.test.tsextensions/codex/src/app-server/native-subagent-monitor.test-support.tstest/non-isolated-runner.sqlite-fixtures.ts, plus its unchanged outer test and shutdown helpersrc/gateway/server-plugin-in-process-dispatch.session-reads.test.tsKept distinct ownership, history, receipt and failure cases. Removed one mocked selector case duplicated by real-registry coverage and three repeated assertions with no intervening work. Replaced a clone-call-count assertion with single-owner delivery and ambiguous-owner rejection. Existing asynchronous tests now await actual persistence attempts; exhaustion checks prove custody remains retained until failed-status settlement and no extra delivery occurs. The new retry regression uses fake timers. The added custody-file audit retains all seven distinct scenarios and every assertion, including child completion after parent host closure. Three scheduler-turn guesses now await turn acceptance or actual completion; the fourth was unnecessary after acknowledged
sessions_yield. Teardown aborts and joins owned work before closing the fixture. Prototype-method observations still call the real method with its original receiver. The final shared helper uses default call-through spies and joins their actual returned promises, removing its two unbound-method suppressions. The additional three files retain all close, rotated-parent and cold-recovery scenarios. Removed two more immediately repeated assertions without intervening work. New receipt-race cases cover a normal retry during validation, a transient read failure with an existing retry, and foreground receipt recovery followed by detachment. Their fixtures use consistent private requester/turn identities and explicitly retire their own pending delivery authority before disposal. A sequential fixture leak was confirmed by the failing case passing alone, then repaired without changing assertions. The core custody audit retains all 20 cases, covering nine assignment orderings, six history outcomes, two handoff modes and three stale producers. It removes one duplicate promise wait and an early repeated call count while retaining the final exact-once assertion. Teardown joins actual delivery and recovery work and restores the runtime. All 23 support exports have consumers. The SQLite fixture repair preserves every scenario and assertion; its complete generator, outer test and shutdown helper audit found no safe pruning needed. The session-read audit retains all six grant, zero-SQL, merged-profile and revocation cases. It replaces the race-dependent in-flight empty-list expectation with explicit cancellation and preserves the empty-list assertion for a fresh blocked-role request. Real handler execution is joined before projection disposal, and cleanup restores the observer even on errors. The final SDK audit covers both entire touched files and the native snapshot-reader file, retaining all original cases. Its fifteen additional SDK cases exercise distinct assignment transitions through real registry state and the actual announcement dispatcher; the five cold variants protect a distinct initialization path and the snapshot checks preserve strict missing-state and retirement coverage. No further pruning was warranted. New case bodies take 4–12ms after the initial 310ms fixture setup. No valid failing cases were skipped, assertions weakened or timeouts increased.The incident logs identify the escaping contention error and automatic process restart. They do not identify the final historical lock holder. A suspected circular worker-admission deadlock was independently falsified; this patch changes neither coordinator pumping nor global rejection handling.