Repository navigation
perf(sessions): skip cold envelopes for transcripts over the archive limit - #183378
Conversation
…limit Cold storage learned that a transcript exceeds the 64 MiB uncompressed archive limit only after building its whole envelope inside a read snapshot, then ended the batch. On Team, 50 windows (6.15 GiB) are over the limit; their snapshot reads took a median 3.2 s and up to 106 s, and the in-memory cooldown resets on every deploy, so each restart re-read them. Selection now sums the original event bytes through the session index and classifies those windows as oversized before any envelope work; later candidates in the same pass still archive. The warning names the session and the lower-bound bytes.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs changes before merge. What this changesThis PR skips archive-envelope preparation when transcript event bytes already exceed 64 MiB and reports the affected session. Example: An eligible 80 MiB transcript precedes a small eligible transcript.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains This PR addresses measured cold-storage waste, but its new byte-count addition incorrectly rejects archivable PostgreSQL transcripts; the previous UTF-16 finding is fixed. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway maintenance and sessions.storage.run dispatch candidate selection and archive preparation to existing workers, then commit verified archives through the session mutation owner. flowchart TD
A[Gateway maintenance or Run now] --> B[Archive worker selection]
B --> C[Stored event byte totals]
C --> D[Oversized warning and cooldown]
C --> E[Prepare eligible envelopes]
E --> F[Guarded archive mutation]
Technical reviewBest possible solution: Keep the existing worker-owned pre-check, convert aggregate values before arithmetic, and protect PostgreSQL archival with a focused regression. Do we have a high-confidence way to reproduce the issue? Source inspection establishes both the original envelope-limit batch exit and the introduced PostgreSQL string-addition path; no target code was executed during this read-only review. Is this the best way to solve the issue? The pre-check removes unnecessary envelope work at the existing selection owner, and the three added tests cover distinct failures; numeric conversion is needed to preserve PostgreSQL behavior. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2f95e977c77d. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +49, Tests +138, Docs +8. Total +195 across 6 files. Added test files: 1. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 25, 2026, 7:10 AM ET / 11:10 UTC (Revision 2). |
UTF-16 SQLite stores leave event_utf8_bytes null, and octet_length counts stored UTF-16 bytes, so the pre-check could mark an archivable transcript oversized and park it on cooldown. Sum exact UTF-8 bytes where known and halve unknown stored bytes on UTF-16 stores, as sqlite-jsonl-budget does.
|
Fixed the UTF-16 finding in dff3331. The pre-check now sums exact New regression
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dff3331b0c
ℹ️ 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".
| const stored = sizes?.stored ?? 0; | ||
| const lowerBoundBytes = | ||
| (sizes?.known ?? 0) + (utf16Storage ? Math.ceil(stored / 2) : stored); |
There was a problem hiding this comment.
Convert PostgreSQL aggregate results before adding byte counts
For PostgreSQL stores, event_utf8_bytes is a bigint, so SUM(event_utf8_bytes) returns numeric. The PostgreSQL bridge leaves that result as a string (decodePostgresRows only converts OID 20), and Kysely's <number> annotation does not convert it at runtime. Consequently, an ordinary transcript with 8,000,000 known bytes and no legacy rows computes "8000000" + 0 as "80000000", incorrectly exceeds the 64 MiB limit, and is excluded from archival for the 24-hour cooldown. Convert the aggregate results to numbers or cast the SQL aggregate to a bridge-supported integer type before performing this addition.
Useful? React with 👍 / 👎.
|
Merged via squash auto-merge.
|
…limit (openclaw#183378) * perf(sessions): skip cold envelopes for transcripts over the archive limit Cold storage learned that a transcript exceeds the 64 MiB uncompressed archive limit only after building its whole envelope inside a read snapshot, then ended the batch. On Team, 50 windows (6.15 GiB) are over the limit; their snapshot reads took a median 3.2 s and up to 106 s, and the in-memory cooldown resets on every deploy, so each restart re-read them. Selection now sums the original event bytes through the session index and classifies those windows as oversized before any envelope work; later candidates in the same pass still archive. The warning names the session and the lower-bound bytes. * fix(sessions): bound UTF-16 stores by UTF-8 bytes in the cold pre-check UTF-16 SQLite stores leave event_utf8_bytes null, and octet_length counts stored UTF-16 bytes, so the pre-check could mark an archivable transcript oversized and park it on cooldown. Sum exact UTF-8 bytes where known and halve unknown stored bytes on UTF-16 stores, as sqlite-jsonl-budget does.
What Problem This Solves
Cold storage only learned that a transcript is over the 64 MiB uncompressed archive limit after building its whole envelope inside a read snapshot. The rejection then ended the batch, so later eligible windows waited for the next pass. The oversized verdict lives in a process-local 24-hour cooldown that resets on every restart.
Read-only measurements on Team (2026-10-24/25, 45 GB roboclaw agent database):
cold transcript snapshotholds for those reads: median 3.2 s, max 106 s.User Impact
User impact: on large installs, cold-storage maintenance no longer spends seconds to minutes re-reading transcripts it cannot archive, and other eligible sessions keep moving to cold storage in the same pass. Operators can see which session is too large in the warning.
Why This Change Was Made
coalesce(event_utf8_bytes, octet_length(event_json))helper. That is an indexed range onsqlite_autoindex_transcript_events_1, and no index is needed.MAX_COLD_ARCHIVE_BYTESis reported as oversized before any envelope work.session-cold-storage-worker.ts:144-148,:176-188), so the sum is a valid lower bound.sessionIdandlowerBoundBytes.Production diff: 4 files, about +57/−8.
Evidence
pnpm test src/config/sessions/session-cold-storage-worker.test.ts --maxWorkers=1: both cases red on the base, green here.pnpm test src/config/sessions/session-cold-storage*.test.ts --maxWorkers=1: 12 files, 131 tests passed.pnpm tsgo:core, the changed-file test typecheck shard, changed-file oxlint,oxfmt --check, andgit diff --check: all passed.Gap: no full Gateway end-to-end run. The 64 MiB limit is a constant, so reproducing it end to end needs a >64 MiB transcript. The integration tests exercise the real worker selection, preparation and mutation against a real agent database. Expect Team's next deploy to show oversized warnings that carry a
sessionId, and no longcold transcript snapshotholds for those windows.Not changed
Schema, indexes, config, archive format, the 64 MiB limit, eligibility and protection rules, ordering, and retention.
Release note context: cold storage no longer re-reads transcripts that are too large to archive, and keeps archiving other eligible sessions in the same pass.