Repository navigation
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 maintainer review before merge. Reviewed September 28, 2026, 10:36 PM ET / September 29, 2026, 02:36 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR changes durable context-engine turn finalization to commit the accepted session first, then offer bounded retries to other pending sessions before maintenance runs. Merge readiness✅ Ready for maintainer review Current main still has the reported starvation path. The branch has a focused regression test and credible Gateway before-and-after proof; I found no blocking patch defect. Priority: P1 Review scores
Verification
How this fits togetherThe agent harness records accepted turns in a per-agent SQLite outbox. Finalization sends ready turns to the selected context-engine plugin and schedules maintenance after acknowledged commits. flowchart LR
A[Accepted agent turn] --> B[Durable outbox]
B --> C[Drain accepted session]
C --> D[Retry other sessions]
D --> E[Context engine commit]
E --> F[Post-turn maintenance]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +24, Tests +65. Total +89 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the session-scoped finalization behavior with its regression coverage; keep global orphan recovery tracked separately in #135628. Do we have a high-confidence way to reproduce the issue? Yes. The PR records a current-main Gateway baseline with 16 stale admitted sessions and a new ready turn that remains uncommitted; current source supports that mechanism. Is this the best way to solve the issue? Yes. The repair stays with the existing finalization and outbox owners, prioritizes the accepted turn, and retains a bounded opportunity for other sessions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4187710037fc. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
63b1db8 to
d8f58c0
Compare
…ext-engine-finalize-drain
|
Landed in 5360b70. Thanks @ericcaiwx-star for the fix, and @Kaspnov for the detailed report and outbox analysis that pinned down the unscoped finalize drain. |
…ale (openclaw#160153) Related: openclaw#156425 ## What Problem This Solves Fixes: a successfully accepted durable context-engine turn can remain uncommitted when unrelated sessions already fill the global outbox drain window. ## User Impact The accepted turn now commits in the same turn and can start post-turn maintenance even when other sessions have stale admitted rows. Ready turns from idle sessions still receive a bounded retry opportunity; this does not change the broader orphan-recovery policy tracked in openclaw#135628. ## Why This Change Was Made Accepted-turn finalization previously used one global drain. Sixteen older unrelated sessions could consume its full budget before the newly accepted row was considered. Finalization now drains the accepted session first. It then offers one bounded retry to each of up to 16 other pending sessions, preserving the existing cross-session recovery opportunity without immediately retrying a failed row from the accepted session. Maintenance remains coalesced once per committed session after draining finishes. ## Evidence - Current-main pre-fail at `a709790e7808e5d833fc75a73c6614ab364f943e`: with 16 unrelated admitted sessions ahead of one accepted ready turn, the accepted session's `commitTurn` was called 0 times (expected 1). - Exact-head regression at `d8f58c0df5533ea39fb06c57d45ba8df37f539c4`: the combined case commits the accepted session first and then commits a ready turn from another session while 15 unrelated admitted sessions are also queued. - Owner and sibling tests: `node scripts/run-vitest.mjs src/agents/harness/context-engine-turn-attempt.test.ts src/agents/harness/context-engine-turn-outbox.test.ts` passed 37/37 tests in 39.02 seconds. - Existing failure semantics remain intact: the sibling suite still verifies a failed current-session commit stays queued with one attempt before the next run. - Real Gateway proof: a temporary on-disk context-engine plugin with durable transcript semantics and foreground maintenance ran through `chat.send` and `agent.wait`; the redacted verdict was `{"terminalStatus":"ok","lifecycle":["maintain","commit","maintain"]}`. The accepted turn reached plugin `commitTurn`, then post-turn `maintain`, with no production credentials or external targets. - Changed-file checks passed against `upstream/main`, including formatting, core and test type checks, lint, database guards, import-cycle checks, and repository ratchets. - Test-audit authoring gate: the regression owns the observable finalization-order and cross-session-retry contract, fails for the original starvation mechanism, is not duplicated by existing coverage, and adds no test-only production seam. - Independent AutoReview found no P0-P2 issue in the final working-tree repair; its only P1 was explicitly index-only and identified the superseded staged version that lacked the bounded retry loop. - Local focused-test wall time: 39.02 seconds on macOS arm64 with Node 26.7.0 and pnpm 12.5.1. Exact-head CI time is pending. ### Isolated Gateway proof on an Anthropic route A real Gateway (`openclaw --profile <isolated> gateway run`, task-owned home/state/config, loopback port) served `openclaw agent --session-key ... --json` turns. The default model was an `anthropic-messages` provider with id `anthropic` pointed at a local mock server (synthetic key, no real credentials), with `contextPruning.mode: "cache-ttl"` so each successful turn also writes the `openclaw.cache-ttl` marker. The context engine was an on-disk plugin declaring `atomic-idempotent-v1` and recording every `commitTurn` in its own JSONL store. To reproduce the reported outbox state, 16 unrelated sessions were started on turns the mock never answered, and the Gateway was SIGKILLed mid-turn. That left 16 `admitted` outbox rows. The Gateway was then restarted and one new Anthropic turn was sent. Baseline: this branch with only `context-engine-turn-attempt.ts` reverted to `origin/main` (which already contains the openclaw#156611 anchor fix). Candidate: `d4912a099927`. | Scenario | Baseline | Candidate | | --- | --- | --- | | Clean state, Anthropic route | committed | committed | | Clean state, OpenAI chat-completions route (control) | committed | committed | | Clean state, provider returns HTTP 400 (control) | not committed, no outbox row | not committed, no outbox row | | 16 stale `admitted` sessions, new Anthropic turn | `ok` reply, **not committed**; its row stays `ready`, `attempt_count 0` | `ok` reply, **committed** (`user,assistant`); row removed | | 16 stale sessions, provider returns HTTP 400 (control) | not committed, no outbox row | not committed, no outbox row | In both runs the 16 stale rows stayed `admitted`/`0`, and the agent database `user_version` was unchanged (23). The clean-state rows show this is not a duplicate of openclaw#156611: on current main the anchor fix already commits Anthropic turns, and the remaining failure is the unscoped finalize drain. After merging current `origin/main`, the owner and sibling tests passed again: `context-engine-turn-attempt.test.ts` and `context-engine-turn-outbox.test.ts`, 37/37. No overlap with Pash/Sarah changes: neither has commits on the changed files. Thanks to @ericcaiwx-star for the fix and to @Kaspnov for the detailed report and outbox analysis. Not tested: a third-party production context-engine deployment or real user data. The Gateway proof used a local loopback provider, an ephemeral plugin, synthetic transcript data, and no credentials. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #156425
What Problem This Solves
Fixes: a successfully accepted durable context-engine turn can remain uncommitted when unrelated sessions already fill the global outbox drain window.
User Impact
The accepted turn now commits in the same turn and can start post-turn maintenance even when other sessions have stale admitted rows. Ready turns from idle sessions still receive a bounded retry opportunity; this does not change the broader orphan-recovery policy tracked in #135628.
Why This Change Was Made
Accepted-turn finalization previously used one global drain. Sixteen older unrelated sessions could consume its full budget before the newly accepted row was considered.
Finalization now drains the accepted session first. It then offers one bounded retry to each of up to 16 other pending sessions, preserving the existing cross-session recovery opportunity without immediately retrying a failed row from the accepted session. Maintenance remains coalesced once per committed session after draining finishes.
Evidence
c0196aec9eb22dde60d1d36616d9d8e6d41fcbd4: with 16 unrelated admitted sessions ahead of one accepted ready turn, the accepted session'scommitTurnwas called 0 times (expected 1).d8f58c0df5533ea39fb06c57d45ba8df37f539c4: the combined case commits the accepted session first and then commits a ready turn from another session while 15 unrelated admitted sessions are also queued.node scripts/run-vitest.mjs src/agents/harness/context-engine-turn-attempt.test.ts src/agents/harness/context-engine-turn-outbox.test.tspassed 37/37 tests in 39.02 seconds.chat.sendandagent.wait; the redacted verdict was{"terminalStatus":"ok","lifecycle":["maintain","commit","maintain"]}. The accepted turn reached plugincommitTurn, then post-turnmaintain, with no production credentials or external targets.upstream/main, including formatting, core and test type checks, lint, database guards, import-cycle checks, and repository ratchets.Isolated Gateway proof on an Anthropic route
A real Gateway (
openclaw --profile <isolated> gateway run, task-owned home/state/config, loopback port) servedopenclaw agent --session-key ... --jsonturns. The default model was ananthropic-messagesprovider with idanthropicpointed at a local mock server (synthetic key, no real credentials), withcontextPruning.mode: "cache-ttl"so each successful turn also writes theopenclaw.cache-ttlmarker. The context engine was an on-disk plugin declaringatomic-idempotent-v1and recording everycommitTurnin its own JSONL store. To reproduce the reported outbox state, 16 unrelated sessions were started on turns the mock never answered, and the Gateway was SIGKILLed mid-turn. That left 16admittedoutbox rows. The Gateway was then restarted and one new Anthropic turn was sent. Baseline: this branch with onlycontext-engine-turn-attempt.tsreverted toorigin/main(which already contains the #156611 anchor fix). Candidate:d4912a099927.admittedsessions, new Anthropic turnokreply, not committed; its row staysready,attempt_count 0okreply, committed (user,assistant); row removedIn both runs the 16 stale rows stayed
admitted/0, and the agent databaseuser_versionwas unchanged (23). The clean-state rows show this is not a duplicate of #156611: on current main the anchor fix already commits Anthropic turns, and the remaining failure is the unscoped finalize drain.After merging current
origin/main, the owner and sibling tests passed again:context-engine-turn-attempt.test.tsandcontext-engine-turn-outbox.test.ts, 37/37.No overlap with Pash/Sarah changes: neither has commits on the changed files.
Thanks to @ericcaiwx-star for the fix and to @Kaspnov for the detailed report and outbox analysis.
Not tested: a third-party production context-engine deployment or real user data. The Gateway proof used a local loopback provider, an ephemeral plugin, synthetic transcript data, and no credentials.