Skip to content

fix(probes): rolling-log fmt-layer default — disarm the disk bomb (#211) - #1547

Merged
joelteply merged 1 commit into
canaryfrom
fix/rolling-log-default-no-disk-bomb
Jun 8, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/rolling-log-default-no-disk-bomb

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

The substrate's tracing fmt layer wrote unbounded to stderr, which made npm start > /tmp/server.log 2>&1 (and nohup ... 2>&1) the only operator option for capturing logs. At RUST_LOG=info under multi-persona load that grew gigabytes per hour into one file — twice now it has eaten the host's disk mid-session.

Per [[never-redirect-substrate-stderr]] doctrine: the substrate owns its log persistence. Shell redirects of substrate stderr are now forbidden because the substrate provides its own managed rolling-file sink.

What changed

  • ProbeTracingConfig.log_dir: Option<PathBuf> + CONTINUUM_LOG_DIR env override.
  • from_env defaults to ~/.continuum/logs/ (resolves via dirs::home_dir()).
  • tracing_appender::rolling::Builder — Rotation::DAILY, max_log_files(7), non_blocking background writer.
  • ProbeInstall.fmt_writer_guard: Option<WorkerGuard> returned to main.rs so the writer thread lives the process lifetime.
  • Boot line: [continuum-core-server] logs landing at <dir>/continuum-core-server.YYYY-MM-DD.log (rolling daily, retention 7) — so operators don't reflexively reach for a shell redirect.
  • Refuses to silently fall back if the configured dir can't be created — surfaces ProbeFileSinkError::OpenFailed per [[no-fallbacks-ever]].
  • ProbeInstall loses its Debug derive (WorkerGuard isn't Debug); the one test that {:?}-formatted it now matches the error variant explicitly.

Why

Two host-disk-fill incidents this session were directly caused by operator stderr redirection of an unbounded RUST_LOG=info firehose. The substrate already has the probe macros + per-module logger + JSONL sink that Joel and I built together — the fmt layer was the last unbounded write path. This closes it.

Reference docs:

  • docs/architecture/OBSERVABILITY-AS-SUBSTRATE.md — substrate owns load-bearing decision capture
  • docs/architecture/RTOS-DEBUGGER-PROBES.md — probe macros are the substrate's RTOS-style breakpoints
  • [[never-redirect-substrate-stderr]] — auto-memory doctrine added this session

Test plan

  • cargo test -p continuum-core --lib routing::tracing_init — 3/3 green
    • install_is_idempotent_with_no_disk_capture
    • install_surfaces_open_failed_for_unwritable_path
    • from_env_reads_documented_env_vars (pins the ~/.continuum/logs default)
  • cargo check --features metal,accelerate -p continuum-core — green
  • Manual: npm start → confirm logs landing at ... boot line, confirm file appears under ~/.continuum/logs/, confirm rotation via CONTINUUM_LOG_DIR=/tmp/test-rolling.
  • Confirm tail -f ~/.continuum/logs/continuum-core-server.*.log shows live stream.

Closes #211.

The substrate fmt layer wrote unbounded to stderr, which made
`npm start > /tmp/server.log 2>&1` and `nohup ... 2>&1` the only
options for capturing logs. At RUST_LOG=info under multi-persona
load that grew gigabytes per hour into one file — twice it has
eaten the host disk mid-session.

Per [[never-redirect-substrate-stderr]]: the substrate owns its
log persistence. Adds:

* ProbeTracingConfig.log_dir: Option<PathBuf> + CONTINUUM_LOG_DIR
  env override. from_env defaults to ~/.continuum/logs/.
* tracing_appender::rolling::Builder daily rotation, max_log_files(7)
  retention, non_blocking background writer.
* ProbeInstall.fmt_writer_guard: Option<WorkerGuard> returned to
  main.rs so the writer thread lives the process lifetime.
* Boot line confirming the rolling-log path so operators do not
  reach for shell redirection by reflex.

Fallback to stderr only when log_dir = None (test path). Refuses
to silently fall back if the configured dir cannot be created —
surfaces ProbeFileSinkError::OpenFailed per [[no-fallbacks-ever]].

ProbeInstall loses its Debug derive because WorkerGuard is not
Debug; the one test that {:?}-formatted it now matches the error
variant explicitly.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (BLOCK-by-default) — APPROVE (self-approval blocked by gh; posting as comment per [[agent-review-as-acceptable-approval]])

Walked the 7 dimensions per [[reviewer-mandate-elegance-and-substrate-viability]].

1. Correctness: Rolling daily rotation via tracing_appender::rolling::Builder with max_log_files(7) wired correctly. WorkerGuard bound at main() scope (let _log_writer_guard) — held for process lifetime, flushes on shutdown. fs::create_dir_all surfaces typed OpenFailed before non_blocking writer construction. Error path sound.

2. Architecture: log_dir: Option sits on ProbeTracingConfig symmetric with probe_file. ENV_LOG_DIR const placed with peer env constants. Fits the 'env-coupling at one seam (from_env)' doctrine. routing/ is the right module.

3. Traits: ProbeInstall lost Debug because WorkerGuard isn't Debug. Only re-export site is routing/mod.rs; no external Debug consumers. Test installer_returns_typed_error_for_unwritable_path correctly pattern-matches instead of {:?}-printing. Clean.

4. Modularity: build_probe_file_sink helper extracted, used identically in both branches. Layer ordering verified identical: UriCapture → ProbeRouter → probe_file_sink → fmt.with_filter(env_filter). No drift. The ~6 lines of duplication is justified — writers are differently-typed (NonBlocking vs Stderr), abstracting requires trait objects.

5. Speed: tracing_appender::non_blocking is the canonical bounded-channel + background-drain pattern. No new allocations on tracing event hot path. Rotation happens on writer thread.

6. Intel-Mac viability: dirs::home_dir() is cross-platform. tracing-appender 0.2 has no platform-specific features.

7. Elegance/KLOC: ~165 net lines for daily rotation + 7-day retention + boot confirmation + WorkerGuard plumbing. The log_dir=None branch is explicitly the TEST path (documented); production from_env always sets it. Not a silent prod fallback per [[no-fallbacks-ever]] — it's the documented containerized-env-without-HOME branch.

Verified specific concerns:

  • tracing-appender 0.2.5 in Cargo.lock satisfies max_log_files ≥0.2.4 requirement ✓
  • WorkerGuard held in main.rs at process scope ✓
  • Layer ordering identical between branches ✓
  • dirs::home_dir() None case documented and returns None cleanly ✓

Minor non-blocking nit: from_env_reads_documented_env_vars test doesn't save/restore CONTINUUM_LOG_DIR; if a future contributor sets it in their shell, the assertion would fail on the override path. CI runners don't set it so this isn't blocking, but worth a follow-up.

Verdict: APPROVE — directly addresses the disk-bomb doctrine [[never-redirect-substrate-stderr]].

@joelteply
joelteply merged commit bfe7914 into canary Jun 8, 2026
3 of 4 checks passed
@joelteply
joelteply deleted the fix/rolling-log-default-no-disk-bomb branch June 8, 2026 02:50
joelteply added a commit that referenced this pull request Jun 8, 2026
…ipt (#1548)

The codelytv/pr-size-labeler@v1 action is Docker-based — it builds an
alpine:3.15 image from Docker Hub at every workflow run. When Docker
Hub rate-limits or times out (regular occurrence on busy mornings),
the action fails during image build BEFORE the `with:` inputs are
processed, so `continue-on-error: true` on the step does NOT contain
the failure. The whole label-pr job goes red, which leaves a false
"PR is broken" signal across the entire PR list.

PR #1547 (rolling-log fmt-layer fix) hit this today:
  failed to resolve source metadata for docker.io/library/alpine:3.15:
  failed to do request: ... dial tcp 54.158.241.65:443: i/o timeout

Replaces the action with an inline `actions/github-script@v7` step
that computes additions+deletions from the PR payload, picks the
appropriate `size: XS/S/M/L/XL` label using the same thresholds the
codelytv config used (so historical label meanings stay consistent),
removes any stale size labels, and applies the chosen one via the
GitHub API. Pure JS on the node20 runner — no Docker, no registry
pulls, no rate limits.

`continue-on-error: true` retained on both steps as defense in
depth: if the GH API request itself fails for some other reason
(GitHub outage, secrets misconfig), the label-pr job still doesn't
poison the PR view.

Co-authored-by: Claude Opus 4.7 <[email protected]>
joelteply added a commit that referenced this pull request Jun 8, 2026
…lake

`install_probe_tracing` calls `tracing_subscriber::registry().try_init()`,
which permanently attaches the substrate's UriCaptureLayer +
ProbeRouterLayer + fmt layer to the GLOBAL tracing default for the
rest of the process. That's correct for production (one process, one
boot, one install) but in cargo's lib-test binary it leaked across
tests:

  routing::tracing_init::tests::install_is_idempotent_with_no_disk_capture
    → installs the global subscriber

  routing::uri_layer::tests::no_subscriber_returns_empty_chain
    → asserts an empty chain "no installed Layer means no captured frames"
    → PANICS when the install ran first in the same binary

Task #203 captured the symptom. Today's PR #1547 hit it deterministically
when running `cargo test -p continuum-core --lib routing::`.

Fix: move both `install_*` tests out of the lib-test binary and into
their own integration-test file (`tests/tracing_install_global.rs`).
Each `tests/*.rs` file becomes a separate binary in cargo's runner —
process isolation contains the global install per binary.

`from_env_reads_documented_env_vars` stays in the lib-test module
because it only touches env vars (already serial within itself) and
never calls `install_probe_tracing`.

Verification: `cargo test -p continuum-core --lib routing::` now
passes 252/252 (was 252/253 with the flake), and the new integration
binary passes 2/2.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
joelteply added a commit that referenced this pull request Jun 8, 2026
…bomb

Per Joel 2026-06-08: "When we have repeated things, like incrementally
improving it, we need to make sure we auto clean like this thing does
now and we reduced the extra gb. It was nearly full."

JsonlProbeFileSink was the next disk bomb waiting. `OpenOptions::append`
on a single file, no rotation, no cap — turn it on for a measurement
session, forget to turn it off, recreate the 3 GB blob problem that
PR #1547 fixed for the fmt-layer.

This applies the same doctrine to the probe sink:

- New constructor `JsonlProbeFileSink::new_rolling(dir, classes, max_log_files)`
  builds a `tracing_appender::rolling::Builder` with daily rotation +
  `max_log_files(N)`. Files land at `<dir>/continuum-probes.YYYY-MM-DD`.
  Disk usage bounded by design, not by operator discipline.
- New env var `CONTINUUM_PROBE_DIR` → rolling mode. Production default.
- Legacy `CONTINUUM_PROBE_FILE` still works but logs a one-line
  `tracing::warn!` pointing operators at the new var. Kept because
  some forensic captures genuinely want one continuous file across days.
- `from_env()` prefers `CONTINUUM_PROBE_DIR` (rolling) and falls back to
  `CONTINUUM_PROBE_FILE` (single-file + deprecation warn).
- `DEFAULT_MAX_LOG_FILES = 7` — same retention as the fmt-layer rolling
  so operators learn one number.
- `path()` deprecated in favor of `target()` — same field, clearer name
  since "target" can be a file or directory depending on mode.
- Storage swapped to `Mutex<Box<dyn Write + Send>>` so the hot-path
  write code is identical regardless of mode.

One focused integration test (`new_rolling_writes_to_dated_file_in_target_dir`)
walks the full lifecycle in a single test per Joel's "less tests with
more coverage" principle — construct, install as tracing layer, fire
probe, observe `continuum-probes.*` file on disk with the right
content. Regression here = the auto-clean doctrine silently falls back
to unbounded growth.

Doctrine memory: [[auto-clean-is-structural-not-operational]].
Structural fix pattern, not opt-in operational discipline. Same shape
the fmt-layer rolling and cargo target shrink (PR #1556) follow.

Same pattern next applies to: ~/.continuum/genome/ (4.2 GB unbounded),
persona recorder fixture output, sentinel checkpoint dirs. Each one is
a follow-up slice.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant