Skip to content

perf(sessions): admit fresh initial input with its restart claim - #166891

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-create-durable-commit-count-20260919
Oct 8, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-create-durable-commit-count-20260919

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A fresh sessions.create with 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.

Metric Baseline Final candidate Unchanged control
20-create burst p50 2,008 ms 1,632 ms 2,015 ms
Burst max 2,490 ms 2,146 ms 2,558 ms
Cold solo 1,075 ms 999 ms 1,003 ms
Warm solo 946 ms 1,187 ms 1,214 ms
Durable commits in burst 60 40 60
Total / largest COMMIT 40 / 10 ms 17 / 1 ms 22 / 2 ms
Broker commands before ACK 120 80 120
Physical FIFO entries before ACK 220 140 220
Physical callback hold p99 74.6 ms 65.1 ms 73.7 ms

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=1 passed 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=1 passed 26/26, 14.02 s wrapper / 9.75 s Vitest. On the first CI head 3d9fac4f720b, 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.
  • Same lease: node scripts/run-vitest.mjs across 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.
  • Perf Testbox tbx_01m4c91cap4vpr4aekes0z7t3t completed 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 under nice/ionice, task-local state and TMPDIR. SourcePerformance builds and native reopen checks passed. All perf resources are stopped and removed.
  • Independent Codex review: P0/P1 scoped-clean. The changed gate passed all 27 test type graphs, then found an inherited unused export in scripts/publish-model-catalog.mts; main removes it in refactor: remove experimental fleet management #165825. This branch was rebased to 5ffec9b0ad85c616a7d73cb9365cdc88d144d7eb without changing any of the seven reviewed files or copying the unrelated fix into the PR. The updated-base node scripts/check-changed.mjs --staged --base 5ffec9b0ad85c616a7d73cb9365cdc88d144d7eb passed 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:list and git diff --cached --check passed.

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 as 9658ea8d8af2c6d1da1b4c1e04d8ccdbf59c2a5e; all seven landed files match the validated candidate.

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.
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 02:06
@steipete
steipete enabled auto-merge (squash) October 8, 2026 02:08
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 11:24 PM ET / October 8, 2026, 03:24 UTC (Revision 2).

ClawSweeper review

What this changes

The 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.

  • Before: The burst uses 60 durable commits and has a 2,008 ms median acknowledgment time.
  • After: The burst uses 40 durable commits and has a 1,632 ms median acknowledgment time.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, owner-approved optimization with meaningful production-boundary proof and no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Linux public-WebSocket workload exercises the changed session-admission owner with native storage and observes fewer commits and lower burst latency; SIGKILL/reopen cells establish the exact retention boundary. Authenticated public-RPC tests cover revocation before COMMIT with no input, claim, started ACK, or dispatch. Corrective-head queued-binding and built-CLI checks support preserved sibling behavior. Existing stored formats are unchanged and native recovery controls support compatibility without migration; historical screenshots are not counted as candidate proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Concurrent fresh session creation spends extra time waiting for initial-message admission before reporting that the run started.
Reason: The measured burst improvement justifies the bounded change. Current-main area history establishes owner involvement, and the owner-authored PR records acceptance of the narrower pre-ACK retention contract.

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
Reviewed head: 4959ffb6b927f0270fcb89339680568c9a8234d2

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point. Added test files: 2.

Security

None.

Evidence

What I checked:

  • Verified introduced production changes: Read the pinned introduced hunks: the staging bypass requires sessions.create, restart-safe eligibility, and no existing retry state; ordinary chat retains staging. (src/gateway/server-methods/chat-send-handler.ts:212, 4959ffb6b927)
  • Optimization remains absent from current main: Current main still stages eligible input before persisting its transcript and restart claim. Tree inspection also verified identical merge-base/current-main blobs for all four changed production files and the session documentation, so these paths have no intervening base changes. (src/gateway/server-methods/chat-send-handler.ts:299, 8204e9172e38)
  • Accepted retention boundary: The area-owner-authored PR records October 7 acceptance of created-session-only state if failure precedes the input commit. The documentation explicitly describes that limitation and preserves queued, hook-dependent, worker-placement, idle-chat, and durable-retry behavior. This accepted tradeoff requires no renewed product decision. Public docs: docs/concepts/session.md. (docs/concepts/session.md:223, 4959ffb6b927)
  • Authority reaches the final transaction: Fresh creation records its committed session identity before entering chat. Composed source assertions survive recorder wrapping; the existing worker checks prepared source predicates inside the transaction and retains live guards through COMMIT. Ordinary lazy chat uses its existing binding owner. (src/config/sessions/session-turn.ts:227, 4959ffb6b927)
  • Public-RPC durability and forbidden-effect coverage: The added tests drive authenticated public WebSocket sessions.create with native writes. Device revocation at COMMIT leaves only session creation, no input or recovery claim, no started acknowledgment, and no dispatch; other cases cover refusal, lost response, restart recovery, same-ID retry, ordinary idle custody, and canonical redacted dispatch bytes. (src/gateway/server.sessions.create.durability.test.ts:113, 4959ffb6b927)
  • Runtime performance and crash observations: The fully supplied PR body, captured sourceRevision b2bc8590849e7e5f60fc6ba44947d03781df63b37e55e14fe8db3e1e180fc902, reports a real Linux public-WebSocket workload with native storage and a mock provider: all 22 turns completed, burst commits fell 60→40, and median latency fell 2,008→1,632 ms. Four SIGKILL cells reopened databases with the expected creation-only, committed-input-plus-claim, and ordinary staged-input states; integrity checks passed. The corrective head also passed queued-binding and built-CLI lifecycle checks. Warm solo latency did not improve. (4959ffb6b927)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Dallin Romney: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +30, Tests +514, Docs +5. Total +549 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 80 50 +30
Tests 2 516 2 +514
Docs 1 8 3 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 604 55 +549

Review metrics

Metric Value Why it matters
Eligible admission commits 3 → 2 per fresh initial turn The existing transaction owner removes one durable staging round trip without adding another store.
Measured burst latency 2,008 → 1,632 ms p50 The supplied matched synthetic workload supports the performance value while explicitly limiting claims about solo and production-provider latency.

Stored data model

Persistent data-model change detected: serialized state: src/sessions/user-turn-transcript.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Labels

Label changes:

  • add P2: This is a bounded session-admission performance improvement with measured benefit and no demonstrated urgent user-facing regression.
  • add merge-risk: 🚨 compatibility: New eligible creates have a narrower pre-ACK retention contract; the area-owner-authored PR records explicit acceptance and documents the creation-only crash outcome.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a bounded session-admission performance improvement with measured benefit and no demonstrated urgent user-facing regression.
  • merge-risk: 🚨 compatibility: New eligible creates have a narrower pre-ACK retention contract; the area-owner-authored PR records explicit acceptance and documents the creation-only crash outcome.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T02:12:11.110Z sha 3d9fac4 :: needs maintainer review before merge. :: none

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.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@steipete
steipete merged commit 9658ea8 into main Oct 8, 2026
137 checks passed
@steipete
steipete deleted the steipete/perf-micro-create-durable-commit-count-20260919 branch October 8, 2026 03:26
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant