Repository navigation
refactor(sessions): stage and settle pending inputs in workers - #164284
Conversation
|
🦞👀 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 3, 2026, 9:03 AM ET / 13:03 UTC (Revision 3). ClawSweeper reviewWhat this changesMoves pending session input staging, completion, and disposition writes into database workers and makes turn cleanup wait for durable settlement. Merge readiness✅ Ready for maintainer review Current main still needs this worker cutover. The repaired head resolves all four prior findings, and no additional blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherPending inputs hold accepted chat and agent messages until processing or transcript consumption settles. The Gateway retains live custody while database workers persist changes, then publishes terminal outcomes and releases turn resources. flowchart TD
A[Chat or agent input] --> B[Gateway admission]
B --> C[Captured session custody]
C --> D[Database worker]
D --> E[Live authority checks]
E --> F[SQLite commit and receipt]
F --> G[Settlement and cleanup]
G --> H[Terminal response and replay]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +765, Tests +736, Docs +32. Total +1533 across 44 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one pending-input owner across worker persistence and terminal settlement while preserving released SDK callbacks and existing stored-state contracts. Do we have a high-confidence way to reproduce the issue? Not applicable as a refactor. Current-main source confirms the native write path, and the supplied boundary runs exercise the changed worker and settlement behavior; this review did not execute tests. Is this the best way to solve the issue? Yes. Extending the existing agent executor and retaining the existing custody owner avoids a competing scheduler or persistence contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fabc10faca32. LabelsLabel 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)
|
Join prepared-input disposition before publishing preaccept errors or abort replay. Preserve failed settlement instead of caching a terminal abort result. Complete worker consumer cutover in tests: route host-broker consumers through the existing fork lane, inject failures at worker-visible boundaries, and join session admission release before reading final disposition or drain state. Validation: 235 repaired-boundary tests pass, plus 59 unchanged replay tests; production and 27 test type graphs, lint, exports, and changed-code guards pass. P2 autoreview is clean. Head/base repetition matrices attribute the original CI failures to the worker cutover; remaining exact-base repetitions continue before merge admission. No schema, retention, durability, or released SDK change.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* origin/main: fix(test): restore fixture state and await async completion (#164222) refactor(sessions): stage and settle pending inputs in workers (#164284) fix: speech-only replies fail when models include reasoning (#164285) fix(nextcloud-talk): avoid webhook migration for unconfigured channels fix: guide background skill reviews through Workshop proposals (#164292) test(build): reject AI dependencies in retained config repairs refactor(channels): require canonical private-network settings (#163535) fix(memory): migrate embedding cache in bounded batches and record oversized rows (#164303) feat(state): incognito actor memory and Codex history routing (P5c, inactive) (#164224) refactor(synology-chat): remove unused route account ID (#164280) test(ui): await web push preference publications (#164295) perf(scripts): avoid compiler projects for runtime import parsing (#164243) fix(worktrees): create workspaces from nested Windows repositories (#164249) test(agents,channels,cli): remove low-value tests (batch d173) (#164302) perf(workboard): serve cards per board revision and push changes instead of polling (#164301) refactor(sqlite): deslop sqlite stores (#164271) chore(ui): refresh control ui locales (#164299) refactor(events): deslop listener and disposal plumbing (#164221) fix: canonicalize fresh worker reasoning signatures (#164287)
…law#164284) * refactor(sessions): stage and settle pending inputs in workers * fix(sessions): settle pending input before publishing rejection Join prepared-input disposition before publishing preaccept errors or abort replay. Preserve failed settlement instead of caching a terminal abort result. Complete worker consumer cutover in tests: route host-broker consumers through the existing fork lane, inject failures at worker-visible boundaries, and join session admission release before reading final disposition or drain state. Validation: 235 repaired-boundary tests pass, plus 59 unchanged replay tests; production and 27 test type graphs, lint, exports, and changed-code guards pass. P2 autoreview is clean. Head/base repetition matrices attribute the original CI failures to the worker cutover; remaining exact-base repetitions continue before merge admission. No schema, retention, durability, or released SDK change.
What Problem This Solves
Pending-input staging, processing completion, and owner finish still execute SQLite on the Gateway thread for ordinary chat and agent turns. Moving those writes also requires terminal replies and close paths to wait for their durable settlement.
Why This Change Was Made
Extend the existing agent executor with
session.pendingInputs.readandsession.pendingInputs.mutate. Capture the physical store before yielding, plan outside synchronous transactions, preserve the writer FIFO, and reread the authoritative session/run/request/lifecycle facts in the worker. Transaction and commit grants check live host custody; admission publishes only after native commit acknowledgment. Lost replies reconcile the existing native receipt; unknown outcomes never replay.Finishing revokes prompt custody immediately while the existing owner retains history custody through settlement. Recorder, chat admission, agent cleanup, and database close join accepted work. Queued-abort final replies and dispatched terminal replay publication now follow the existing cleanup boundary, including recovery callbacks that arrive during finish. Original sources remain distinct from collected input, and processing completion remains distinct from transcript consumption.
User Impact
The moved runtime operations leave the Gateway thread. No schema, stored-byte, retention, durability, environment-variable, configuration, or update behavior changes. Append/transcript rewriting and native binding remain outside this cut.
The synchronous
completeProcessingand voidfinishPendingInputcontracts are present in releasedv2026.9.8. Preserve them for SDK callers; internal callers awaitcompleteProcessingAsyncandwaitForPendingInputSettlement. Incognito retains its existing process-held owner.The lane-6 extension point is
PendingInputRead.kindonsession.pendingInputs.read: a bounded pending-source read can be added to its discriminated request/result contract. Submitted-input retry comparison and recovered dedupe are not implemented here.Overlap: #162433 is an umbrella design-review draft. Changes to execution/dispatch here are limited to settlement joins; that draft's eventual controller would absorb these joins.
Retained pre-existing host authority reads remain follow-up debt: the captured-source key/alias check at
src/config/sessions/session-accessor.sqlite-exact-read.ts:286, exact session identity read atsrc/config/sessions/session-accessor.sqlite-entry-read.ts:122, and nonprojected membership check atsrc/config/sessions/session-sharing-store.kernel.ts:45. These belong to session identity/sharing owners; no pending-input SQL was added to grants. Boundary assertions cover the moved operations.Evidence
chat.sendand private agent turns prove staging/completion/finish with zero caller-thread SQL for the moved writes. Recorder boundary additionally observes zero caller-thread data SQL throughout the moved operations.v2026.9.8; native rollback/postcommit compatibility tests pass.try/finallypreserves settlement joins under the repository callback contract. No newOPENCLAW_*names.Final gates passed:
node scripts/check-changed.mjspnpm check:madge-import-cyclespnpm check:database-worker-ratchet --base 5df82fa43619dff034f9f000d7cb3e6be5cfb0ddpnpm plugin-sdk:surface:checkBoth required shared-registry import suites pass. Gateway worktree setup/build completed successfully. No unrelated main failure was encountered in these gates.
Focused test wall times — 252 tests in 16 files
Each command was
pnpm test <file> --maxWorkers=1. Times include local compilation and wrapper overhead on the shared host; unchanged-owner proof was reused. CI seconds are not yet measured; no CI reruns were used as proof.src/gateway/server-methods/chat-send-work-admission.test.tssrc/config/sessions/session-pending-input-operations.test.tssrc/config/sessions/session-accessor.pending-inputs.test.tssrc/config/sessions/session-accessor.pending-inputs-consumed.test.tssrc/gateway/agent-turn/agent-run-execution-phase.owner.test.tssrc/gateway/server.private-completion.test.tssrc/gateway/server-methods/chat-send-pending-inputs.test.tstest/scripts/runtime-process-build-graph.test.tssrc/auto-reply/reply/get-reply.imports.test.tssrc/gateway/server-methods/agent.followup-owner.test.tssrc/gateway/server.subagent-settle-replay.harness.test.tssrc/config/sessions/session-pending-input-history.test.tssrc/config/sessions/session-accessor.pending-inputs-worker-custody.test.tssrc/config/sessions/session-pending-input-withdrawal.test.tssrc/gateway/agent-turn/agent-run-dispatch.owner.test.tssrc/gateway/agent-turn/agent-run-dispatch.incognito.test.tsLanding repair and verification
Repair commit e02c42d9 addresses the failures in original-head CI run 37121069290 and all three ClawSweeper P2 findings. These are attributable to the worker cutover; no inherited-main exception or green rerun is claimed.
Rejected agent admission now joins prepared-input disposition before error or abort replay publication. Failed or uncertain settlement cannot become cached terminal abort replay. The new real-flow regression fails on the pre-gate implementation: a fresh-authority retry receives cached abort replay instead of the pending-custody refusal; the gated implementation passes. Existing released SDK signatures remain unchanged, and the changed revalidator is internal-only.
The remaining consumer changes route real host-broker tests through the existing fork lane, inject failures where worker writes actually occur, and await existing settlement/release promises before snapshots and drain assertions. The database-close owner already joins the schema fixtures, so no extra schema waits were retained. The media-retention assertions remain intact; their fixture now waits for disposition through that same release owner. No sleeps, retries, assertion weakening, or new test-only production seam were added.
Repair proof: 235 tests pass, plus 59 unchanged embedded-replay tests. Production types, all 27 selected test type graphs, core/script lint, dead exports, ratchets, and the remaining changed-code guards pass. Final Codex autoreview through P2 is scoped-clean for the staged candidate. Both required shared-registry import suites from the original candidate remain valid; the repair adds no worker or launcher module import.
Tests used
pnpm test <file-or-focused-group> --maxWorkers=1; the new cases reuse the existing Gateway fixture. These are measured local wall times. Linux Testbox proof for the final eight-case resumed-send suite passed in 40.42 seconds. Exact-head PR CI 37124579732 passed on its first run, with 624 seconds elapsed CI wall time; both the Actions gate and combinedopenclaw/ci-gatestatus succeeded. No CI reruns or admin exception were used. ClawSweeper completed review ofe02c42d9af4be4647aacfe37cc582faa4fdb76b4with no actionable findings.Attribution uses five separate full-file runs on the original head and five on merge base
5df82fa4. Completed matrices independently reproduce the routing, fault-injection, migration, identity, and admission-publication failures on the PR and pass on the base. Resumed-send fails 4/5 original-head repetitions, consistent with the diagnosed race, and passes 5/5 base repetitions. All three chat files split 5/5 failing head versus 5/5 passing base. Every requested five-run head/base matrix is complete. The clean Testbox environment eliminated unrelated timeouts from the contended local host.Follow-up scope remains the retained SDK/incognito path, other-owner authority reads, and lane-6 reads.