Repository navigation
bt-daemon: expire stalled routes and reclaim session storage space - #287
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31d689a716
ℹ️ 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 (@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 (@codex) address that feedback".
| /// when a destination keeps rejecting spans. | ||
| #[arg( | ||
| long, | ||
| env = "BRAINTRUST_DAEMON_RETENTION_HOURS", |
There was a problem hiding this comment.
Read the retention environment setting through the shared helper
The new BRAINTRUST_DAEMON_RETENTION_HOURS setting is read directly through Clap's env attribute, bypassing bt-daemon/src/env.rs. This violates the explicit requirement in AGENTS.md that user-facing environment variables be read through that module and introduces a separate environment-resolution path. Resolve the environment default through crate::env while preserving explicit command-line precedence and range validation.
AGENTS.md reference: AGENTS.md:L57-L60
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3c2e4a6: --retention-hours is now optional. It falls back to BT_TRACE_RETENTION_HOURS read through crate::env, then to the default, and keeps the flag's precedence and the range check.
bbf1156 to
08a7106
Compare
A route held by a failure its settings never correct, such as a span too large for its destination, kept its SpanOps forever while translation kept adding more, so its session storage grew without bound. Any route that has delivered nothing for the retention period now expires the same way a route that never subscribed did: GC stops its delivery, deletes its head and the output only it was owed. A later event starts it again from current output. A detached head is never behind, so it is never stalled. GC also compacts each session's storage. Files created before incremental auto-vacuum was enabled are rebuilt once to enable it. Incremental vacuum is now stepped to completion; execute_batch stepped it only once, so it released at most one page. Retention is an optional --retention-hours flag that falls back to BT_TRACE_RETENTION_HOURS read through crate::env, then 168 hours. An unusable value is reported and ignored. Daemon tuning variables are declared in env.rs and AGENTS.md describes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
serve --retention and BT_TRACE_RETENTION take a duration such as 7d, 12h or 1h 30m, parsed by humantime, instead of a number of hours. Zero and unitless values are rejected; an unusable environment value is reported and the 7 day default applies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
08a7106 to
c599db7
Compare
Stacked on #276, the fourth in the stack:
main← #289 ← #291 ← #276 ← this PR. Part of the fix for SDK-830:pipeline/SQLite files grew by tens of GB. Most of that space was in sessions whose destination kept rejecting spans with 413 or 400 errors, or whose span plugin failed.Problem
With #276, a route waiting on a failure kept its head forever. A 413 or a missing-access 400 isn't fixed by new credentials, so the head never moved. Translation kept adding SpanOps behind it, and the session file was never removed. Separately, deleted rows never returned space to the file system:
maindon't have auto-vacuum enabled, so freed pages stay inside the file.incremental_vacuum(256)went throughexecute_batch, which steps a statement only once, so it freed about one page.Changes
heads.subscribedcolumn is gone, since nothing needs it now.VACUUMto enable incremental auto-vacuum. The rebuild only copies the live data, so it is fast once expired rows are gone.incremental_vacuumis stepped until it finishes.serve --retention, or setBT_TRACE_RETENTION(read throughsrc/env.rs), to a human-readable duration such as7d,12hor1h 30m, parsed byhumantime; the default is 7 days. The flag wins over the env var. Zero and unitless values are rejected; an unusable env value logs a warning and the default applies. It applies to every retention-based cleanup the daemon does, which runs hourly. Hook-spawned daemons inherit the variable from the agent's environment.Tests
doctor_reports_storage_open_failures_with_storage_retry_conditionsonce hit its 5 s timeout under full-suite load, then passed alone and in two full lib runs.🤖 Generated with Claude Code