Skip to content

perf(sessions): combine candidate transfer with commit admission - #169744

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-writer-hold-and-group-commit-20260919
Oct 12, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-writer-hold-and-group-commit-20260919

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Queued session mutations hold the per-agent writer while transferring a candidate through separate handle, data, end-marker, and commit-authority exchanges. These waits amplify the transaction tail while other sessions wait behind the same FIFO.

User Impact

Ordinary session mutations now carry their last data frame and end marker in the existing final commit grant. This removes three host round trips per patch. FIFO, live authority, large-result framing, native commit receipts, incognito behavior, and update/storage contracts remain intact. This change does not establish overall queue relief or meet the lane's 150 ms queue-p95 target.

Why This Change Was Made

A 20-session synthetic workload attributed 61.5% of small-patch transaction wall time to authority exchanges and 2% to COMMIT. A bounded independent-write group-commit prototype saved only 14 COMMITs across roughly 1,000 metadata admissions and did not improve the matched queue result (576→565 ms p95). It was removed entirely. Callback prepare/compare boundaries still dominate the queue.

The remaining change shares envelope collection between the durable and incognito consumers and removes the standalone transfer acknowledgments. The full candidate is still checked before the live final grant; only the small original receipt certifies native COMMIT. Production delta: +19 lines. The retained arbitrary-size framed-result contract and incognito decode-before-authorize ordering require the shared collector and prevent deleting the large-result path.

Evidence

Linux rig, synthetic state, one database, 20 sessions × 5 measured tool turns; 100 probes, 400 history reads, and 100 UI metadata updates. No Team access or Testbox/Crabbox allocation.

Phase, p95 ms Quiet baseline Singleton subset with collapsed transfer
Host callback/scope preparation 0.295 0.285
Native preparation (coarse timer) 9 10
Authority waits inside transaction 22.410 13.310
SQL/local transaction work 4.515 4.841
COMMIT/fsync 0.216 0.231
Whole transaction after BEGIN 26.087 16.815
Committed-view adoption/publication 1.949 2.185

The controlled singleton transaction-tail improvement was 35.5% (1.55×), with six→three authority exchanges. This comparison used the singleton subset of the subsequently discarded batch prototype, not a matched final-checkout end-to-end benchmark. The final four-file production candidate separately completed 100/100 turns and all probes with three exchanges and zero batches. Its busy-host queue p95 was 1,398 ms and transaction p95 37.142 ms; shared-host load prevents a valid latency comparison. BEGIN in the original phase capture was 0.20 ms p95. Phase percentiles are separate distributions and must not be summed.

Focused local proof: changed-file oxfmt and repo oxlint; session-entry authority, large payload/lost reply, incognito entry patch, goal management, and internal-source message-admission tests. Independent review: no actionable P0–P2 findings on the final diff. Full typecheck/build/closure/suite gates are delegated to PR CI per the lane validation rule.

  • pnpm test src/config/sessions/session-entry-patch.authority.test.ts src/config/sessions/session-entry-patch.test.ts src/state/openclaw-agent-execution-incognito.entry-patch.test.ts --maxWorkers=1: passed, 91.88 s including worker compilation.
  • pnpm test src/agents/tools/message-tool.internal-source-reply.integration.test.ts src/config/sessions/goals-operations.test.ts --maxWorkers=1: passed, 30 tests, 197.20 s on the busy local host.

CI found two unconstrained generic callers after the transfer helper's receipt contract was narrowed to objects. The purge and maintenance-finalization callbacks now carry the same constraint; this changes types only. The correction received an independent clean P2 review.

  • pnpm test src/config/sessions/session-agent-purge.test.ts src/config/sessions/session-native-binding.reclamation.test.ts --maxWorkers=1: passed, 15 tests, 110.16 s including compiler cleanup.
  • Initial CI attempt 38222011397 stopped on those caller type errors and cancelled sibling jobs. The correction is pushed for normal PR CI; no CI reruns or dispatches were requested.

CI disposition

The corrected head fa0a4b346d8bf559f50f3fc9cd7de03f1807e086 ran CI 38223434226, attempt 1. Its sole root failure is checks-node-compact-small-1: test/scripts/type-suppression-inventory.test.ts reports an unlisted @ts-expect-error in scripts/lib/managed-cleanup-handoff.mts. The successful fail-fast monitor cancelled sibling jobs; the CI aggregate failed downstream. Cancelled jobs are incomplete coverage, not passes.

Baseline qualification: the same focused file fails identically on untouched main commit 2b4c2a10bb419014419482a8c44e3d2925b83310 (one failed / three passed, 12.16 s). CI checked out merge ef20ef2f1af9dbcb1dd138f196712c82ef66207f, whose parents are that main baseline and the exact PR head. The cleanup script, inventory implementation, and inventory test are byte-identical between the baseline and tested merge; none is part of this PR. This qualifies for the operator-authorized inherited-failure landing exception. No rerun, dispatch, update-branch, or synthetic push was requested.

Additional focused closure proof: pnpm test test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts --maxWorkers=1 passed, 20 tests, 49.90 s. The final CI attempt used 292 wall-clock seconds (08:25:05–08:29:57 UTC); most broad coverage was cancelled, so it is not a full-green result.

Carry final candidate frames with the live commit grant, retaining bounded intermediate frames and durable receipt settlement. Share envelope validation across durable and incognito consumers. A measured group-commit prototype did not relieve the queue and is not included.
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Oct 12, 2026
@steipete
steipete marked this pull request as ready for review October 12, 2026 08:10
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR combines session candidate transfer with the final commit-authority exchange while preserving framed large results and native receipts.

Example: Change agent:main:compound-worker from label initial to committed candidate.

  • Before: The ordinary candidate requires separate handle, data-frame, end-marker, and commit exchanges.
  • After: One commit exchange carries the candidate and end marker, removing three round trips before the same durable result.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source and focused worker coverage support correctness; directly inspectable end-to-end performance evidence remains limited.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal optimization is outside the ordinary contributor proof gate; the body reports 100 successful final-candidate synthetic turns and focused real-worker tests, without a linked execution trace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Queued session mutations wait behind avoidable host exchanges while the per-agent writer remains occupied.
Reason: The maintainer-directed change removes identifiable overhead while explicitly limiting its claims to transfer exchanges rather than overall queue relief.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a useful maintainer-directed optimization, and no actionable introduced correctness defect was found.

Priority: P2
Reviewed head: a4f8342d58523b63554fabdc0746daa165727dfc

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not show a shipped-entry-point trace, a matched final-head latency comparison, or base-fail/head-pass execution of the new exchange regression.
Agent review details

How this fits together

Session mutations enter the per-agent FIFO writer, execute in a SQLite worker, obtain current host authorization, and publish committed session facts after native receipt confirmation.

flowchart LR
Caller[Session mutation] --> FIFO[Per agent writer]
FIFO --> Worker[SQLite transaction worker]
Worker --> Collector[Candidate collector]
Collector --> Authority[Live host authorization]
Authority --> Commit[Native COMMIT]
Commit --> Publication[Receipt and publication]
Loading

Technical review

Best possible solution:

Retain the combined exchange and existing receipt owners, then land after the normal CI gate is resolved.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the redundant exchanges; no runtime reproduction was run during this read-only review, and the author reports synthetic workload measurements.

Is this the best way to solve the issue?

The scoped optimization uses the existing worker, framing, authorization, and settlement owners without introducing batching or changing durable semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 76f4fdd41acf.

Provenance checked

  • Durable candidate transfer and publication keeps the original intent (d6929f8: Move prepared metadata transactions off the Gateway thread while preserving FIFO, predicates, caller authority, and native receipt publication.)
  • Sequential commit receipt isolation keeps the original intent (5d13f20: Reset each commit's candidate and transfer state so a later operation cannot borrow an earlier acknowledgment.)
  • Incognito entry publication keeps the original intent (6f22790: Use the captured actor and synchronous worker transaction while preserving source authority, framed results, and committed publication.)
  • Large-result framing keeps the original intent (ecfbddb: Return complete large worker results through bounded frames without publishing partial results or replaying operations.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ca77256 adds src/config/sessions/session-entry-patch.worker.ts:73 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ca77256127e6; files: src/config/sessions/session-entry-patch.worker.ts)

PR surface

Source +19, Tests +35, Docs +7. Total +61 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 111 92 +19
Tests 3 74 39 +35
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 192 131 +61

Review metrics

Metric Value Why it matters
Production versus test LOC Production +111/-92, net +19; tests +74/-39, net +35 The shared collector replaces duplicated consumers while retaining bounded large-result transfer and incognito ordering; test changes preserve authority coverage and assert the reduced exchange contract.

Labels

Label changes:

  • add P2: A focused session-write performance improvement with no established urgent user-facing regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A focused session-write performance improvement with no established urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 execution lanes are retired.

Reviewed October 12, 2026, 4:19 AM ET / 08:19 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing under the authorized inherited-failure exception for exact head fa0a4b346d8bf559f50f3fc9cd7de03f1807e086.

CI run 38223434226, attempt 1 has one root failure: checks-node-compact-small-1, where test/scripts/type-suppression-inventory.test.ts finds an unlisted Bun socket @ts-expect-error in scripts/lib/managed-cleanup-handoff.mts. The same focused file fails on untouched main 2b4c2a10bb419014419482a8c44e3d2925b83310 with the identical extra entry (1 failed / 3 passed, 12.16 s). The implementation, test, and offending script are byte-identical between that main baseline and CI's tested merge ef20ef2f1af9dbcb1dd138f196712c82ef66207f; none is touched by this PR.

The successful fail-fast monitor cancelled siblings, and the aggregate gate failed downstream. Those cancellations remain incomplete coverage. Focused storage/authority/incognito, goals, message admission, agent purge/reclamation, and the two closure files passed locally; independent reviews found no actionable P0–P2 defects. No CI rerun or dispatch was requested.

@steipete
steipete merged commit 31a4b92 into main Oct 12, 2026
91 of 134 checks passed
@steipete
steipete deleted the steipete/perf-micro-writer-hold-and-group-commit-20260919 branch October 12, 2026 08:33
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…nclaw#169744)

* perf(sessions): combine candidate transfer with commit admission

Carry final candidate frames with the live commit grant, retaining bounded intermediate frames and durable receipt settlement. Share envelope validation across durable and incognito consumers. A measured group-commit prototype did not relieve the queue and is not included.

* fix(sessions): constrain maintenance transfer receipts
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 19, 2026
…turn (#1475 D1)

Carry openclaw#169843 (ca0a172, "fix: chat turns fail when
session receipts exceed transport limits") onto the composite's actor
shape, plus the transfer collector it depends on from
openclaw#169744 (31a4b92, sqlite-worker-transfer.ts only).

When the committed outcome serializes past SQLITE_WORKER_MAX_MESSAGE_BYTES,
the worker frames it through live transaction admissions and commits only
a small transfer witness. The host accepts the frames, and certifies the
outcome only when the witness names the completed transfer. The receipt cap
is unchanged.

Adaptation to 855242b: admissions carry the full projected hot snapshot
(this base has no projectSessionActorAuthority), and the commit admission
has no inner kernel publication, so authorities receive undefined there as
before. Accepted cost: on oversized sessions every frame repeats the hot
snapshot; upstream later bounded the hot state itself (openclaw#172702, openclaw#174274),
which stays a separate carry.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 454e86e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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