Repository navigation
perf(sessions): admit fresh initial input with its restart claim - #166891
Conversation
For eligible local, idle, restart-safe sessions.create turns, retain session creation as the first commit and accept the initial input with the existing transcript/restart-claim commit. Before that second commit, a crash may leave only the created session without retained initial-input bytes; no started ACK precedes durability. This scoped pre-ACK retention change is maintainer approved. Existing queued, idle-chat, hook, worker and durable-retry custody remain unchanged. Carry prepared current-authority checks to the native write, preserve canonical dispatch bytes, and remove redundant hook-time validation. Public-RPC regression and SIGKILL proof cover rollback, revocation, retry, recovery and accepted-write settlement. A controlled 20-create burst drops from 60 to 40 commits and about 2.01 s to 1.63 s p50; warm solo does not improve.
|
🦞👀 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 October 7, 2026, 11:24 PM ET / October 8, 2026, 03:24 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch removes intermediate pending-input staging for eligible fresh session turns and commits their input together with the restart-recovery claim. Example: Create 20 fresh sessions concurrently in the supplied synthetic workload.
Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR retains useful work absent from current main, with convincing boundary proof and an accepted retention tradeoff. No actionable correctness or security finding remains. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway accepts session creation requests and initial messages, then stores their transcript and restart-recovery state in the existing agent database. Successful started-run acknowledgments follow durable input admission. flowchart TD
A[Session creation request] --> B[Commit new session]
B --> C{Eligible fresh initial turn?}
C -->|Yes| E[Commit input and restart claim together]
C -->|No| D[Existing input staging owner]
D --> E
E --> F[Started acknowledgment and dispatch]
E --> G[Restart recovery]
Technical reviewBest possible solution: Keep the existing transcript transaction as the single initial-input admission owner, with the approved pre-ACK retention boundary documented and other custody paths preserved. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is an optimization of working admission behavior. Current-main source establishes the redundant staging step, and supplied public-WebSocket measurements exercise its cost. Is this the best way to solve the issue? Yes: the branch reuses the existing atomic transcript-and-restart-claim transaction, confines the bypass to eligible fresh creation, and preserves ordinary lazy-chat binding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8204e9172e38. Provenance checked
TestingProof path: shipped entry point. Added test files: 2. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +30, Tests +514, Docs +5. Total +549 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
|
Scope the added sharing-source assertion to eligible fresh creation, where session identity is committed before initial input admission. Ordinary chat can authorize an absent target and let its prepared-session owner bind the new session later; reusing that absent snapshot rejects valid queued writes. The existing queued-binding suite and built-CLI SQLite lifecycle verifier failed on the previous head and pass with this correction. Fresh creation still validates its recorded sharing authority at the input commit.
…nclaw#166891) * perf(sessions): admit fresh initial input with its restart claim For eligible local, idle, restart-safe sessions.create turns, retain session creation as the first commit and accept the initial input with the existing transcript/restart-claim commit. Before that second commit, a crash may leave only the created session without retained initial-input bytes; no started ACK precedes durability. This scoped pre-ACK retention change is maintainer approved. Existing queued, idle-chat, hook, worker and durable-retry custody remain unchanged. Carry prepared current-authority checks to the native write, preserve canonical dispatch bytes, and remove redundant hook-time validation. Public-RPC regression and SIGKILL proof cover rollback, revocation, retry, recovery and accepted-write settlement. A controlled 20-create burst drops from 60 to 40 commits and about 2.01 s to 1.63 s p50; warm solo does not improve. * test(sessions): compare canonical history content as JSON * fix(sessions): retain lazy chat binding authority Scope the added sharing-source assertion to eligible fresh creation, where session identity is committed before initial input admission. Ordinary chat can authorize an absent target and let its prepared-session owner bind the new session later; reusing that absent snapshot rejects valid queued writes. The existing queued-binding suite and built-CLI SQLite lifecycle verifier failed on the previous head and pass with this correction. Fresh creation still validates its recorded sharing authority at the input commit.
What Problem This Solves
A fresh
sessions.createwith an eligible initial turn entered the agent write FIFO for three durable commits: session creation, pending-input staging, and the transcript plus restart claim. The intermediate staging round trip added queue and worker traffic before the started-run acknowledgment.User Impact
Fresh local, idle, restart-safe initial turns now use two commits. The session commits first; its input and restart claim commit together before any successful started-run ACK. A failure or crash between these commits can leave the created session without retained initial-input bytes. Once the input commits, it remains recoverable even if its ACK is lost. This narrower pre-ACK retention contract was explicitly approved by the maintainer on October 7, 2026.
Existing idle
chat.send, queued input, hook-dependent input, worker placement, durable retries, staged rows, and active claims retain their current owners and behavior. No schema/index, stored-format migration, configuration option, or WAL change is involved. Updating changes new eligible attempts only; reverting cannot restore bytes that never committed. The session lifecycle documentation describes the new boundary.Why This Change Was Made
The existing transcript-turn owner already commits the input and restart claim atomically. The eligible creation path now uses that boundary directly. Fresh creation carries its recorded sharing authority through the recorder to the worker's transaction and final commit checks. Ordinary lazy chat retains its prepared-session binding owner; its earlier absent-target sharing snapshot must not be reused after session creation. Accepted custody does not reacquire expired original authority. The redundant hook-time check is removed; FIFO order, publication fencing, native accepted-write settlement, and canonical redacted dispatch bytes remain with their existing owners.
Production delta: +30 lines across four files (80 additions, 50 deletions). The scoped retention contract requires retaining staging for the other real callers, an explicit initial-turn selection, and carrying prepared fresh-source authority to the remaining write. This removes a transaction and its queue/transport work without adding a second transaction owner or cache.
Evidence
Same-host Linux synthetic public-WebSocket workload, pinned base
471f950ee340e11abc5111fbfb7022be953b89b6: 10,000 catalog rows, mock provider, managed worktrees, one cold solo / 20 concurrent creates / one warm solo. Every run completed all 22 turns, worktree preparations, post-publication describes, and exact single-user-message durability checks.Burst p50 improved about 19% and met the <2 s target; warm solo did not improve. COMMIT timings use the existing integer-millisecond clock, include WAL work, and are not separate fsync measurements. These synthetic results do not claim production-provider latency. The measured eligible creation path is unchanged by later guard deduplication and test corrections. A follow-up restricts the added sharing assertion to that path so ordinary lazy chat retains its existing binding contract.
Four real SIGKILL cells passed through the public RPC and native transaction owner: after session creation; during the initial-input transaction before COMMIT; immediately after its COMMIT before response/ACK; and after ordinary idle-chat staging. Reopened databases respectively retained creation only, creation only, one input with matching restart/lifecycle claim, and the existing queued input. No started ACK escaped; all four integrity checks passed.
Remote proof:
blacksmith-testbox,openclaw-check,tbx_01m4c9kpjydkvg5w46cjv883t8:pnpm test src/gateway/server.sessions.create.durability.test.ts --maxWorkers=1passed 14/14, 55.94 s wrapper / 52.05 s Vitest. The file reuses its Gateway fixture; actual native writes, public ACKs, and startup recovery require this boundary.pnpm test src/sessions/user-turn-transcript.persistence.test.ts --maxWorkers=1passed 26/26, 14.02 s wrapper / 9.75 s Vitest. On the first CI head3d9fac4f720b, both files passed: durability 14/14 used 19.531 s summed case time (77.72 s owning two-file wrapper; 190 s job), and recorder 26/26 used 4.725 s case time (61.38 s owning three-file wrapper; 128 s job). Separate CI per-file wall times were not emitted.node scripts/run-vitest.mjsacross 15 relevant Gateway, recorder, and native custody siblings passed 312/312, 394.50 s wrapper. Final creation-partial-success and pending-custody checks passed 40/40, 113.56 s wrapper. The original-production negative control failed exactly because commit refusal retained one pending input; the candidate passes with none.tbx_01m4c91cap4vpr4aekes0z7t3tcompleted its baseline, then sync timed out before the candidate. AWS and Hetzner refused allocation at fleet capacity. The authorized isolated Linux rig ran the complete baseline/candidate/control/final confirmation and SIGKILL cells undernice/ionice, task-local state and TMPDIR. SourcePerformance builds and native reopen checks passed. All perf resources are stopped and removed.scripts/publish-model-catalog.mts; main removes it in refactor: remove experimental fleet management #165825. This branch was rebased to5ffec9b0ad85c616a7d73cb9365cdc88d144d7ebwithout changing any of the seven reviewed files or copying the unrelated fix into the PR. The updated-basenode scripts/check-changed.mjs --staged --base 5ffec9b0ad85c616a7d73cb9365cdc88d144d7ebpassed on the authorized Linux rig: core types, all 27 test type graphs, all 3 export scans, lint 0 warnings/errors, formatting, storage and remaining guards. Final runtime reruns passed durability 14/14 (101.54s wrapper), recorder 26/26 (56.78s), and native custody/initialization 54/54 (103.15s).pnpm docs:listandgit diff --cached --checkpassed.The first CI run exposed a lane-caused stale sharing-snapshot check in ordinary lazy/queued chat. The correction limits the added sharing source to the eligible fresh-create path. Remote proof of that correction passed queued binding 14/14, the exact built-CLI SQLite lifecycle verifier 1/1, and fresh durability/profile cases 29/29. The corrective head passed the complete staged changed gate again (39m38.5s), with all 27 test type graphs, all three export scans, and zero lint warnings/errors. The built verifier kept its assertions and timeouts; an isolated preload constrained only test port allocation to the rig range. No inherited-failure bypass was used for the lane-caused failures.
Final CI 37721996661 completed successfully on
4959ffb6b927f0270fcb89339680568c9a8234d2. Squash merged as9658ea8d8af2c6d1da1b4c1e04d8ccdbf59c2a5e; all seven landed files match the validated candidate.