Skip to content

perf(sessions): retain bounded transcript facts between turns - #172702

Merged
steipete merged 5 commits into
mainfrom
dbasync/warmparanoid2
Oct 15, 2026
Merged

steipete merged 5 commits into
mainfrom
dbasync/warmparanoid2

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Compact durable append receipts stopped transferring full transcript indexes, keeping receipt size independent of transcript length. Warmed turns consequently lost reusable context and anchor facts and repeatedly hydrated them from SQL. This follow-up restores reuse in the Gateway's existing actor replica without putting those indexes back into receipts.

User Impact

No intended user-visible behavior change. Ordinary warm turns reuse bounded transcript facts while cold and unsupported reads keep the canonical reader. This continues #172557 and preserves the compact-receipt property of #172462.

Design

Cold bounded hydration seeds a resident context window. Committed append deltas advance it, with at most the configured context byte/event limits plus 512 KiB / 128 events of append slack. The existing recent-event suffix remains capped at 512 KiB / 128 events; positive anchor facts are capped at 128 KiB estimated / 128 entries. Omitted anchors are unknown, never proof of absence. No full-history index is retained by the Gateway.

Identity-preserving prompt metadata rewrites update covered resident rows and preserve immutable anchors. Unsupported rewrites, resets, complex navigation, and reads outside retained coverage fall back to the canonical bounded reader. SQL-side payload limits remain in SQL. Durable input preparation remains because it supplies actual hook, retry, and pending-input custody facts.

Removed work and accepted edges

  • Repeated context and anchor hydration now consumes covered owner facts. After eviction or an unsupported rewrite, the next read may perform one cold hydration.
  • The duplicate prepared-message idempotency reread and deep comparison are removed. If another owned append claims that key while hook preparation runs, the canonical committed message wins; the hook may already have run. Final-effect authority and pending-input custody remain checked by their owners.

Measurement

Three alternating pairs (M,C,M,C,M,C), 30 individual warmed turns per revision, base 22e08398513c2b506bab8270aa6bc38901d08957 versus candidate bd609c6f75770de8cf3468432c504105826a7ace. The matched result is 26 fewer SQL statements and three fewer requests at the warmed median. Counts only; no latency claim on this busy host.

Scope, median [min–max] Base SQL Candidate SQL Base requests Candidate requests Base MAIN Candidate MAIN
Turn-caused warmed, all threads 113 [109–119] 87 [86–103] 34 [32–37] 31 [30–36] 0 [0–0] 0 [0–0]
Raw warmed windows, including background 113 [109–148] 87.5 [86–135] 35 [33–44] 32 [31–39] 0 [0–9] 0 [0–13]
First turn, turn-caused 277 [240–283] 268 [267–269] 75 [71–75] 73 [72–73] 0 [0–0] 0 [0–0]
Whole workload, per run 4267 [4262–4335] 3929 [3926–3937] 974 [966–1003] 926 [926–926] 218 [217–218] 217 [217–218]

The three warmed SQL/request median pairs were 109.5/32.5→87/31, 113/34→87/31, and 113/34→87/31. Total turn-caused warmed work: 3384 SQL/1019 requests→2655/942. Whole-workload totals: 12864/2943→11792/2778. SQL-free requests remain counted.

Warm operation SQL median, base→candidate Request median, base→candidate SQL/request totals across 30 turns
Context reader 17→0 2→0 510/60→27/3
Anchor reader 9→0 1→0 263/29→0/0
Durable input preparation 4→4 1→1 120/30→120/30

The three residual context reads are nine statements each. Durable preparation still reads real idempotency, context-state, pending-input, and row facts. The removed duplicate prepared-message check does not remove those needed input facts.

Shared native read-family warm SQL totals: exact-entry 2→0; actor hydration 2→0; entry-cache snapshot 0→0; row facts 30→30; standalone watermark 0→0. Their per-turn medians remain 0,0,0,1,0. Whole-workload totals are 77→77, 30→26, 24→21, 118→114, and 12→12 respectively. Whole exact-entry median is 25→26 despite equal total 77; this small run distribution change is disclosed, not hidden in aggregate savings. Family carrying-request counts overlap and must not be summed. All 46 flagged family memberships (37 distinct SQL shapes) already occur on baseline; expanded matchers and variable IN cardinalities account for the flags. No candidate-only SQL shape was found.

Two observed increases remain charged to causal totals: session-entry patches +30 SQL/+10 requests and shared-auth reads +6/+6. One baseline run omitted the ten activity-summary commits present in both other baseline runs and all candidate runs; provider traces also lack that baseline's interleaved recap requests. The exact admission/scheduling reason is unrecorded. It is not evidence for a timeout or backoff. Patch medians stay 15 SQL/6 requests. These unchanged summary writes advance transcript coverage even when text repeats, so suppressing them would be wrong. The baseline's recap participation differed; this is a measurement limitation, not background reclassification. Shared-auth +6 is +21 simple-completion reads associated with recap demand, offset by −15 other auth reads. Its per-turn median stays three; individual cache-miss invalidation reasons were not recorded.

Raw warmed MAIN totals are 39→21, all plugin lifecycle lease/maintenance reads. Raw first-turn MAIN median is 0→9; the same background work moved from connect/warm windows. First+warmed MAIN is [13,13,13]→[17,13,13] (median 13 both; totals 39→43); the extra four in C1 are capture-directory staging work placed in connect in other runs. Connect+first+warmed MAIN is 17 in every run (51→51 total). No new MAIN path is introduced. First-turn raw SQL/request medians also fall: 1395/174→1076/167.

The initial attempted run was excluded because its cron fixture lacked a stored inference account. A task-local harness copy now seeds a shared synthetic account through the supported owner before instrumentation, and cron selects that account. Both sides use the same repair and unchanged product assertions. This matched baseline is 113/34, not the earlier 114/31 census; historical numbers are not spliced into this comparison. All six repaired workloads passed, including child, cron, compaction and shutdown; all fixture children exited and fixtures were removed.

Receipt and memory evidence

Matched owner probe, 160 one-event appends per side Base receipt bytes median [min–max] Candidate receipt bytes Base whole-outcome bytes Candidate whole-outcome bytes
256-event history, with hydration 6378 [6367–6386] 6378 [6367–6386] 6719 [6708–6727] 6719 [6708–6727]
35,500-event history, append-only supplement 6426 [6415–6434] 6426 [6415–6434] 6768 [6757–6776] 6768 [6757–6776]

Receipt and outcome sizes match exactly within each pair. Receipt/full hot-state anchor, idempotency and completion indexes remain empty. These fixed one-event probes support compact append receipts at large history; they do not empirically establish arbitrary batch-size complexity. The two probe variants have different hydration and fixture metadata, so the 48-byte difference is not attributed solely to history size. Source and receipt regressions establish delta-only construction; this PR adds no receipt fields.

The candidate small-history probe reaches and stays at tail 128 events/166848 stored bytes, positive anchors 128/88832 estimated bytes, and a 256-row context window plus header / 326806 stored bytes. Baseline retains an exact129-event context snapshot (including header), not a window. Candidate maximum serialized replica is 388173 bytes; after warm rehydration baseline is 342052 bytes. In the large append-only pair, candidate anchors stop at 128/90624 estimated bytes and tail 128/166848 stored bytes; context is absent because hydration was not exercised. Maximum serialized replicas are 170991→225023 bytes. Each inspected collection stays within 257 entries; no full-history Gateway index returns.

Large context-hydration limitation: both original 35,500-event hydrated probes failed with the production worker timeout and produced no completed result. One observation-only baseline diagnostic located its failure at cold hydration after actor acquire/read, before any append. Candidate's original failure stage was not instrumented and is unknown. The successful append-only supplement does not turn either failed hydrated cell into a success; large-history context hydration/residency remains unproven by this live probe.

Whole-Gateway warmed phase RSS, pooled 30 samples: 2730.91 [2153.69–2823.56]→2775.20 [2701.88–2871.25] MiB. Sampled run-maximum RSS medians: 2878.81→2921.92 MiB. In the large append-only owner pair, RSS after 160 appends was989.79→750.19 MiB. These are descriptive observations, including workers, SQLite and allocator retention; main-isolate GC does not collect worker heaps. They establish neither a controlled RSS saving/regression nor a process ceiling or exact replica heap cost. Deterministic collection bounds are the stronger memory evidence.

Provenance: shared harness 2.1.0 with task-local account/RSS/receipt observation helpers, frozen identically across all six runs; run helper SHA-256 fbc3d9afa483c069bca2887a85e5d234314a839c0338e53aceee90fda5d1afed, original memory probe efae2fecc029d83bbf6cd84b4b0c724c22246b34c6973fec301fe15bc36c520b, supplemental append-only probe 8a0d3511a22599d73ccaceb99cd75fba1e902590eccd507d2febd82099761407. Source/build pins, exact per-turn counts, native owner/shape attribution, cleanup, receipt checkpoints and failed-cell evidence were reconciled before summarizing raw scratch.

Evidence

All five edited tests pass on corrected head bd609c6f757: transcript replica (16), durable reuse (2), memory transcript (8), receipt bounds (3), and input custody (12). They cover cold seeding, append reuse, metadata rewrite reuse, bounded pre-input context, eviction fallback, canonical idempotent retry, and compact receipts. Changed-file formatting, basic lint, and diff checks passed. Codex autoreview completed in two rounds: production clean through P2; numeric type correction and documentation clean through P1. A later required timestamp was added to the synthetic message fixture. Corrected-head typed lint, source contracts, Madge, production types, aggregate and all five core test-type shards, build, and T1/dialect ratchets pass in PR CI 38668303119. The exact-head Knip scan reports the same 23 rule/file/symbol tuples as current main, with zero candidate-only or touched-file findings. Both unused-file scans and script exports pass with zero findings. Knip is an inherited-static exception, not a green scan.

The five cron session-lifecycle failures match main job 116189131871: the same provenance/continuity/fallback tests fail because their automation lacks a recorded inference account. The failing test and rejection sources are unchanged. The broader dependency-scan workflow also encountered four UI consent-modal timeouts matching current main; the UI tree is unchanged. These failures are reported to the main-failure owner.

Merged as 0aadd8942f64683efa53b644d926040700f265b8 using the authorized inherited-failure exception and head-pinned REST squash fallback after the native workflow rejected this lane’s external-root layout. The required measurements above completed after merge under campaign policy.

No schema, retention, permission, public SDK, update, Doctor, plugin-loading, or service-lifecycle change. No update cell applies. Area T1: 0 → 0; whole-repository ratchet: 223 → 223 live calls and 12 → 12 deprecated compatibility calls. Changed-file dialect groups: 0 → 0. Current diff: production +278/−55 lines; tests +370/−65 lines; documentation +22/−11 lines. The added production code maintains bounded resident windows; it adds no receipt payload fields.

Publish actor transcript watermarks and bounded heartbeat and ACP facts; read interrupted prompt context without an unused count while preserving SQL payload limits.
Keep insertion, update, deletion, and lifecycle assertions while expecting the committed receipt to satisfy reads. Document the existing typed receipt invariant for the assertion-safety ratchet.
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T02:01:11.531522Z bd609c6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 15, 2026
@steipete
steipete merged commit 0aadd89 into main Oct 15, 2026
226 of 234 checks passed
@steipete
steipete deleted the dbasync/warmparanoid2 branch October 15, 2026 02:07
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…aw#172702)

Seed bounded Gateway transcript context and selected anchors from cold hydration, then advance them from existing append receipt deltas. Preserve compact append receipts and canonical fallback after eviction or unsupported rewrites.

Reuse covered metadata rewrite facts and remove the duplicate prepared-message idempotency body reread. Final-effect authority and pending-input custody remain owner-checked. No schema, retention, permission, SDK, or update change.

Required static checks and touched tests pass; inherited Knip and cron failures are documented in the PR. Three alternating SQL comparisons and long-history receipt/RSS results are tracked there.
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

docs Improvements or additions to documentation size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant