Skip to content

fix(logs): name Alloy read positions in logs-reset; pin the exit drain bound and Loki hint wiring - #478

Merged
roodboi merged 1 commit into
nextfrom
wf/g90-drain-loki-followups
Oct 24, 2026
Merged

roodboi merged 1 commit into
nextfrom
wf/g90-drain-loki-followups

Conversation

@roodboi

@roodboi roodboi commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Refs HACK-1425. Follow-ups from the verifier reviews of #447 (merged as 686b6b8) and #449 (merged as 4c9eb3e). None of them blocked those PRs.

Root cause

  1. No test pinned the production drain bound. Every drain test read NATIVE_EXIT_DRAIN_BOUND_MS itself, or injected a wide value through the exitDrainBoundMs test seam. The held-descendant cases only checked an upper bound (settled - exited < bound + margin). So setting the constant to 250 (or changing the ?? NATIVE_EXIT_DRAIN_BOUND_MS default to ?? 250) passed the whole suite.
  2. Three bound drains had no late-writer case. The one-off drain and the two recovery drains (selection and cleanup) use the same code path as status, read, logs and exec. Only those four had a "closed code written after the reported exit" case.
  3. Three wiring mutations in src/commands/project.ts survived the tests. tests/logs-loki-empty-fallback-cli.test.ts never passed --pretty, --query or --until through the CLI. Replacing pretty: args.options.pretty === true, or the selectors' query: opts.queryOpt or until: opts.until, with a constant did not fail any test.
  4. The hack global logs-reset text was out of date. The command runs down -v, which (since fix(logs): persist Alloy positions, release SIGINT handlers and carry every selector in Loki hints #449) also deletes the alloy-data volume that holds Alloy's read positions. The confirm prompt and the CLI summary named only Loki and Grafana.

Fix

  • tests/native-runtime-client.test.ts
    • New case the production exit drain bound keeps its documented floor and outlasts a late writer. It checks that NATIVE_EXIT_DRAIN_BOUND_MS >= 5000 (the documented floor, now written in the constant's doc comment) and that the bound is larger than the late-writer delay plus a clock tolerance.
    • The held-descendant exit cases (read, selection, cleanup) do not pass the seam. They now also check settled - exited >= NATIVE_EXIT_DRAIN_BOUND_MS - 50 ms, which proves the production default is the bound in effect.
    • LATE_WRITER_SELECTIONS gains one-off, selection and cleanup.
  • tests/native-project-process.test.ts: the same lower bound on the foreground graph owner's two held-descendant cases. This covers that file's own ?? NATIVE_EXIT_DRAIN_BOUND_MS default.
  • tests/logs-loki-empty-fallback-cli.test.ts gets two CLI cases. Both use the stub docker, the fake Loki, and a private HOME via privateCliEnv:
    • --loki --no-follow --pretty migrate: the hint repeats --pretty.
    • --no-follow --query '<custom LogQL>' --until 1m: Loki receives the custom query exactly as given, and the hint lists --query '…' and --until 1m as selectors that --compose cannot apply.
  • src/commands/global.ts: the summary is now "Wipe Loki, Grafana and Alloy volumes (fresh logs, dashboards and Alloy read positions)". The prompt now says it deletes "ALL Loki logs, Grafana state and Alloy read positions". docs/reference/cli.md was regenerated with bun run docs:cli-reference. docs/architecture.md already described the volume removal, so it is unchanged.

There is no production behavior change apart from the logs-reset text and a doc comment.

Evidence

Mutation runs (each mutation applied on its own and restored from a backup afterward):

Mutation Killed by
NATIVE_EXIT_DRAIN_BOUND_MS = 250 documented-floor case
runtime client selected ?? 250 read, selection and cleanup held-descendant exit cases
graph owner opts.exitDrainBoundMs ?? 250 ready and early failure held-descendant cases
fixed 250 ms window for one-off only authored one-off keeps a closed code written after the reported exit
fixed 250 ms window for recovery-selection only authored selection keeps a closed code …
fixed 250 ms window for recovery-cleanup only authored cleanup keeps a closed code …
pretty: args.options.pretty === true → false explicit --loki snapshot hint repeats --pretty
selectors query: opts.queryOpt → undefined explicit --query snapshot hint names --query and --until
selectors until: opts.until → undefined explicit --query snapshot hint names --query and --until

Local gates at this head (Bun 1.4.2):

  • bun run check passed, including privacy:check.
  • bun run --cwd packages/cli typecheck and root bun run typecheck reported 0 errors.
  • Biome reported no issues on the changed files.
  • gitleaks 8.30.1 on the origin/next..HEAD patch found no leaks.
  • Focused tests: native-runtime-client, native-project-process, logs-loki-empty-fallback-cli, global-command and prerequisites-matrix gave 74 pass, 0 fail.

The full-suite evidence is hosted CI's sharded test job at this PR head.

Gaps

  • The new lower-bound checks rely on the wall clock of two processes and a 50 ms tolerance. The lower direction does not depend on host load, because a timer cannot fire before its delay, so these checks should not add flakiness.
  • The new prompt text has no test. confirmSafe declines in non-interactive runs (initialValue: false), so a CLI test cannot see the prompt without a TTY harness. This matches the coverage before this PR.
  • The pin is a floor (>=), not an exact value. Raising the bound still passes, which is intended.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…n bound and Loki hint wiring

- Pin NATIVE_EXIT_DRAIN_BOUND_MS at its documented 5 s floor and above the
  late-writer delay, and assert the held-descendant cases (runtime client and
  foreground graph owner) keep reading for the whole production bound, so a
  smaller constant or default no longer passes.
- Add late-closed-code cases for the one-off and recovery (selection and
  cleanup) bound drains.
- Add CLI cases that carry --pretty, --query and --until into the empty-Loki
  hint through src/commands/project.ts.
- `hack global logs-reset` now says it also deletes the Alloy read positions
  volume in its prompt and summary; regenerate docs/reference/cli.md.

Refs HACK-1425

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Oct 24, 2026

Copy link
Copy Markdown

HACK-1425

@roodboi
roodboi marked this pull request as ready for review October 24, 2026 18:07
@roodboi
roodboi merged commit 3ccbad6 into next Oct 24, 2026
21 checks passed
@roodboi
roodboi deleted the wf/g90-drain-loki-followups branch October 24, 2026 18:07
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.

1 participant