Skip to content

perf(sessions): skip protection scans for full cold batches - #192033

Closed
vincentkoc wants to merge 1 commit into
mainfrom
fix/cold-storage-full-batch-scan-20261103
Closed

vincentkoc wants to merge 1 commit into
mainfrom
fix/cold-storage-full-batch-scan-20261103

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Cold-storage selection scans every session for hot-transcript protection even when embedded archives already fill the batch and no hot transcript can be selected.

User Impact

Full externalization batches skip unused preparation work. Selected records, ordering, incoming-reference protection, commit validation, schemas, stored formats, retention, and recovery authority remain unchanged. No configuration or migration is required.

Why This Change Was Made

Move the protection scan into the existing hot-window selection condition. PostgreSQL buffers the query result, so avoiding the query also avoids transferring unused metadata through the bridge. This is an avoided-work claim, not a measured latency result.

Evidence

  • Exact head: de8e95eccd408feb4661a7f030a1afeb9df8ca89; base: 6f8c9bad8bd1a8c339f2d61985e637f9e557550d.
  • SQLite selection, eligibility, and worker suites: 3 files, 30 tests passed.
  • New real PostgreSQL regression: 1 test passed, none skipped. A full embedded-archive batch issues no protection scan; a free slot retains the scan and incoming-reference protection; removing the reference admits the hot transcript with its authoritative generation/sequence snapshot.
  • PostgreSQL conformance selection includes the new test. Its registration also merges cleanly with the session-age PR.
  • Core and session-test typechecks, targeted lint, and formatting passed.
  • Fresh independent P2 review plus final registration-only delta review: no findings.
  • Proof: Blacksmith Testbox run 41676457364. Completed Testbox commands exited 0 before the lease reached its one-hour workflow limit. The later cancelled workflow status does not represent an interrupted test command.
  • Production: +41/-38 lines, including conformance registration. Tests: +221/-0 lines.

Review hold: #184507 already contains the same selection optimization and additionally avoids the mutation-side scan. Keep that existing PR as the canonical runtime repair; do not land both production patches. This draft adds distinct SQLite and PostgreSQL protection/reference regression coverage that should be preserved during consolidation. The other PR's checkout, source branch, and validation remain untouched.

Outstanding: consolidate this coverage with the canonical repair, then validate the combined candidate.

Track A only. Draft for Vincent's review; do not merge or enable auto-merge.

Regression replay

The unchanged PostgreSQL regression failed on the unpatched frozen base because a full externalization batch still executed the protection SELECT. It passes at this PR head. The separate overlap/consolidation hold remains. Replayed with test-only overlays and unchanged production on the recorded base through Blacksmith Testbox.

@vincentkoc vincentkoc self-assigned this Nov 3, 2026
@clawsweeper

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

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR skips hot-transcript protection scans when embedded archives already fill a cold-storage batch.

Example: One embedded archive fills a batch whose maxTranscripts is 1.

  • Before: Selection scans session metadata for hot-transcript protection even though it cannot select a hot transcript.
  • After: Selection returns the embedded archive without that unused protection scan.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source-consistent, but executed behavioral validation is absent; the draft state itself does not lower the rating.
Proof confidence 🦪 silver shellfish (2/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body explicitly disclaims executed regression and runtime proof, and no supplied artifact exercises this head's changed selection behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Archive-only maintenance reads and parses session metadata that cannot affect its selected batch.
Reason: The maintainer-authored direction removes demonstrably unused work through the existing owner without adding configuration, state, or a parallel policy.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored draft makes a focused, source-consistent optimization with no actionable introduced defect found, but substantially overlaps an existing open PR.

Priority: P2
Reviewed head: aa8ac6cc0fc1f54a150536f02c69ca7a2d1ac71c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The added real-SQLite regression has not run, its base-fail/head-pass result is unshown, and no maintenance-entry-point trace demonstrates avoided selection work with full and mixed batches.
Agent review details

How this fits together

The cold-storage worker receives batch limits and admission identities, selects embedded archives and eligible hot transcripts, and passes preparation results to the existing guarded mutation worker.

flowchart TD
A[Maintenance request] --> B[Cold selection worker]
B --> C[Embedded archive selection]
C --> D[Protection scan when slots remain]
C --> E[Archive preparation]
D --> E
E --> F[Guarded mutation worker]
F --> G[Database and archive files]
Loading

Technical review

Best possible solution:

Carry one conditional selection implementation forward, coordinating its landing with #184507.

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

Current-main source deterministically performs the protection scan before discovering that embedded archives fill the batch; no runtime reproduction was executed in this review.

Is this the best way to solve the issue?

Moving the read into its sole consumer's existing condition is the smallest complete selection-side fix and preserves the original snapshot and protection owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Worker-owned selection and exclusion policy keeps the original intent (418ec9b: Move cold-maintenance selection into workers while retaining archive ordering, budgets, stored ownership, and live admission checks.)
  • Live-session protection inputs keeps the original intent (10334ec: Derive liveness from the run registry rather than persisted running status and supply live identities to selection.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 418ec9b adds src/config/sessions/session-cold-storage-selection.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 418ec9b6bec7; files: src/config/sessions/session-cold-storage-selection.ts)

PR surface

Source +2, Tests +76. Total +78 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 40 38 +2
Tests 1 76 0 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 116 38 +78

Root-cause cluster

Relationship: duplicate
Canonical: #184507
Summary: The earlier open PR contains the same selection optimization and additionally addresses the analogous unused mutation scan.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: Avoids unnecessary whole-store metadata work in enabled cold-storage maintenance without evidence of an urgent user-facing outage.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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: Avoids unnecessary whole-store metadata work in enabled cold-storage maintenance without evidence of an urgent user-facing outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Execute the focused regression on base and head, then record full/mixed maintenance counts and history preservation through the existing worker path.

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 November 3, 2026, 11:00 AM ET / 16:00 UTC.

@vincentkoc

Copy link
Copy Markdown
Member Author

Consolidated into #184507, now merged with this PR’s unique SQLite and PostgreSQL regression coverage. Closing the duplicate; the original source branch is preserved.

@vincentkoc vincentkoc closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts 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