Repository navigation
fix(gateway): persist response continuations and reject unresolved previous_response_id - #159227
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 28, 2026, 5:22 AM ET / 09:22 UTC (Revision 5). ClawSweeper reviewWhat this changesThe branch stores OpenResponses continuation IDs in SQLite for up to 30 days, scopes bearer IDs with an installation-keyed HMAC, and returns HTTP 400 for unresolved IDs. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 10 items remain Keep open: current main still has the reported continuation failure, while the pinned branch has unresolved compatibility and session-boundary defects. Its after-fix proof does not reach the final agent effect. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway OpenResponses endpoint accepts authenticated HTTP requests and selects an agent session before running a turn. It returns JSON or streaming events, and later requests can use a response ID to select that session again. flowchart LR
A[Authenticated HTTP request] --> B[OpenResponses handler]
B --> C[Response ID lookup]
C --> D[Shared SQLite store]
C --> E[Session authorization]
E --> F[Agent turn]
F --> G[JSON or streaming reply]
F --> D
Decision needed
Why: Both paths worked before this branch; the PR body states a strict direction, but the available discussion does not specifically accept these client-visible compatibility changes or their upgrade behavior. Before merge
Findings
Agent review detailsSecurityNeeds attention: Bearer subjects use a purpose-bound HMAC, but durable response IDs are not fenced to the live session generation. PR surfaceSource +52, Tests +405, Docs +6. Total +463 across 22 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep ordinary continuations in the shared keyed store, preserve authorized stable-session recovery and live Incognito continuation, and fence every stored ID to the current session generation before agent dispatch. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main falls back for an unknown ID, and the pinned branch has direct stable-session, Incognito, and reset-stale paths; this read-only review did not execute them. Is this the best way to solve the issue? No. The shared keyed store is the appropriate persistence owner, but the unconditional 400 changes recoverable existing paths and its stored value cannot identify a replaced session generation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against fa9473b3fcb8. 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 (4 earlier review cycles)
|
c411ca1 to
b6442d8
Compare
b6442d8 to
77ffd16
Compare
77ffd16 to
970cf21
Compare
…evious_response_id Persist previous_response_id mappings in the core keyed store (core:openresponses/response-sessions, 30-day TTL, 5,000 cap) with purpose-bound HMAC bearer scoping, never persist Incognito mappings, commit continuity before terminal publication, keep failed-run errors, and return a uniform 400 for unresolved ids.
970cf21 to
4053d29
Compare
|
Admin-merged at the maintainer's direction at exact reviewed head The red checks (
The root-cause fix for both is being prepared directly on Proof for this PR is in its body: focused OpenResponses and Gateway tests, the keyed-store persistence and restart continuity, and the bearer-scoped HMAC isolation. The final Codex autoreview found no remaining accepted findings. There is no schema change; continuity uses the core plugin-state keyed store. |
The shared HTTP server fixture omitted the Gateway request context required for bearer-scoped OpenResponses continuity after 14f6562 (#159227). Use the existing request-context factory and real config revision projector, matching production wiring while preserving explicit fixture overrides. Production authentication, persistence, and current-authority checks are unchanged. Reproduced all five HTTP 500 failures on pristine main 6aa5242. The existing regression cases pass 34/34 after the fix. On isolated Linux, the failed CI shard plus every harness consumer and OpenResponses suite pass 1179 tests across 65 files; pnpm tsgo:core and formatting also pass. Focused runner wall time: 49.49s before (cold compiler), 17.05s after (cached compiler); these are validation costs, not a performance claim. Independent review found no actionable issues.
## What Problem This Solves Cron exit watcher retry deadlines now use the required Gateway scheduler. A scheduled retry joins startup and failed-start state publication, then the existing watcher owns the long-running child through exit. Cancellation and replacement still preserve exact slot ownership and drain watcher lifecycles. The cutover deletes native timeout handles, `unref` calls, and the unused shell-injection option. No operator configuration or persisted schema changes. Production **+32/-26/net +6**; tests **+101/-38/net +63**. This correctness-driven slice uses the closeout's real deletion offsets. ## Evidence Final head `66d57e0dfa26e242a9c80f415c7f29d65a5721cd`, based on merged main `14f65626bd25cd23182cba98a2b9ca1af6fc5f23` after cron stream merge `2aaf6d41a73e43180334a669315eb68bad1b3173`. Only the exit commit is included. The rebase is patch-identical (`git range-diff` reports `=`), and all three changed files are byte-identical to the tested head below. Existing review and Testbox proof are reused; `git diff --check` passes and the worktree is clean. - Independent Codex autoreview: clean through P2. The committed patch exactly matches the reviewed patch (SHA256 `3ca06c7e52888c92689d9dbc5cebcbb1a18199c1bf3290351d81a14693e81755`). - Exact-head Blacksmith Testbox `tbx_01m3kjwyph0svfjebr22jy7w8q`, run [36399017112](https://github.com/openclaw/openclaw/actions/runs/36399017112), head `80fc468ac824da48ef94423d7a79da316d4ed976`: `pnpm test src/gateway/cron-exit-watchers.test.ts --maxWorkers=1` passed (**28 tests**, **3.75s wall**). - Scoped `node scripts/check-changed.mjs --base 42975a2 -- src/gateway/cron-exit-watchers.test.ts src/gateway/cron-exit-watchers.ts src/gateway/server-cron.ts` passed on the same exact head: **1463.25s wall**, including production and all core test type graphs, format, lint, line ratchets, dead-export scan, and architecture guards. Release-note context: Gateway-owned cron exit retries now share scheduler catch-up and shutdown ownership while child-process settlement remains with its watcher. ### Final inherited-CI classification CI run [36411857535](https://github.com/openclaw/openclaw/actions/runs/36411857535) completed on reviewed head `66d57e0dfa26e242a9c80f415c7f29d65a5721cd`, testing merge tree `80ef6fe243fb9c0c148975007d087c81f1a1a52d` against main parent `fc168b2f6c16312181ce15bcb56d36a14e2c4849`. All six failing test jobs have independent evidence in owners this change does not modify: | Failure | This PR | Matching independent evidence | | --- | --- | --- | | Session rename remains Original session after ordinary Enter | [job 108894925328](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894925328) | Clean main at `251c610735855d2955f9f0f1aa5e4338be18f5e4`: [job 108908250303](https://github.com/openclaw/openclaw/actions/runs/36416233754/job/108908250303). The same parameterized test body fails at line 119 with the same expected committed title and received Original session. Matrix cells differ: this PR uses legacy/Escape; main uses modern/Enter. Both already passed the composition assertions, then execute the identical ordinary Enter, matching patch, list reconciliation, and final rendered-title assertion. | | Manually unread UI state times out waiting for its unread dot | [job 108894925308](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894925308) | Independent MCP [job 108865636156](https://github.com/openclaw/openclaw/actions/runs/36402978963/job/108865636156): same `session-management.unread.e2e.test.ts` case, line 266, unread-dot locator, and 30000ms timeout. | | Canonical skills refresh E2E exceeds its 90000ms timeout | [job 108894929439](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894929439) | Independent questions [job 108880022656](https://github.com/openclaw/openclaw/actions/runs/36407409443/job/108880022656): identical canonical-skills test and 90000ms timeout. | | Subagent completion remains pending instead of suspended | [job 108894929700](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894929700) | Independent activity [job 108869549339](https://github.com/openclaw/openclaw/actions/runs/36404157978/job/108869549339): same ordinary-delivery-exhaustion test and pending/retryable versus suspended/permanent_failure assertion. | | Requester serial continuation never reaches delivered cleanup | [job 108894933085](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894933085) | Config [job 108890604749](https://github.com/openclaw/openclaw/actions/runs/36410694894/job/108890604749) and companion [job 108888541543](https://github.com/openclaw/openclaw/actions/runs/36410052666/job/108888541543): identical CLI cell with next child accepted=false and requester final=false; same failed/intentional_non_delivery state, `worker task timed out`, and helper line 101. | | Five OpenResponses HTTP fixture cases receive 500 instead of 200 | [job 108894933187](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894933187) | Clean actual CI main parent `fc168b2f6c16312181ce15bcb56d36a14e2c4849`, complete-file reproduction on Blacksmith Testbox `tbx_01m3kswm6aw0bxmdxv2e6qpfv6` ([lease run 36411554208](https://github.com/openclaw/openclaw/actions/runs/36411554208)): identical five failures, 29 passes, and missing Gateway context error. | The remaining red is the aggregate [CI gate](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108903858681), derived from those six jobs. For the HTTP baseline, a separate clean detached worktree passed exact-SHA, clean-tree, and frozen-install assertions. The complete `src/gateway/server-http.openai-compat.test.ts` ran once through `node --import tsx scripts/ci-run-node-test-shard.mts` with the CI `test/vitest/vitest.gateway-server.config.ts` config, `bun-compatible` runtime policy, empty prebuilt-dist setting, and two-worker group setting. Wall time: **73.419s**. Responses image-limit hot reload and the completed image/file requests with streaming enabled and disabled all fail at the same `OpenResponses bearer scope requires a current Gateway context` guard in `openresponses-http.ts:127`. The fixture omits `resolveGatewayContext`; the guard introduced on main by #159227 requires its `configRevisionProjector`. This PR changes only cron exit watchers, their focused tests, and `server-cron.ts` wiring. No assertions were weakened, no baseline source was changed, and no hosted CI was rerun for this evidence. The maintainer’s standing instruction authorizes pinned admin squash over these proven inherited failures. The protected native GraphQL route preserves the expected head, squash method, and reviewed message.
…penclaw#159227) Persist previous_response_id mappings in the core keyed store (core:openresponses/response-sessions, 30-day TTL, 5,000 cap) with purpose-bound HMAC bearer scoping, never persist Incognito mappings, commit continuity before terminal publication, keep failed-run errors, and return a uniform 400 for unresolved ids.
The shared HTTP server fixture omitted the Gateway request context required for bearer-scoped OpenResponses continuity after a13bb6b (openclaw#159227). Use the existing request-context factory and real config revision projector, matching production wiring while preserving explicit fixture overrides. Production authentication, persistence, and current-authority checks are unchanged. Reproduced all five HTTP 500 failures on pristine main dba4154. The existing regression cases pass 34/34 after the fix. On isolated Linux, the failed CI shard plus every harness consumer and OpenResponses suite pass 1179 tests across 65 files; pnpm tsgo:core and formatting also pass. Focused runner wall time: 49.49s before (cold compiler), 17.05s after (cached compiler); these are validation costs, not a performance claim. Independent review found no actionable issues.
## What Problem This Solves Cron exit watcher retry deadlines now use the required Gateway scheduler. A scheduled retry joins startup and failed-start state publication, then the existing watcher owns the long-running child through exit. Cancellation and replacement still preserve exact slot ownership and drain watcher lifecycles. The cutover deletes native timeout handles, `unref` calls, and the unused shell-injection option. No operator configuration or persisted schema changes. Production **+32/-26/net +6**; tests **+101/-38/net +63**. This correctness-driven slice uses the closeout's real deletion offsets. ## Evidence Final head `66d57e0dfa26e242a9c80f415c7f29d65a5721cd`, based on merged main `a13bb6b2dcc93892ce304c8141d522d5bd11f0c2` after cron stream merge `9942ecb05f9fabbd6858661cbf38d92c1c55b083`. Only the exit commit is included. The rebase is patch-identical (`git range-diff` reports `=`), and all three changed files are byte-identical to the tested head below. Existing review and Testbox proof are reused; `git diff --check` passes and the worktree is clean. - Independent Codex autoreview: clean through P2. The committed patch exactly matches the reviewed patch (SHA256 `3ca06c7e52888c92689d9dbc5cebcbb1a18199c1bf3290351d81a14693e81755`). - Exact-head Blacksmith Testbox `tbx_01m3kjwyph0svfjebr22jy7w8q`, run [36399017112](https://github.com/openclaw/openclaw/actions/runs/36399017112), head `80fc468ac824da48ef94423d7a79da316d4ed976`: `pnpm test src/gateway/cron-exit-watchers.test.ts --maxWorkers=1` passed (**28 tests**, **3.75s wall**). - Scoped `node scripts/check-changed.mjs --base 42975a2 -- src/gateway/cron-exit-watchers.test.ts src/gateway/cron-exit-watchers.ts src/gateway/server-cron.ts` passed on the same exact head: **1463.25s wall**, including production and all core test type graphs, format, lint, line ratchets, dead-export scan, and architecture guards. Release-note context: Gateway-owned cron exit retries now share scheduler catch-up and shutdown ownership while child-process settlement remains with its watcher. ### Final inherited-CI classification CI run [36411857535](https://github.com/openclaw/openclaw/actions/runs/36411857535) completed on reviewed head `66d57e0dfa26e242a9c80f415c7f29d65a5721cd`, testing merge tree `80ef6fe243fb9c0c148975007d087c81f1a1a52d` against main parent `fe49033cd6a57cf09fce7aa1401f29695460ad6b`. All six failing test jobs have independent evidence in owners this change does not modify: | Failure | This PR | Matching independent evidence | | --- | --- | --- | | Session rename remains Original session after ordinary Enter | [job 108894925328](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894925328) | Clean main at `8aae819471a9328e0bfe29676372dcb8717cfaa0`: [job 108908250303](https://github.com/openclaw/openclaw/actions/runs/36416233754/job/108908250303). The same parameterized test body fails at line 119 with the same expected committed title and received Original session. Matrix cells differ: this PR uses legacy/Escape; main uses modern/Enter. Both already passed the composition assertions, then execute the identical ordinary Enter, matching patch, list reconciliation, and final rendered-title assertion. | | Manually unread UI state times out waiting for its unread dot | [job 108894925308](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894925308) | Independent MCP [job 108865636156](https://github.com/openclaw/openclaw/actions/runs/36402978963/job/108865636156): same `session-management.unread.e2e.test.ts` case, line 266, unread-dot locator, and 30000ms timeout. | | Canonical skills refresh E2E exceeds its 90000ms timeout | [job 108894929439](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894929439) | Independent questions [job 108880022656](https://github.com/openclaw/openclaw/actions/runs/36407409443/job/108880022656): identical canonical-skills test and 90000ms timeout. | | Subagent completion remains pending instead of suspended | [job 108894929700](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894929700) | Independent activity [job 108869549339](https://github.com/openclaw/openclaw/actions/runs/36404157978/job/108869549339): same ordinary-delivery-exhaustion test and pending/retryable versus suspended/permanent_failure assertion. | | Requester serial continuation never reaches delivered cleanup | [job 108894933085](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894933085) | Config [job 108890604749](https://github.com/openclaw/openclaw/actions/runs/36410694894/job/108890604749) and companion [job 108888541543](https://github.com/openclaw/openclaw/actions/runs/36410052666/job/108888541543): identical CLI cell with next child accepted=false and requester final=false; same failed/intentional_non_delivery state, `worker task timed out`, and helper line 101. | | Five OpenResponses HTTP fixture cases receive 500 instead of 200 | [job 108894933187](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108894933187) | Clean actual CI main parent `fe49033cd6a57cf09fce7aa1401f29695460ad6b`, complete-file reproduction on Blacksmith Testbox `tbx_01m3kswm6aw0bxmdxv2e6qpfv6` ([lease run 36411554208](https://github.com/openclaw/openclaw/actions/runs/36411554208)): identical five failures, 29 passes, and missing Gateway context error. | The remaining red is the aggregate [CI gate](https://github.com/openclaw/openclaw/actions/runs/36411857535/job/108903858681), derived from those six jobs. For the HTTP baseline, a separate clean detached worktree passed exact-SHA, clean-tree, and frozen-install assertions. The complete `src/gateway/server-http.openai-compat.test.ts` ran once through `node --import tsx scripts/ci-run-node-test-shard.mts` with the CI `test/vitest/vitest.gateway-server.config.ts` config, `bun-compatible` runtime policy, empty prebuilt-dist setting, and two-worker group setting. Wall time: **73.419s**. Responses image-limit hot reload and the completed image/file requests with streaming enabled and disabled all fail at the same `OpenResponses bearer scope requires a current Gateway context` guard in `openresponses-http.ts:127`. The fixture omits `resolveGatewayContext`; the guard introduced on main by openclaw#159227 requires its `configRevisionProjector`. This PR changes only cron exit watchers, their focused tests, and `server-cron.ts` wiring. No assertions were weakened, no baseline source was changed, and no hosted CI was rerun for this evidence. The maintainer’s standing instruction authorizes pinned admin squash over these proven inherited failures. The protected native GraphQL route preserves the expected head, squash method, and reviewed message.
What Problem This Solves
On the Gateway's OpenResponses endpoint,
POST /v1/responseswith aprevious_response_idthe Gateway could not resolve returned HTTP200with a completed response in a new conversation. The caller was never told its context was dropped. Continuation mappings were also memory-only (30 minutes, 500 entries), so every Gateway restart or idle gap silently broke legitimate continuations. Found by live QA onmain:{"model":"openclaw","input":"Hi","previous_response_id":"missing"}returned 200.Why This Change Was Made
Maintainer decision: persist mappings, then go strict.
Mapis replaced bycreateCorePluginStateKeyedStore(src/gateway/openresponses-session-store.ts) in the shared state DB:core:openresponses, namespaceresponse-sessionsevict-oldestThe value holds the session key plus the request scope. A lookup returns the session only when the auth subject, agent, and requested session key all match. This PR does not touch the SQLite schema, the state-worker contracts, or the generated DB types.
authSubjectis an HMAC-SHA-256 of the bearer under a purpose-bound key derived from the existingconfig_revision_keysinstallation key (labelopenresponses-session-scope, viasrc/gateway/config-revision-token.ts). It is never a raw or unsalted hash. Trusted-proxy and gateway-auth subjects are unchanged. Incognito mappings, including short session-key aliases, are never written.maybeFinalizerecords that invariant.response.failed).runFailed, keeps its own error response, and the persistence failure is logged.previous_response_idreturns400 invalid_request_error("Cannot resolve previous_response_id. Retry with full input context and omit previous_response_id."), including forstream: true. The error is uniform, so it does not reveal whether another caller's id exists.docs/gateway/openresponses-http-api.mddocuments the rule and the mapping lifetime.User Impact
Evidence
mainsha256(bearer)node scripts/check-changed.mjspasses.finalUsage, which is assigned only after the run settles). The resolved-failed-run finding was fixed.