Skip to content

fix: bound daemon translator and sink memory - #24

Merged
Stephen Belanger (Qard) merged 2 commits into
mainfrom
t3code/review-issue-plan
Aug 18, 2026
Merged

fix: bound daemon translator and sink memory#24
Stephen Belanger (Qard) merged 2 commits into
mainfrom
t3code/review-issue-plan

Conversation

@Qard

@Qard Stephen Belanger (Qard) commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Bounds retained memory across the daemon pipeline while preserving trace content and journal replay semantics.

  • Keeps only active session state in memory and changes the default journal-backed retirement window from 5 minutes to 30 seconds. A later event rebuilds the delivery pipeline from disk.
  • Adds shared bounded recent-ID/map helpers for replay deduplication and correlation instead of lifetime-growing completed-ID sets.
  • Bounds both Codex and Claude transcript catch-up through translator continuations. Claude now materializes one historical LLM input per batch instead of every growing history snapshot at once.
  • Treats native Codex compaction as the history memory barrier, drops terminal Codex/Claude subagent state, releases completed OpenCode fragments, and clears Pi turn-local correlation state.
  • Removes completed SpanHandles from the Braintrust sink, preserving late updates through stateless merges.
  • Bounds the shared SDK queue at approximately 8 MiB per backend client and caps inactive backend clients at 16. The queue budget is shared across sessions using the same client.
  • Streams transcript parsing instead of retaining a second full-file string, skips unchanged attach polls, and destroys each completed bulk-import session before starting the next file.

Memory model

The journal and native transcripts are the durable source of truth. In-memory state is limited to:

  • currently open spans and correlation data;
  • the active conversation context required to construct the next LLM span;
  • a bounded recent deduplication window;
  • one bounded translator output batch;
  • one shared, byte-budgeted SDK submission queue.

Codex replacement history is applied immediately at compaction, so pre-compaction context is retained only long enough to emit the compaction span. Idle delivery pipelines, credentials, journal handles, and translator/sink state are retired after 30 seconds and reconstructed from the journal if traffic resumes.

RSS evidence

Measurements are process RSS in KiB using the same synthetic payload shapes before and after the changes. Temporary probes were removed after collection.

Scenario Before After Evidence of bounded growth
Claude: one 96 MiB transcript catch-up 10,928 -> 2,965,328 6,800 -> 414,400 peak 96 one-request batches; 86% lower peak
Codex: 96 closed 1 MiB subagents 8,544 -> 122,832 7,392 -> 26,816 24,720 at 48; only +2,096 over the next 48
OpenCode: 96 completed 1 MiB messages 7,680 -> 110,928 7,376 -> 13,248 13,232 at 48 and 13,248 at 96
Pi: 96 completed 1 MiB turns 8,400 -> 11,024 7,392 -> 13,952 12,912 at 48 and 13,952 at 96; remained bounded in both versions
Sink: completed 1 MiB spans 7,712 -> 94,352 after 64 9,328 -> 47,008 after 64 still 47,008 after 128; exact second-wave plateau

The Claude trace still contains the same cumulative historical inputs by contract, but they are emitted sequentially rather than held simultaneously. High-water RSS can remain mapped by the process allocator after values are freed; the second-wave plateaus distinguish that from continued live retention.

Validation

  • cargo fmt --manifest-path bt-daemon/Cargo.toml --all -- --check
  • cargo clippy --manifest-path bt-daemon/Cargo.toml --all-features --all-targets --locked -- -D warnings
  • cargo test --manifest-path bt-daemon/Cargo.toml --all-features --locked (128 passed; 4 real-agent tests intentionally ignored)
  • git diff --check

Regression coverage includes bounded Codex and Claude catch-up, late stateless merges after completed handles are released, bounded recent caches, the 30-second retirement default, journal-backed retirement/resume, import continuations, and existing translator trace contracts.

@Qard Stephen Belanger (Qard) changed the title fix: bound Codex catch-up memory fix: bound daemon translator and sink memory Aug 18, 2026
@Qard
Stephen Belanger (Qard) marked this pull request as ready for review August 18, 2026 13:05
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Qard
Stephen Belanger (Qard) merged commit 0acc190 into main Aug 18, 2026
20 checks passed
@Qard
Stephen Belanger (Qard) deleted the t3code/review-issue-plan branch August 18, 2026 15:41
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.

2 participants