Skip to content

perf(sessions): keep closed-turn transcript work in workers - #169052

Merged
steipete merged 8 commits into
mainfrom
dbasync/t1transcript
Oct 11, 2026
Merged

steipete merged 8 commits into
mainfrom
dbasync/t1transcript

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closed-turn transcript persistence retained a main-thread incognito outbox fallback, and suffix replacement read the same source and projection facts repeatedly while preparing and applying a single mutation.

User Impact

Transcript suffix replacement preserves stale-input rejection and committed transcript bytes with fewer reads. Incognito outbox operations use their existing session actor; an unbound incognito session fails with the existing missing-session error instead of opening native state.

Why This Change Was Made

Prepare and apply suffix replacement in one synchronous writer transaction. Retain one exact source comparison and the caller-provided mutation timestamp check, plus writer authority and rollback. Remove the exported preparation path and its second source read, repeated mutation reads, duplicate projection-health check, and pre-transaction hot-state check. Mark the closed-turn range module as worker-only; retain the outbox worker cutover now also present on main.

Final-base T1 inventory: 635 → 629 (−6) against 2c1f8c167747805bee91c55970f1b5f5fd0665f5. All six calls are the range module now accurately classified as worker-only. The original measured base was 705 → 687 (−18); main independently absorbed the outbox cutover before this final integration. The twelve named transcript hot spots total 125 → 119 T1 calls; the six-call range module accounts for that scoped reduction. The remaining transcript/index/history/archive kernels still have released synchronous SDK or maintenance callers; they remain T1. Reclassifying those kernels would conceal reachable work. Their complete cutover needs an owner/API change outside this scoped patch. Remaining named counts are unchanged: transcript-state 14, suffix 12, projection-rebuild 12, index 9, transcript-write 6, parent 5, history-interval 8, active-events 5, active-context 6, archive-store-kernel 6, and node-artifacts 26. Native SessionManager.persist()/append and unbound compaction still reach index/projection kernels; reconciliation's maintenance/deletion fallback reaches the archive/artifact kernels. These are the calls stopped under the owner-redesign escape hatch, not worker-only implementations.

Removed checks and accepted edge cases:

  • Re-reading suffix bytes after planning: the exact source read and replacement now share one synchronous transaction. Reentrant test instrumentation that mutates during statement preparation is not a supported writer.
  • Rechecking the mutation revision after planning and before apply: no await or competing writer occurs inside the transaction. A stale caller still fails its one input comparison.
  • Rechecking projection health during apply: the transaction's prepared projection fact remains authoritative until commit.
  • Checking hot storage before entering the writer: retain the in-transaction check; do not protect a theoretical transition between two checks.

No schema, migration, retention, update, Doctor, plugin loading, service lifecycle, or SDK surface changes.

Evidence

Shared harness, three alternating pairs on the same Blacksmith Testbox, baseline 4ea3e6bc0b9f781feea0ac744dd4428c63344367 versus this patch. Values are median [min–max].

Per warmed turn Base Candidate
All-thread statements 408.5 [407.7–409.0] 411.7 [407.9–424.7]
Requests 93.2 [93.2–93.4] 93.1 [93.0–93.7]
MAIN statements 4.1 [4.1–4.1] 4.1 [4.1–4.1]
Duration, ms 1432.8 [1405.0–1451.5] 1449.4 [1419.0–1488.9]

The measured warmed transcript operations emit identical SQL and requests: anchors 12 statements/1 request, hydration 27/2, actor append 23/2, delivery settlement 7/2, patch commit 64/7, and patch prepare 6/3 per turn. The harness does not execute suffix replacement or incognito outbox operations; it therefore does not establish a warmed SQL saving for the modified paths.

The raw increase triggered the required extra alternating pair on a fresh Testbox after the original lease expired:

Extra pair Base Candidate
Warmed statements/turn 407.8 407.7
Warmed requests/turn 93.3 92.9
MAIN statements/turn 4.1 4.1
First-turn statements 1164 1354
First-turn requests 201 201
Startup-to-shutdown statements 10834 10948
Startup-to-shutdown requests 1746 1753
Startup-to-shutdown duration, ms 42987 43364

Extra SQL is repeated admission in unchanged readers: +19 each user_version, schema_version, and schema-catalog reads; +13 primary schema metadata reads; +6 each canonical-table setup statements. The extra pair's unchanged reader families include exact entries (+32 statements), membership (+22), tombstones (+16), entry (+11), corpus inventory (+11), and transcript stats (+10); offsets in other families bring the total to +114. No changed suffix/outbox operation ran. Coordinator accepted this +114-statement (+1.05%) / +7-request cold admission overhead on 2026-10-11: moving Gateway SQLite off the main thread is the mission and warmed turns are neutral. This limitation is accepted for this PR; it is not reported as a warmed query-reduction win.

Product source was pinned at d992ea4bb0a8be8efe9ee4facb007c002e4bccc6; measurement carrier commits add only task-owned proof bootstraps. The canonical workload and observer were unchanged, with census hooks shared by the campaign. All workload runs passed and duration ratios stayed below 1.5.

Blacksmith Testbox: all 179 focused tests passed on the integrated candidate (six files; pnpm test <files> --maxWorkers=1 via the repository runner, 145.54 seconds wall time / one remote job). Coverage includes stale full/incremental suffix input after an intervening append, bound actor outbox read-after-write, missing incognito actor rejection, closed-turn delivery, attempt handling, and canonical descendants.

check:changed --base 4ea3e6bc0b9f781feea0ac744dd4428c63344367 passed, including core/test typechecks, type-aware Oxlint, Knip exports, T1 and dialect ratchets, and source contracts. Separate Madge and export-collision checks passed. SDK API diff and published-driver update cell are not applicable to the touched surfaces.

Production/test LOC: +54/−111 production (net −57), +55/−66 tests (net −11); +22/−1 inventory tooling and +39/−24 generated inventory/documentation. Generated inventory and documentation are reported separately. Reviewed with the Codex autoreview engine: no actionable P0/P1 findings.

Earlier integrated-head verification (008e0df702461075febeeaafea851863a9f4c518): all 179 focused tests also passed after the first conflict-only integration (148.38s). All planned static commands completed on the final head: core and test typechecks, source contracts, T1/dialect ratchets, script lint and root-test lint passed. The max-lines suppression check fails on untouched src/web-search/runtime.test.ts; the same rule/file was reproduced on baseline ac8a432aafa73674f8e41ab2132860d8901c6dcb. Knip reports the same 28 production/full-tree export entries on candidate and that baseline (MCP UI components and one subagent registry export). Type-aware Oxlint reports the same 15 max-lines errors on the same untouched files on both revisions. No changed file has a static failure. Separate Madge and export-collision checks passed. The latest conflict integration adopts main’s outbox worker kernel and migrates its range import; it adds no SQL. On final head adfe6943727a9f2dfc5da279b0a0862e4c71cb66, the three affected outbox/attempt suites passed (96.81s), type-aware Oxlint for all three affected production modules passed, and export collisions, T1 and dialect ratchets passed. Knip’s 50 production/full-tree entries exactly match the same files and symbols on the integration base 2c1f8c167747805bee91c55970f1b5f5fd0665f5; none is a changed module.

Landing uses the RELAXED LANDING v4 head-pinned REST squash fallback after two native review allocation failures; the owned stale operation lock was recovered. Required CI/security status is checked on the exact head before dispatch. Final diff: 16 files, +128/−163.

@clawsweeper

clawsweeper Bot commented Oct 11, 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 scripts Repository scripts agents Agent runtime and tooling size: M labels Oct 11, 2026
# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
# Conflicts:
#	docs/reference/database-schemas/worker-access-inventory.md
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR combines transcript suffix planning and replacement in one writer transaction, classifies closed-turn reads as worker-only, and rejects unbound incognito outbox operations.

Example: Start a turn in agent:main:dashboard:incognito-demo with a durable context engine and no actor binding.

  • Before: The base catches the generic execution-owner error and begins the turn with the legacy fallback.
  • After: IncognitoSessionMissingError escapes admission and stops the turn before it begins.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Owner-level test evidence supports the suffix simplification, but the source-reproducible incognito admission regression blocks merging.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; reported focused tests exercise real SQLite and worker owners, while the benchmark explicitly excludes the changed suffix and incognito outbox operations.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated transcript reads and synchronous outbox work increase session persistence cost.
Reason: The maintainer-authored direction fits the existing worker ownership contract and reduces duplicate suffix work without expanding configuration or public APIs.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: the suffix transaction simplification is useful, but the typed missing-owner rejection still prevents supported native incognito turns from starting.

Priority: P1
Reviewed head: adfe6943727a9f2dfc5da279b0a0862e4c71cb66

Before merge

  • Preserve native incognito admission until actor activation (P1) - An ordinary native incognito session has no actor binding: attempt preparation explicitly retains its native owner, and actor acquisition remains inactive. With a durable context engine and a transcript recorder or admission, prepareRun reaches this guard and throws IncognitoSessionMissingError. drainPendingContextEngineTurnsBeforeRun rethrows that typed error, so beginContextEngineLogicalTurn never reaches lease.begin. On the pinned base, execution capture instead raises a generic native-owner error, which the same catch degrades to the legacy engine and allows the turn to begin. Main has independently absorbed worker dispatch, so the earlier finding should now be repaired by deferring this typed refusal rather than restoring the removed main-thread dispatch. Creating another native incognito session does not resolve the missing binding.
  • Explain or restore the original intent of Unbound native incognito admission - 7d88b6f: Actor composition remained inactive, with native routing preserved until atomic activation; the new refusal does not account for valid native sessions.

Findings

  • [P1] Preserve native incognito admission until actor activation — src/agents/harness/context-engine-turn-outbox-store.ts:33-35

Provenance

  • Unbound native incognito admission changes intended behavior without addressing why it exists (7d88b6f: Actor composition remained inactive, with native routing preserved until atomic activation; the new refusal does not account for valid native sessions.)

Tests

  • Missing end-to-end proof: The supplied proof does not exercise ordinary native incognito acquisition through turn admission, and the new suffix cases have no recorded failing-base run.
Agent review details

How this fits together

The session persistence and context-engine outbox owners consume transcript events and turn admissions, execute SQLite work, and return committed transcript facts or pending turn advancement.

flowchart TD
A[Session turn] --> B[Outbox store]
B --> C[Agent or incognito worker]
C --> D[SQLite transaction]
E[Suffix replacement] --> D
D --> F[Committed transcript facts]
Loading

Technical review

Best possible solution:

Keep the suffix simplification and existing worker cutover, and defer typed unbound-incognito refusal until runtime acquisition installs the actor binding.

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

The current source establishes the failure through native acquisition, missing binding, typed rejection, and admission rethrow; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Combining suffix planning and mutation is coherent under the single synchronous writer owner, but rejecting every unbound incognito target is premature while native acquisition remains supported.

Full review comments:

  • [P1] Preserve native incognito admission until actor activation — src/agents/harness/context-engine-turn-outbox-store.ts:33-35
    An ordinary native incognito session has no actor binding: attempt preparation explicitly retains its native owner, and actor acquisition remains inactive. With a durable context engine and a transcript recorder or admission, prepareRun reaches this guard and throws IncognitoSessionMissingError. drainPendingContextEngineTurnsBeforeRun rethrows that typed error, so beginContextEngineLogicalTurn never reaches lease.begin. On the pinned base, execution capture instead raises a generic native-owner error, which the same catch degrades to the legacy engine and allows the turn to begin. Main has independently absorbed worker dispatch, so the earlier finding should now be repaired by deferring this typed refusal rather than restoring the removed main-thread dispatch. Creating another native incognito session does not resolve the missing binding.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Exact transcript suffix planning and replacement changes intended behavior with a stated reason (68be5fd: fix: sessions_yield keeps long transcript history available #137381 introduced exact suffix mutation to keep long yielded histories readable, preserve concurrent appends, and rotate stale cursors.)
  • Closed-turn worker dispatch and range module keeps the original intent (e63b5a0: The merged agent-preparation change moved outbox SQL into its execution worker; this PR preserves that dispatch and renames the unchanged range kernel.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/harness/context-engine-turn-attempt.test.ts src/agents/harness/context-engine-turn-outbox.test.ts src/state/openclaw-agent-execution-incognito.outbox.test.ts --maxWorkers=1
  • pnpm test src/config/sessions/session-accessor.sqlite-transcript-store.test.ts --maxWorkers=1
  • pnpm check:changed --base 2c1f8c1
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e63b5a0 adds src/agents/harness/context-engine-turn-outbox-store.ts:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e63b5a01cf26; files: src/agents/harness/context-engine-turn-outbox-store.ts)
  • Josh Lehman: Raw commit 68be5fd adds src/config/sessions/session-accessor.sqlite-transcript-suffix.ts:170 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 68be5fdcd14b; files: src/config/sessions/session-accessor.sqlite-transcript-suffix.ts)
  • WhatsSkiLL: Raw commit 715b24a adds src/agents/harness/context-engine-turn-outbox-store.ts:45 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 715b24a194ae; files: src/agents/harness/context-engine-turn-outbox-store.ts)

PR surface

Source -37, Tests -11, Docs +13, Other 0. Total -35 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 54 91 -37
Tests 5 55 66 -11
Docs 2 18 5 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 16 128 163 -35

Review metrics

Metric Value Why it matters
Production versus test LOC Production +54/−111; tests +55/−66 The internal suffix simplification reduces production code; the unchanged range-module rename contributes no net code growth.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The introduced typed rejection stops native incognito turns with a durable context engine before execution begins.
  • merge-risk: 🚨 compatibility: Existing native incognito sessions lack the inactive actor binding and lose the base's recoverable degradation path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 (2 earlier review cycles)
  • reviewed 2026-10-11T10:11:40.282Z sha 008e0df :: needs changes before merge. :: [P1] Retain native incognito outbox dispatch until actor activation
  • reviewed 2026-10-11T11:31:50.903Z sha 008e0df :: needs changes before merge. :: [P1] Retain native incognito outbox dispatch until actor activation

Reviewed October 11, 2026, 7:47 AM ET / 11:47 UTC (Revision 3).

@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Oct 11, 2026
@steipete
steipete merged commit 599d0de into main Oct 11, 2026
130 checks passed
@steipete
steipete deleted the dbasync/t1transcript branch October 11, 2026 11:48
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…#169052)

Classify closed-turn range reads in the worker and keep incognito outbox operations on their actor. Prepare and apply transcript suffix mutations in one transaction, removing repeated internal checks while preserving the append/source integrity check.

T1 calls decrease from 635 to 629 on the final integration base. Warmed-turn SQL is neutral; the measured +1.05% whole-workload admission overhead is accepted for this worker cutover. Focused tests and static gates pass; inherited lint and Knip failures match main.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 19, 2026
First-parent upstream 75df19c..5ed6a30 (23 commits, including
openclaw#169005 infrastructure SQLite work and runtime-write offload, openclaw#169062,
openclaw#136677, openclaw#169070, openclaw#168857 plugin-sdk SQLite runtime writes into workers,
openclaw#169038, openclaw#168916, openclaw#169053, openclaw#169052 closed-turn transcript work in
workers, openclaw#168974, openclaw#168811, openclaw#169082, openclaw#169084, openclaw#166581 worker heap limits).

Conflicts:
- openclaw-state-worker-runtime.ts: upstream routes more update-run
  mutations to the worker; our continuation custody dispatch stays ahead
  of that branch.
- worker-access inventory: regenerated (632 files, 2429 calls).

server-restart-sentinel.ts auto-merged: upstream's awaited update-run
writes; our continuation restart delivery is unaffected.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant