Skip to content

perf(sessions): shorten cold transcript writer holds - #200076

Merged
steipete merged 5 commits into
mainfrom
steipete/perf-cold-storage-bounded-writer-20261116
Nov 17, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/perf-cold-storage-bounded-writer-20261116

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Background cold transcript archival held the per-agent SQLite writer while converting an entire large session to navigation rows and removing its search index. Queued transcript appends could not run until that work committed.

This completes the original implementation in this PR and retains its commits. Publication is atomic per session: every archive chunk is durable before the cold marker becomes visible. Readers select that complete archive immediately. Navigation payload cleanup and FTS deletion then use separately admitted transactions capped at 256 rows, with feedback targeting 20 ms. Embedded child blobs are cleared one chunk per transaction. Each unit rechecks the cold marker; queued foreground writes can run between units, and restoration cancels further cleanup. Read-only selection discovers interrupted cleanup, including sessions whose FTS rows are already gone.

Unqualified transcript projections reconcile through their existing owner before archive preparation. Idle maintenance stays read-only. No schema, index, configuration, retention, cache, or data-format change.

Cold operations now use distinct session.cold.batch, .restore, .sweep, and .maintain transaction labels. Their existing statement attribution records native statementExecutionMs separately from callbackOtherMs; legacy sqlMs included application work and cannot alone identify the cost of SQL execution.

Evidence

Predeclared rule: five serial, interleaved A1/A2/B cycles from identical closed synthetic fixtures; both A arms use pinned main ea94eb3bd38e29d17df08a957a08fa2866355110. B must beat both controls on maximum writer hold and p99 append queue wait. A throughput or CPU regression of 20% or more blocks landing. SQL-work target is 50 ms, with a fixed row ceiling rather than a promised elapsed deadline under arbitrary I/O stalls. Report every sample.

Fixture: 37.30 GiB, 2,401 sessions, 6.05 million events. One eligible session has 50,000 events and 220,291,661 raw UTF-8 bytes; 2,400 hot siblings have 2,500 events each. Actual maintenance runs alongside 100 transcript appends, scheduled at 5 ms intervals after archival begins. The initial 200-append setup exceeded the existing 128-pending-task pool capacity and is retained as failed setup, not accepted timing evidence. No production data or systems were accessed.

Host: Apple M3 Ultra, 512 GiB RAM, Node 24.22.1, APFS. This reproduces database scale, not btrfs or a particular production I/O-pressure tail. Payloads are deliberately compressible; this is not an incompressible-file stress result. Workspace files are not traversed by this flow. Fresh cloned fixtures and fresh processes are used; warm-up precedes timing, and host load is recorded for every run.

Metric A1 A2 B
Maximum cold writer hold (ms) 1517.59 1505.59 103.88
Maximum native SQL in a cold unit (ms) 1181.09 1168.94 14.92
Median per-run p99 append queue wait (ms) 2018.00 2005.00 171.00
Median complete maintenance pass (ms) 15126.45 15086.69 16954.00
Aggregate sessions/min 3.95 3.89 3.57
Median process CPU (seconds) 16.97 16.29 18.29
Sampled lifetime allocations, separate profile runs (GB) 14.824 14.822 15.838

Writer hold includes COMMIT and excludes BEGIN wait. Append queue wait sums the preparation and mutation admissions belonging to each real append; it is not just the final write admission. Complete-pass throughput includes preparation, publication, cleanup and page reclamation. B lowers maximum cold hold about 93% and median p99 queue wait about 91%. Throughput is 8–9% lower and CPU 8–12% higher, within the declared threshold. Commit latency dominates B's longest holds; its largest native-SQL unit is 14.92 ms.

Separate instrumented A/A/B runs captured 28 allocation and CPU profiles per arm, with files verified for every observed transaction thread before teardown. Allocation sampling includes collected objects and startup/warm-up; these are allocated-byte estimates, not retained heap or latency measurements. B allocates about 7% more. Cold-owner CPU samples total 1.72 / 1.79 / 1.45 seconds; total process CPU still rises because separately admitted units add commit/admission work.

The earlier 128-row candidate was rejected: it reduced holds but increased median CPU 23% against A2. The 256-row ceiling roughly halves cleanup transaction count while preserving short native-SQL units. Its complete results remain retained alongside the accepted series.

All five samples per arm
Arm Max cold hold per pass (ms) Complete pass (ms) Per-pass p99 append queue wait (ms)
A1 1432.5, 1515.3, 1439.8, 1439.7, 1517.6 14192.4, 16256.0, 15126.4, 14910.3, 15511.1 1929, 2390, 1987, 2174, 2018
A2 1477.5, 1401.9, 1444.1, 1418.7, 1505.6 16076.1, 13634.1, 14500.8, 15086.7, 17823.2 2153, 1949, 1980, 2053, 2005
B 82.8, 80.7, 93.6, 103.9, 84.9 17025.5, 16883.4, 16954.0, 17318.0, 15757.9 167, 171, 183, 182, 160

At five samples, nearest-rank p95 is the observed maximum. No samples were discarded.

Correctness and validation

The navigation regression fails on pinned main (eight unbounded updates instead of the bounded update, with untouched rows required to retain their exact payloads). Statement-attribution regression cases also fail on main. Tests cover interrupted navigation and FTS cleanup, restart with no FTS rows remaining, atomic rollback, exact restoration after partial cleanup, embedded-chunk recovery, foreground admission between units, and idle read-only maintenance.

Local proof is green: 66 focused backend tests (cold storage, crash recovery, admission, search worker, and native-SQL diagnostics), 17 affected Control UI browser tests, 4 transcript-search UI e2e tests, pnpm check:changed --base ea94eb3bd38e2, changed-script lint/format, and git diff --check. Codex autoreview is scoped-clean on the final staged implementation and profiling fix. The frozen-target follow-up at 419235050498c31ba7f24e576212c431ea36626b also passes 32 consumer tests, the tooling test typecheck, shell syntax, pnpm check:changed --base 1268ef13, and scoped-clean Codex review through P2. It changes no runtime storage code, so the A/A/B and affected UI proof remain applicable. Hosted CI and ClawSweeper must qualify the exact final head before landing.

Limits and implementation cost

Foreground restoration remains one atomic transaction and can still be long. File verification remains inside archive publication; statement attribution now exposes that application cost separately. Archive preparation still holds a long read snapshot, and recovery discovery can scan completed cold navigation rows outside writer admission; this PR does not claim to bound every read or every filesystem delay. Existing primary keys support the bounded write ranges, so no index proposal is required for this fix.

Production TypeScript delta against main is +309 lines, including the original PR's implementation. Growth implements the shared bounded cleanup operation, recovery selection and admission flow; extraction of the existing mutation adapter into its own file is mechanical. There is no second state owner or durable cleanup queue.

Reproduction uses the committed scripts (all directories must be new synthetic paths):

node --import ./scripts/tsx.mjs scripts/perf/session-cold-writer.mjs --prepare --state-dir <seed>
node scripts/perf/session-cold-writer-padding.mjs <seed> 2400
# Clone the closed seed for each run. Add --source-root <pinned-main> for A1/A2.
NODE_OPTIONS=--import=./scripts/perf/session-cold-writer-observer.mjs node --import ./scripts/tsx.mjs scripts/perf/session-cold-writer.mjs --state-dir <copy> --flow --appends 100
# Separate instrumented A/A/B runs: existing output directory, all-thread CPU/allocation profiles.
OPENCLAW_COLD_WRITER_PROFILE_DIR=<profiles> NODE_OPTIONS=--import=./scripts/perf/session-cold-writer-observer.mjs node --import ./scripts/tsx.mjs scripts/perf/session-cold-writer.mjs --state-dir <copy> --flow --appends 100

Existing-data compatibility: pre-fix main ea94eb3bd38e29d17df08a957a08fa2866355110 created and archived two synthetic sessions with 3,000 events. The candidate restored those persisted archives with an identical SHA-256 over transcript bytes, navigation, metadata and search rows, and unchanged settings. Additional running-Gateway and stable-to-candidate state-upgrade proof is recorded below. Frozen-target detection now accepts both old and bounded navigation call shapes, preserving the legacy archival distinction from #190716; both Docker consumers have red-before/green-after regression cases.

Running Gateway and stable-data upgrade

Built exact head 419235050498c31ba7f24e576212c431ea36626b with pnpm build:ci-artifacts. An isolated running Gateway received sessions.storage.run and concurrent chat.inject RPCs: 10,003 events / 45,272,371 bytes archived, 122 foreground appends completed, 27 appends completed between the archived session’s 82 cold write transactions. Observer classification was restricted to the archived session ID so foreground FTS inserts were not counted as cold work. Subsequent RPC restoration preserved every original transcript byte and timestamp. This is product-boundary correctness/interleaving proof, not another latency benchmark.

The published 2026.11.5 Gateway imported synthetic sessions, archived two of them in its older archive format, and retained disabled cold-storage settings with the seven-day policy. After a clean stop, the candidate Gateway started on that same state, served all histories, and restored both archives through chat.inject; all nine original events and timestamps and the selected configuration sections survived exactly. Both Gateways stopped cleanly. This tests the persisted-state upgrade through a binary switch, not the package updater itself.

Main’s package version is 2026.11.4, behind the published baseline. The initial direct start correctly refused a downgrade. For the proof only, a separate copy of the exact built artifact was relabeled to 2026.11.5 with the existing stampFixtureVersion helper used by published-driver.mjs; commit/build identity and compiled code were preserved. No downgrade override, source version change, release, or live-state access was used. The initial stable harness also correctly exposed the legacy no-hot-row archive dialect; the final verifier checks exact restored data rather than imposing current navigation layout on stable.

Sanitized proof output:

{"gatewayRpc":true,"events":10003,"rawTranscriptBytes":45272371,"concurrentAppends":122,"appendCompletionsBetweenColdTransactions":27,"coldTransactions":82,"exactRestoration":true}
{"baseline":"2026.11.5","candidate":"419235050498c31ba7f24e576212c431ea36626b","settingsUnchanged":true,"archivedSessionsRestored":2,"originalTranscriptEventsPreserved":9,"gatewayUpgradePassed":true}

@clawsweeper

clawsweeper Bot commented Nov 16, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T21:50:13.944351Z 4192350 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 docs Improvements or additions to documentation scripts Repository scripts size: L labels Nov 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR publishes cold transcript archives atomically, then releases the writer between bounded navigation and search-index cleanup transactions.

Example: Archiving a 50,000-event session while foreground transcript appends are queued.

  • Before: The supplied baseline measurements show maximum cold writer holds of approximately 1,518 ms.
  • After: Cleanup admits at most 256 rows per unit, with approximately 104 ms maximum writer hold in the supplied candidate measurements.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, correct, and proven through the running Gateway and stable-state boundary, with explicit performance tradeoffs and passing current-head gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Public sanitized exact-head Gateway output exercises sessions.storage.run alongside real chat.inject RPCs, demonstrates foreground progress between cleanup transactions, and verifies exact restoration; stable 2026.11.5 state also loads and restores unchanged after the documented fixture-version adjustment.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Background archival of a large session delays queued foreground transcript appends.
Reason: The maintainer-authored direction delivers a measured reduction in writer holds and append queue waits, with explicit acceptance of the throughput, CPU, allocation, and remaining read-scan costs.

Merge readiness

✅ Ready for maintainer review

This PR is ready for normal landing: the previous classifier and upgrade-proof blockers are resolved, current-head CI passes, and no additional blocking defect was found.

Priority: P2
Reviewed head: 419235050498c31ba7f24e576212c431ea36626b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway maintenance selects inactive sessions, prepares durable archives, and uses the existing agent database writer to publish archives and clean derived rows while foreground writes share admission.

flowchart TD
  A[Gateway maintenance] --> B[Archive preparation worker]
  B --> C[Durable archive files]
  C --> D[Atomic cold marker publication]
  D --> E[Bounded cleanup transactions]
  F[Foreground transcript writes] --> G[Agent database writer]
  E --> G
  D --> H[Cold history readers]
Loading

Technical review

Best possible solution:

Land atomic per-session archive publication and bounded cleanup through the existing writer, retaining exact restoration and cold-marker recovery.

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

The baseline source performs whole-session navigation conversion and FTS deletion under one writer transaction, matching the supplied interleaved baseline measurements; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change addresses writer monopolization at its existing owner while preserving atomic archive publication and restoration; the extracted mutation adapter retains a complex existing boundary, and no competing durable cleanup owner is introduced.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Atomic cold archival and navigation retention keeps the original intent (fce0e56: Retain navigation so bounded history reads can serve cold archives without restoring an entire transcript.)
  • Cold maintenance transaction boundaries changes intended behavior with a stated reason (43dc38e: Reduce selection and transaction work while preserving eligibility, protection, and atomic restoration; this PR further splits derived cleanup to reduce measured writer monopolization.)
  • Frozen-target archive contract detection keeps the original intent (02f6c40: Distinguish published legacy archives from retained-navigation implementations so release fixtures use the correct read and restore expectations.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Bounded cleanup through existing owners: The introduced loop publishes sessions separately and repeatedly admits navigation, FTS, and embedded-chunk cleanup through the existing mutation and agent-writer owners. (src/config/sessions/session-cold-storage.ts:191, 419235050498)
  • Previous classifier finding resolved: Frozen-target detection now accepts both navigation call shapes, and the added consumer fixtures exercise the bounded multiline call through both Docker entry points while retaining legacy detection. (scripts/lib/frozen-target-compat.sh:360, 419235050498)
  • Running Gateway and stable-state proof: The public body and author response record exact-head sessions.storage.run with 122 concurrent chat.inject appends, 27 append completions between cold transactions, exact restoration, and a published 2026.11.5-to-candidate state transition preserving legacy archives, events, timestamps, and settings. (419235050498)
  • Accepted performance tradeoffs: The maintainer-authored body explicitly records lower throughput, higher CPU and allocations, potentially long restoration and preparation snapshots, and recovery scans over completed cold navigation rows; these are accepted limits of the focused writer-hold improvement. (src/config/sessions/session-cold-storage-selection.ts:167, 419235050498)
  • Current-head gates pass: The live combined status reports openclaw/ci-gate success with applicable security requirements passed; the two cancelled check runs are not diff-caused failures. (419235050498)
  • Related search work remains distinct: The merged fix: agent session searches stall on large histories #200355 removes inventory paging from transcript search and explicitly identifies this PR's separate cold-exclusion integration; it does not implement bounded archival cleanup. (src/config/sessions/session-transcript-search.worker.ts:247, a564030a2b6e)

Likely related people:

  • Peter Steinberger: Raw commit fce0e56 adds src/config/sessions/session-cold-storage-navigation.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fce0e56fc0a6; files: src/config/sessions/session-cold-storage-navigation.ts)
  • Vincent Koc: Raw commit 02f6c40 adds scripts/lib/frozen-target-compat.sh:327 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 02f6c40c5656; files: scripts/lib/frozen-target-compat.sh)

PR surface

Source +309, Tests +245, Docs +7, Other +868. Total +1429 across 27 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 13 615 306 +309
Tests 7 260 15 +245
Docs 2 11 4 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 5 869 1 +868
Total 27 1755 326 +1429

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Cold archival can delay foreground transcript appends on large databases; this is a measured performance improvement with a limited maintenance-path blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • 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 execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-16T11:02:12.456Z sha 7b638e2 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-17T21:33:10.224Z sha 1268ef1 :: blocked before merge. :: [P2] Update frozen-target detection for bounded navigation cleanup
  • reviewed 2026-11-17T21:58:28.479Z sha 4192350 :: blocked before merge. :: none

Reviewed November 17, 2026, 5:15 PM ET / 22:15 UTC (Revision 4).

Preserve native SQLite method descriptors in the benchmark and await the interactive write directly in the sweep test. Align the inherited CLI JSON failure assertion with its existing reported-error contract.
Prepared identity and active-event inserts saved about 18 ms of query compilation in a 12 s restore; drop them to keep the change focused on the measured archive holds.
Publish archives per session, then clear navigation payloads and FTS rows in separately admitted units capped at 256 rows. Resume interrupted cleanup through the existing cold marker and clear embedded chunks individually. Split cold operation labels and distinguish native statement time from callback work. Preserve synchronous commit sections and atomic restoration.

Validated with 37.3 GiB synthetic A/A/B and concurrent transcript appends, allocation and CPU profiles, focused backend and Control UI tests, check:changed, and independent review.
@steipete
steipete force-pushed the steipete/perf-cold-storage-bounded-writer-20261116 branch from 7ba585e to 1268ef1 Compare November 17, 2026 21:10
@openclaw-barnacle openclaw-barnacle Bot added size: XL and removed cli CLI command changes size: L labels Nov 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The completed follow-up is pushed at 1268ef13aaf9d0eb0abce135410d4eecbbb49571, rebased on current main at the start of this work and retaining the original PR commits. The prior review has zero open numbered findings.

The remaining large-session gap is addressed by 256-row navigation/FTS units with separate admission, per-unit cold-marker checks and one-child blob cleanup, and read-only interrupted-cleanup discovery. Distinct transaction labels and existing statement attribution separate native SQL from application work.

The body now contains five-cycle A/A/B on 37.3 GiB synthetic state with real concurrent transcript appends: maximum cold hold 1518/1506/104 ms; median per-run p99 queue wait 2018/2005/171 ms; maximum candidate native SQL 15 ms. Throughput, CPU and allocation costs are retained. Local checks, 66 focused backend tests, 21 UI browser/e2e tests and independent Codex review are green. Foreground restore and read-snapshot limitations remain explicit. Exact-head CI is pending.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1268ef13aa

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +171 to +175
return retainSessionColdNavigationInTransaction(
database,
input.sessionId,
input.afterSeq,
input.maxRows,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update frozen-target detection for the bounded navigation writer

When this commit is selected for frozen-target validation, scripts/lib/frozen-target-compat.sh:360-368 no longer recognizes its cold-storage contract: it searches for the exact string retainSessionColdNavigationInTransaction(database, sessionId), which this refactor removes. Both its navigation and legacy predicates therefore become false, entering the error case and returning status 2. The frozen-target runs of scripts/e2e/openai-chat-tools-docker.sh and scripts/e2e/session-runtime-context-docker.sh consequently stop before running their scenarios. Update the classifier and its fixtures alongside the new bounded call while preserving detection of older shipped implementations.

AGENTS.md reference: AGENTS.md:L55-L55

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The previous request was superseded while the required PR-context headings were corrected. The body is now settled, native preparation is complete, and head remains 1268ef13aaf9d0eb0abce135410d4eecbbb49571. No source changed after the scoped-clean local Codex review. The prior review has zero numbered open items; the bounded cleanup, recovery, attribution and synthetic proof details are in the body. Please review this final head.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed 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 Nov 17, 2026
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Nov 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing all three open items against 4192350:

  1. Frozen-target detection: fixed at scripts/lib/frozen-target-compat.sh:360. It recognizes the navigation call independently of its argument list. The consumer fixtures at test/scripts/live-docker-stage.test.ts:222 exercise the multiline bounded call through both Docker entry points. Both cases failed before the predicate fix with status 2 and “unable to resolve frozen cold transcript archival contract”; all 32 tests pass after it. Existing legacy, old-navigation, authorization and unknown-writer cases still pass.

  2. Existing stored data: there is no schema, archive-format, configuration or retention change. I added a cross-revision compatibility check: pinned pre-fix main ea94eb3bd38e29d17df08a957a08fa2866355110 created and archived two synthetic sessions (3,000 events), then this implementation opened those persisted archives and restored them. Exact transcript bytes, navigation, metadata, search rows and settings match. The before/after SHA-256 is 2baed0612731a634da088be778b7b2c0c19d5e1eaf1451824930bf025ce9268e. Existing embedded-chunk compatibility is covered at session-cold-storage.chunks.test.ts:324, including re-externalization, bounded cleanup and exact restoration. The archive reader/record format is unchanged. This is a pre-fix-main data compatibility check, not a claim of a full application upgrade from v2026.11.5. The identified frozen-target bug prevented a validation scenario from starting; it did not establish incompatible stored data.

  3. Original frozen-target intent: inspected 02f6c40c5656938e785cd00f501c148ee67d60b4 / fix(ci): align cold-storage fixtures with retained navigation #190716. Its contract distinguishes published legacy archival, which restores on reads, from retained-navigation archival, which serves cold history without restoration. That distinction and the legacy predicate remain intact at frozen-target-compat.sh:358-367. Only the brittle old argument-list match changed. Both older call shapes and legacy implementations remain recognized; unknown implementations still fail closed.

Validation: 32 consumer tests, tooling test typecheck, shell syntax, pnpm check:changed --base 1268ef13, git diff --check, and scoped-clean Codex autoreview through P2. Storage implementation is unchanged from the five-cycle A/A/B and 66-backend/21-UI-test proof already recorded in the body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4192350504

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +170 to +174
.selectFrom("transcript_events")
.select(["event_json", "event_zstd", "event_utf8_bytes", "navigation_json"])
.where("session_id", "=", cold.session_id)
.where((eb) =>
eb.or([eb("event_json", "is not", null), eb("event_zstd", "is not", null)]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound cleanup discovery for already-clean cold sessions

For stores with substantial archived history, every maintenance pass now scans the retained transcript rows of every fully cleaned cold session. Once its FTS rows and embedded chunks are gone, hasCleanup is false, so this query must inspect the session's rows to establish that no removable payload remains; the existing (session_id, seq) index cannot filter by payload presence. The pending.length limit never bounds this work when sessions are clean. Because Gateway maintenance runs every 60 seconds, even an idle store repeatedly reads its entire cold transcript inventory, introducing growing CPU and I/O costs precisely after archival completes. Make completed-session discovery indexable or bound the recovery scan with resumable progress instead of rescanning all completed history each pass.

AGENTS.md reference: AGENTS.md:L70-L70

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot removed merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the sole remaining open item on 419235050498c31ba7f24e576212c431ea36626b:

  1. Data-model compatibility / running-Gateway proof: completed both requested boundaries on synthetic state. A running candidate Gateway handled sessions.storage.run plus 122 concurrent chat.inject calls while archiving 10,003 events / 45,272,371 bytes. Twenty-seven foreground appends completed between the archived session’s 82 cold write transactions; classification was restricted to that session ID. RPC restoration preserved exact original bytes and timestamps. The shipped method is sessions-maintenance.ts:42; the bounded writer loop remains session-cold-storage.ts:191.

    Separately, the published 2026.11.5 Gateway imported synthetic data and created two legacy-format cold archives. After a clean stop, the candidate Gateway started on the same state, served history and restored both archives through chat.inject. All nine original events/timestamps and the session, agent, Gateway, plugin and logging settings remained exact. This is a stable-to-candidate persisted-state upgrade through a binary switch, not a test of the package updater.

    Main currently identifies as 2026.11.4. The direct attempt correctly hit the downgrade guard. The successful isolated proof used a separate copy of the exact built artifact, relabeled to 2026.11.5 through the existing stampFixtureVersion workflow, as published-driver.mjs already does for a lagging main version. Compiled code and commit/build identity were preserved; no downgrade override or repository version change was used. Both Gateways stopped cleanly. Sanitized result logs and these limits are now in the PR body.

The earlier classifier and provenance items remain fixed and covered by the 32 passing consumer tests. No source changed after the last review. pnpm build:ci-artifacts also passed on this exact head.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Nov 17, 2026
@steipete
steipete merged commit 807ecef into main Nov 17, 2026
173 of 175 checks passed
@steipete
steipete deleted the steipete/perf-cold-storage-bounded-writer-20261116 branch November 17, 2026 22:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
* perf(sessions): shorten cold transcript writer holds

* perf(sessions): repair cold storage proof checks

Preserve native SQLite method descriptors in the benchmark and await the interactive write directly in the sweep test. Align the inherited CLI JSON failure assertion with its existing reported-error contract.

* perf(sessions): keep cold restore record inserts unchanged

Prepared identity and active-event inserts saved about 18 ms of query compilation in a 12 s restore; drop them to keep the change focused on the measured archive holds.

* perf(sessions): bound cold cleanup writer units

Publish archives per session, then clear navigation payloads and FTS rows in separately admitted units capped at 256 rows. Resume interrupted cleanup through the existing cold marker and clear embedded chunks individually. Split cold operation labels and distinguish native statement time from callback work. Preserve synchronous commit sections and atomic restoration.

Validated with 37.3 GiB synthetic A/A/B and concurrent transcript appends, allocation and CPU profiles, focused backend and Control UI tests, check:changed, and independent review.

* fix(ci): recognize bounded cold navigation targets
RomneyDa added a commit that referenced this pull request Nov 18, 2026
* fix(update): include cold archives in candidate snapshots

Co-authored-by: steipete <[email protected]>

* fix(update): preserve file archives in rehearsal snapshots

Co-authored-by: steipete <[email protected]>

* fix(update): preserve source WAL state during archive inventory

Classify cold archive SQL under its existing candidate-state subprocess owner. Preserve incomplete WAL source families so header inspection retains private cleanup custody.

Co-authored-by: steipete <[email protected]>

---------

Co-authored-by: steipete <[email protected]>

Release adaptation: the baseline does not contain the #195487 header-cleanup
suite. Keep that unrelated suite absent; carry the new incomplete-WAL inventory
assertions into the existing inventory suite instead. Add a per-change 214-line
allocation for the source regression, chunk fallback, and WAL preservation tests.
No schema, updater protocol, authority, or archive-integrity changes.

Companion audit at 9e917f0:
- #200733 is selected as the next dependency-closure repair: missing archives
  must warn instead of blocking updates, and Windows copies must not share live
  read-only inode attributes. Do not qualify this intermediate checkpoint alone.
- #200076 and #200930 are independent cold-history performance changes, not
  prerequisites for this snapshot repair.
- #201009, #200994, #200866, #200577, #200805, #200802, and #200732 overlap only
  adjacent update documentation and independent repair flows; not prerequisites.

Proof on base 309067b:
- New production-subprocess regression: 4/4 fail before, 4/4 pass after.
- Cold archives, chunks, and inventory: 31/31 pass after.
- Additional budget/cleanup/import siblings: 46/47 pass. Configured-cache
  containment fails identically on the unchanged base at budget.test.ts:737;
  retained as an independent failure, not weakened or repaired here.
- Targeted lint and format, documentation links, SQLite worker ratchet, and
  test-line ratchet pass. SQLite T1 counts remain 170; compatibility 15.
- Worker typecheck was blocked at dependency custody, without guard bypass.
  Parent canonical core typecheck, typed lint (five files), and formatting
  passed with its owned dependencies. Full installed-upgrade/FRV proof remains
  pending the assembled candidate, including selected companion #200733.

(cherry picked from commit 802e3f7)

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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