Skip to content

perf(coding-agent): batch saved session catalog - #990

Open
fettpl wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
fettpl:agent/944-batch-session-catalog
Open

perf(coding-agent): batch saved session catalog#990
fettpl wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
fettpl:agent/944-batch-session-catalog

Conversation

@fettpl

@fettpl fettpl commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • reads saved-session metadata with a bounded 16-worker pool while preserving monotonic progress
  • batches progressive agents-view reconciliation every 32 items or 50 ms and emits one authoritative terminal reconciliation
  • resumes metadata scans from verified append boundaries using cached rolling catalog state

Design

The metadata cache records file identity, size, timestamps, a safe newline offset, rolling session metadata, and bounded opening/old-EOF proofs. A larger file resumes from the cached offset only when identity and both proofs still match. Truncation, same-size rewrites, replacement, proof mismatch, and malformed or unterminated tails use a full scan.

Session files are defined as append-only. The bounded proofs detect header and append-boundary rewrites without rereading the complete prefix; arbitrary same-inode rewrites confined to the middle remain outside that storage contract. Atomic replacements are detected by identity.

If a live file grows during a scan, a verified newline-safe prefix remains visible at its old offset and catches up on the next refresh. Unsafe boundaries retry against the newer file.

The agents view owns a generation-scoped batch scheduler. Superseding refreshes and view shutdown cancel pending timers, while successful and failed terminal responses each publish exactly one final state.

Scaling

For synchronous progressive input, reconciliation counts change from N + 1 to:

  • 10 sessions: 1
  • 100 sessions: 4
  • 1000 sessions: 32

Time-based flushes keep slow scans progressive. Safe appends read only the appended range plus at most 8 KiB of verification windows instead of rescanning the full file.

Verification

  • 10/100/1000-session progress and concurrency bounds
  • count- and time-based batching with one terminal reconciliation
  • superseded-refresh and view-finish cancellation
  • mode-level selection preservation
  • append byte counts and concurrent-growth catch-up
  • deletion, truncation, rewrite, replacement, prefix mismatch, malformed tail, and unterminated-boundary fallback
  • focused affected suites: 89 tests passed
  • npm run check

No daemon command, event, response, schema, or protocol behavior changes.

Integration note

Draft PR #959 changes JSONL tail repair in the same session-manager.ts file and the coding-agent changelog. The features are complementary: this PR only reads/falls back on malformed tails and does not copy or perform #959's repair. The imports/changelog may need conflict resolution when one branch rebases.

Fixes #944

Note

Batch saved-session catalog refreshes with incremental append-only scanning

  • Replaces full-file rescans with verified append-only reads: on cache hit, only new bytes are scanned using prefix/suffix proofs; truncations or rewrites trigger a full fallback scan.
  • Adds ProgressiveCatalogBatcher in progressive-catalog-batcher.ts to coalesce per-session updates into bounded flushes (by count and time), reducing redundant agents-view rebuilds.
  • Parallelizes session metadata reads up to SESSION_LIST_METADATA_CONCURRENCY=16 with deterministic output ordering and diagnostics callbacks for bytes read and read mode.
  • Cancels any in-flight batcher on supersession or mode shutdown to prevent stale late flushes.
  • Behavioral Change: cache invalidation now checks file identity (dev, ino, birthtimeMs) and ctimeMs in addition to size and mtime.

Macroscope summarized 4d3a670.

@fettpl
fettpl marked this pull request as ready for review August 8, 2026 15:32
@fettpl

fettpl commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@snimu This is ready for review. The exact head passed all CI jobs and two independent code-review passes. The PR documents the append-only cache contract and the mechanical overlap with #959; no daemon protocol behavior changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch saved-session catalog reconciliation

1 participant