Repository navigation
refactor(sessions): keep pending history reads off the Gateway thread - #163582
Conversation
Move durable pending history and exact-message reads through the history worker and stale interruption through the agent writer. Preserve bounded pages, consumed filtering and live cancelled disposition custody with SQL-free transaction and commit grants; settle acknowledged writes without replay. Keep incognito and unrelated custody operations with their existing owners.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 10:52 AM ET / 14:52 UTC. ClawSweeper reviewWhat this changesMove durable pending-message history reads and stale-input reconciliation into existing database workers, and update callers to await their results. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release still perform pending-history SQL synchronously. No actionable correctness or security defect was found in the introduced changes. Likely related people: steipete (medium confidence, recent session-storage work). Priority: P2 Review scores
Verification
How this fits togetherPending-input history supplies accepted messages that have not entered the conversation transcript to chat history, startup, and exact-message lookup. Its storage owner also records interrupted inputs when their live execution custody has ended. flowchart TD
A[Chat history and message lookup] --> B[Capture database identity]
B --> C[History read worker]
C --> D{Live input custody?}
D -->|Yes| F[Return bounded pending messages]
D -->|No| E[Agent writer rechecks and reconciles]
E --> F
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +453, Tests +309, Docs +9. Total +771 across 48 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep pending-history reads and reconciliation with the existing reader and writer owners while preserving bounded pages, live custody, and confirmed-write settlement. Do we have a high-confidence way to reproduce the issue? Yes for the stated caller-thread SQL mechanism: current-main source directly performs those queries and writes. Runtime performance was not reproduced during this read-only review. Is this the best way to solve the issue? Yes: the patch extends existing database owners, removes the synchronous durable implementation, and preserves the separate incognito owner without adding a competing storage path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 553c6bde778c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…63582) Move durable pending history and exact-message reads through the history worker and stale interruption through the agent writer. Preserve bounded pages, consumed filtering and live cancelled disposition custody with SQL-free transaction and commit grants; settle acknowledged writes without replay. Keep incognito and unrelated custody operations with their existing owners.
…nventory Run A (all --changed shards at a25baa1) failed 16 tests, all in fork-pinned areas. Each is TEST-DRIFT: the fork behaviour holds on 10.1 and only the test setup changed upstream. Each fix has a revert control that fails for the right reason. - attempt-prompt-context (Telegram current-message carrier, v3/v4): openclaw#163471 replaced the BEGIN/END internal-context wrapper with an "OpenClaw runtime context:" label applied at model send. The fork's carrierText still states the body. Control: without carrierText the v3 case fails on a bare "openclaw#19452:". - session-context (runtime carriers at compaction boundaries, 3, an upstream test): openclaw#161281 pins the summary exactly, and the fork's checkpoint line collides with that. The cut point is unchanged from 9.9. Controls: no checkpoint line -> 14/21; a cut between the carrier and its user -> 19/21. - pending-inputs.redrive: openclaw#163582 made listSessionPendingInputs async. Control: without the fork's terminal block, 10.1 admits a fresh turn for a committed source turn ("expected true to be false"). - agent-runner-failure-reply (3) and assistant-failure (1): the 10.1 copy from openclaw#163381, under this carry's precedent (the fork keeps its classification and takes 10.1's copy). The transport cases now also assert "not took too long"; without that, the old negatives passed with the fork code removed. assistant-failure asserts the FailoverError fields (provider, model) in place of the old text. The 9.9 build did not rotate profiles on this path either (probe at 9eea409). - owner-only-tool-stubs (4) and attempt.owner-only-tool-stubs (2): openclaw#154239 makes non-owner turns use the real `sessions` tool, limited to assign_owner, rather than denying it. Alex, 2026-10-11: take upstream's rule. The tests therefore expect every owner-only tool except `sessions` to be stubbed. openclaw#164296 makes the tool-surface bridge add the Tool Search controls itself, so the attempt test covers Tool Search off, on, and Code Mode. Controls: with the fork's stub shaping off, 5/8; with the refusal line removed, 0/4. Also adds src/agents/owner-only-tool-stub-marker.ts to scripts/pr-lib/wrapper-components.txt. tool-policy.ts has imported it since the 9.9 carry and it was never listed, which failed eager-import-closure. With the line, eager-import-closure is 18/18 and pr-wrappers 217/217.
What Problem This Solves
Pending-input pages in
chat.history/chat.startupand exact pending-message lookup inchat.message.getstill executed SQLite on the Gateway thread. Their read helper also synchronously wrote inferred interruptions for inputs without live custody.Why This Change Was Made
Move durable bounded reads through the existing history reader and stale-disposition reconciliation through the existing agent writer. Capture the physical store before yielding, reread authoritative candidates in a synchronous transaction, and ask the live host custody registry at transaction and commit admission without host SQL. An aborted registered owner keeps its right to finish cancelled. Acknowledged commit receipts update the page even if ordinary result delivery fails; accepted work settles before releasing custody, and uncertain writes are never replayed.
Both runtime callers now await the operations. Remove the old synchronous read implementation and migrate its test callers. The reader factory gets one minimal registration; reply validation is unchanged.
User Impact
No schema, durability, retention, configuration, or update changes. Preserve 20-item and byte limits, ordering, consumed filtering, and exact-message isolation. Process-held incognito retains its existing owner pending its separate actor cutover. Stage/finish/append custody, submitted-input recovery, pending-input repair, and S10 entry patching remain outside this change.
Production LOC: +606 / −153 / net +453 (759 changed lines). Selected durable-flow host SQL exposure: 8 → 0. Conservative full inventory T1: 1,518 → 1,518; the shared kernels remain counted because incognito still uses them, and staging retains its native custody query. No mixed file was relabeled worker-only.
Overlap: draft #157240 has a different reply-validation refactor. Coordinator explicitly approved minimal reader-factory additions here; that PR must rebase after subsequent merged factory changes. #162473 touches shared pending-input files in separate append/consumption functions; these hunks preserve that scope.
Evidence
Base pinned to
9b6e3c4bdb5ca52dc1ef4bd5c1f79acb5f841d35, which contains the requested base and merged #163264.All focused invocations use
pnpm test <file> --maxWorkers=1. Wall times include compiler preparation and cleanup on a loaded macOS host.src/config/sessions/session-pending-input-history.test.tssrc/config/sessions/session-accessor.pending-inputs.test.tssrc/config/sessions/session-accessor.pending-inputs-consumed.test.tssrc/gateway/server-methods/chat-pending-inputs.test.tssrc/gateway/server-methods/chat-message-get-handler.test.tssrc/gateway/server-methods/chat-send-pending-inputs.test.tssrc/gateway/server-methods/chat-send-pending-input-withdrawal.test.tssrc/gateway/server-methods/sessions-suggestions.custody.test.tssrc/state/openclaw-agent-pending-inputs-schema.test.tsThe zero-caller-SQL regression failed on the original implementation (39.56 s wall), then passed with real reader/writer workers. It also proves transaction/commit custody rechecks, atomic rollback of multiple candidates, and acknowledged commit recovery after ordinary reply loss. Existing suites cover bounds, stable cursors, consumption, cancellation, reset, and Gateway presentation.
An initial schema-fixture run also exposed an unjoined asynchronous database close before raw reopen; it now joins worker cleanup and passes all seven cases. Five UI E2E callsites were migrated to awaited reads and retained async polling.
An initial accessor run failed because its injected SQL trigger was rejected by canonical worker schema admission. The rollback assertion now uses commit-grant refusal in the boundary suite; the production schema check remains intact.
node scripts/check-changed.mjs: reaches the inherited env-name budget failure (477 vs 476); the max-lines suppression check reports it. The standalone env-count script confirms the same failure, and this diff adds 0OPENCLAW_*names. Budget unchanged. Remaining planned checks executed separately: passed after fixing lint, except the inherited test type error below. Final focused lint, formatting, UI i18n checks, and the resumed typecheck shards passed.tsgo:core:testalso reports inherited TS2339 atsrc/gateway/worker-environments/worker-turn-launcher.claim-recovery.test.ts:346:openSessionManager().appendMessage(...)calls an instance method on a Promise. The pinned base already has this exact call; its unchanged helper atworker-turn-launcher.test-support.ts:287explicitly returnsPromise<SessionManager>. Both files andsession-manager.tsare unchanged by this PR. Remaining typecheck shards were run separately so this inherited failure does not hide checks for this change.git diff --check: passed.Hosted CI seconds are not yet available. This PR is ready for review; it has not been merged.
Released SDK surface check
Compared the changed signatures against release tag
v2026.9.7and inspected the SDK exports, documented subpaths, andapi.runtimeimplementation.listSessionPendingInputsandreadSessionPendingInputwere synchronous internal helpers in that release; neither is reachable from a released plugin contract. The internal session-accessor barrel is not wildcard-exported by an SDK entrypoint. No released signature changes, compatibility record, or compatibility type test are needed.Landing preflight reran the standalone env-count check against the pinned base: the inherited count remains 477 against budget 476. The PR adds zero
OPENCLAW_*names and does not change the budget.