Skip to content

Record the running CLI command in crash report trace strings - #31688

Merged
dylan-conway merged 6 commits into
mainfrom
farm/b2c83d73/crash-report-cmd-char
Jul 20, 2026
Merged

dylan-conway merged 6 commits into
mainfrom
farm/b2c83d73/crash-report-cmd-char

Conversation

@robobun

@robobun robobun commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

What

Crash reports from Rust-port builds always encode _ ("pre-init") as the command character — 206 of 213 crashes on 1.4.0-canary are tagged (pre-init), including crashes that are demonstrably mid-bun install. On Zig builds this dimension worked (InstallCommand, AutoCommand, …).

Repro

BUN_CRASH_REPORT_URL=http://localhost:<port> BUN_ENABLE_CRASH_REPORTING=1 \
  bun test/cli/run/fixture-crash.js panic

stderr trace string before: http://…/1.4.0/l_2561eb8f… — the byte after the platform char is _ for every subcommand.

Cause

The port has the storage and the reader but the setter was never ported:

  • cli_state::CMD_CHAR (src/crash_handler/lib.rs) is declared with a cmd_char() getter consumed by the trace-string encoder, but no set_cmd_char exists and nothing in the tree stores to it.
  • bun_runtime::cli::CMD is written at dispatch (create_context_data, the port of Zig's Cli.cmd = command), but the crash handler is a lower-tier crate and can't read it — cli_state exists precisely so bun_runtime can mirror the value down, like the adjacent set_main_thread_id already does.

Fix

  • Add cli_state::set_cmd_char(u8).
  • Call it from create_context_data with cmd.char() — the single dispatch point every subcommand funnels through, matching Zig's write site. Tag::char() was already ported byte-for-byte from Command.Tag.char() (kept in sync with bun.report's decoder).

After: http://…/1.4.0/la2561eb8f… (a = AutoCommand); bun.report can again pick the per-command issue template and Sentry's command facet works for Rust builds.

Also syncs Cargo.lock with the bstr dependency added to bun_bin in 90f334a (lockfile wasn't regenerated in that commit).

Verification

New tests in test/cli/run/crash-report-command-char.test.ts self-host the report URL, crash under three different subcommands via the debug crash hooks, and decode the command byte from the trace string: bun <file> → a, bun run <file> → r, bun test → t. All three fail with _ before the fix and pass after.

The tests live in their own file (rather than run-crash-handler.test.ts) because that file is skip-listed in test/expectations.txt — its pre-existing segfault-reporter test is broken — so anything added there is silently skipped on every CI lane.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 17 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1b961cd-1c68-4b6b-a6c3-e006607536ca

📥 Commits

Reviewing files that changed from the base of the PR and between a0d1472 and faa81b4.

📒 Files selected for processing (3)
  • src/crash_handler/lib.rs
  • src/runtime/cli/mod.rs
  • test/cli/run/crash-report-command-char.test.ts

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the claude label Jun 2, 2026
@robobun

robobun commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — straightforward wiring of the existing CMD_CHAR atomic via a setter that mirrors set_main_thread_id, with tests.

Extended reasoning...

Overview

Two tiny production changes plus tests and a lockfile sync:

  • src/crash_handler/lib.rs: adds cli_state::set_cmd_char(u8), a one-line AtomicU8::store that exactly mirrors the adjacent set_main_thread_id setter. The backing CMD_CHAR static and its cmd_char() reader already existed; only the writer was missing.
  • src/runtime/cli/mod.rs: one new call bun_crash_handler::cli_state::set_cmd_char(cmd.char()) in create_context_data, right after the existing CMD.write(Some(cmd)), plus a comment tweak. Tag::char() already exists in src/options_types/command_tag.rs and returns the bun.report-compatible byte (verified a/r/t for the tested commands; all variants are non-zero so the 0 → '_' sentinel is preserved).
  • Cargo.lock: one-line addition of bstr under bun_bin, matching src/bun_bin/Cargo.toml:20 which already declares it — pure lockfile catch-up.
  • test/cli/run/run-crash-handler.test.ts: three new tests that crash under bun <file> / bun run / bun test and decode the command byte from the trace URL printed to stderr.

Security risks

None. The change writes a single constant ASCII byte derived from the parsed subcommand into a process-local atomic that is only read when formatting crash-report trace strings. No user-controlled data flows into it, and it touches no auth, crypto, filesystem, or network surface.

Level of scrutiny

Low. This is diagnostic metadata only — the worst possible failure mode is that crash reports continue to show _ (the status quo). The implementation follows the established set_main_thread_id pattern in the same module byte-for-byte, the call site is the documented single-threaded startup funnel that every subcommand passes through, and the change is covered by new regression tests that pin the exact encoded characters.

Other factors

No CODEOWNERS rules cover the touched paths. No prior human review comments are outstanding. The bug-hunting system found nothing. The PR description is thorough and the fix matches the Zig original's write site (Cli.cmd = command in createContextData).

@robobun

robobun commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI note: build 59762 went red only on darwin-14-aarch64-test, darwin-14-x64-test, and darwin-26-aarch64-test, all Expired at 0s — the jobs were never picked up by a macOS agent, so no tests executed there. The darwin builds themselves passed, and all 72 other lanes (every Linux/Windows build+test lane, clippy, miri) are green, including the new crash-handler tests. Pushed one retrigger commit for the mac lanes.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — straightforward wiring of the missing set_cmd_char setter following the existing set_main_thread_id pattern, with regression tests; the inline nit is non-blocking.

Extended reasoning...

Overview

This PR fixes crash-report trace strings always encoding _ (pre-init) as the command character on Rust-port builds. The storage (CMD_CHAR: AtomicU8) and reader (cmd_char()) already existed in bun_crash_handler::cli_state; only the setter was never ported. The fix adds set_cmd_char(u8) and calls it from create_context_data (the single dispatch point all subcommands funnel through) with cmd.char(). Also includes a one-line Cargo.lock sync and three new regression tests in run-crash-handler.test.ts covering AutoCommand/RunCommand/TestCommand.

Security risks

None. The change only affects which one-byte tag is encoded into crash-report telemetry URLs. No auth, crypto, parsing, or user-input handling is touched. The atomic store uses Ordering::Relaxed identically to the adjacent set_main_thread_id, and the write happens during single-threaded startup.

Level of scrutiny

Low. This is a ~10-line mechanical fix that exactly mirrors an established adjacent pattern (set_main_thread_id → MAIN_THREAD_ID). Tag::char() was already ported and returns non-zero ASCII (so it can't collide with the 0 = unset sentinel). The blast radius is limited to crash-report diagnostics — a regression here would degrade telemetry quality, not runtime behavior.

Other factors

  • No CODEOWNERS coverage on the touched paths.
  • CI: 72/75 lanes green including the new tests; the 3 red darwin test lanes expired at 0s due to agent unavailability (infra, not code) and a retrigger was pushed.
  • The one finding from the bug-hunting pass is a pre-existing comment-accuracy nit on a line the PR happens to edit — zero runtime impact and not a blocker.
  • No outstanding human reviewer comments.

Comment thread src/runtime/cli/mod.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — comment nit addressed in bf704c4; the setter/call wiring mirrors set_main_thread_id exactly and is covered by the new tests.

Extended reasoning...

Overview

Two-line functional change: add cli_state::set_cmd_char(u8) (a one-line AtomicU8::store) in src/crash_handler/lib.rs, and call it from create_context_data in src/runtime/cli/mod.rs with cmd.char(). This restores the per-subcommand byte in crash-report trace strings, which the Rust port had been emitting as _ (pre-init) because the setter was never ported. The remainder is a comment-wording fix (addressing my earlier nit), three new regression tests in run-crash-handler.test.ts, and a one-line Cargo.lock sync for bstr in bun_bin.

Security risks

None. A single u8 derived from a compile-time enum→byte table is stored into a process-global AtomicU8 during single-threaded startup, and read only by the crash-report trace encoder. No user input, auth, crypto, filesystem, or network surface is touched.

Level of scrutiny

Low. The change is mechanical and follows the identical pattern of the adjacent set_main_thread_id mirror (same cli_state module, same Ordering::Relaxed store, same call-site shape in CLI startup). Tag::char() already existed and is documented as kept in sync with bun.report's decoder. The blast radius is limited to crash-report telemetry metadata; it cannot affect normal execution.

Other factors

  • New tests exercise three subcommands (a/r/t) end-to-end by self-hosting the report URL and decoding the trace string from stderr; per the PR they fail before and pass after.
  • CI: 72 lanes green including clippy/miri and the new tests; the only red lanes were macOS test runners that expired at 0s (agent unavailability, not code), and a retrigger was pushed.
  • My one prior inline nit (comment wording on the CMD write) was addressed in bf704c4 and is resolved.
  • The Cargo.lock hunk just records an already-declared bstr dep on bun_bin; bstr is used workspace-wide.

robobun added 3 commits June 2, 2026 05:36
The crash handler's cli_state module had storage for the one-byte
command tag (CMD_CHAR) and a reader used by the trace-string encoder,
but no setter existed and nothing ever stored to it — every crash
report encoded '_' (pre-init) regardless of which subcommand was
running.

Add cli_state::set_cmd_char and call it from create_context_data, the
single dispatch point every subcommand passes through, mirroring Zig's
'Cli.cmd = command' in createContextData. The Tag::char() mapping
already matches bun.report's decoder byte-for-byte.

Also sync Cargo.lock with the bstr dependency added to bun_bin in
90f334a.
@robobun
robobun force-pushed the farm/b2c83d73/crash-report-cmd-char branch from bf704c4 to d5a4f8f Compare June 2, 2026 05:40

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — the comment nit was addressed, and the fix is a minimal wiring of an existing atomic following the same pattern as set_main_thread_id.

Extended reasoning...

Overview

This PR wires cli_state::CMD_CHAR (an existing AtomicU8 in the crash handler crate that was declared and read but never written) by adding a public set_cmd_char(u8) setter and calling it from create_context_data — the single dispatch funnel every subcommand passes through. The change is ~5 effective lines of production code: one 3-line setter in src/crash_handler/lib.rs, one call site in src/runtime/cli/mod.rs, and a comment correction. The rest is new test coverage in run-crash-handler.test.ts that self-hosts the crash-report URL and asserts the correct command byte (a/r/t) appears in the trace string for three subcommands.

Security risks

None. The change stores a single hardcoded byte (from the Tag::char() lookup table) into a process-local atomic that is only read by the crash-report trace-string encoder. No user input, no I/O, no auth/crypto/permissions surface. The test changes spawn local servers on port 0 and crash child processes via existing debug hooks — same pattern as the adjacent automatic crash reporter describe block.

Level of scrutiny

Low. The setter is a one-line Ordering::Relaxed atomic store that exactly mirrors set_main_thread_id two lines above it in the same module. The call site sits immediately after the existing CMD.write(Some(cmd)) it mirrors, and Tag::char() was already ported and unused-until-now. This is restoring telemetry metadata that worked in Zig builds and was simply never wired in the Rust port — there is no new design here, just a missing plumbing line.

Other factors

  • My earlier nit (the "debug logging only" comment was incomplete) was addressed in bf704c4 / d5a4f8f; the comment now correctly names both readers, and the inline thread is resolved.
  • Three new tests cover the fix end-to-end and would have caught the original regression (_ instead of the per-command byte).
  • CI redness on earlier builds was attributed by the author to macOS agents expiring at 0s (infrastructure), with all 72 Linux/Windows/clippy/miri lanes green; subsequent commits are a CI retrigger and a comment-only clarification.
  • No CODEOWNER-gated paths; no outstanding reviewer comments.

@robobun

robobun commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: done — new tests verified passing on every platform; remaining CI red is known-flaky/infra files only.

Where crash-report-command-char.test.ts has now executed and passed 3/3: all Linux lanes (x64/aarch64/musl/ASAN), Windows x64 + baseline, darwin-14 x64 (build 59908 shard 0), and darwin-26 aarch64 (build 59908). That's the full platform matrix.

Every remaining mac-lane failure across builds 59846/59904/59908 is the same set of unrelated files: js/sql/sql.test.ts wholesale (postgres unreachable on the agent), sql-postgres-datetime-roundtrip, websocket-proxy, autobahn, net/double-connect, snapshot.test.ts, bun-install-proxy — service/network flake on the darwin agents, none touching this PR.

The fix: adds the never-ported cli_state::set_cmd_char and calls it from create_context_data (port of Zig's Cli.cmd = command), so Rust-build crash reports encode the running subcommand instead of _ (pre-init). Fail-before/pass-after verified.

Merge-ready on the evidence above.

run-crash-handler.test.ts is skip-listed in test/expectations.txt (its
segfault-reporter test is broken), so tests added there never run in
CI. Move the crash-report command character tests to their own file.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — minimal setter wire-up mirroring the adjacent set_main_thread_id pattern; prior nit addressed, remaining nit is non-blocking and pre-existing.

Extended reasoning...

Overview

Five-line production change: adds cli_state::set_cmd_char(u8) to src/crash_handler/lib.rs (a one-line AtomicU8::store body, identical in shape to the adjacent set_main_thread_id) and calls it from create_context_data in src/runtime/cli/mod.rs immediately after the existing CMD.write(Some(cmd)). The storage (CMD_CHAR: AtomicU8), the reader (cmd_char()), and the consumer (the trace-string encoder at lib.rs:2632) all already existed — only the setter was missing from the port. A new 61-line test file exercises three subcommands and decodes the command byte from the emitted trace string.

Security risks

None. The change writes a single telemetry-metadata byte (the subcommand tag) into a process-local atomic that is read only when formatting a crash-report URL. No new inputs, no parsing, no auth/crypto/permissions surface, no untrusted data flow. Ordering::Relaxed is appropriate — the write happens in single-threaded startup before any worker thread exists, matching the SAFETY invariant on the adjacent CMD.write.

Level of scrutiny

Low. This is a mechanical port-gap fix following an established pattern in the same module (set_main_thread_id → is_main_thread mirrors a higher-tier crate's state down to the crash handler for exactly the same reason). Tag::char() was already ported and documented as kept in sync with bun.report's decoder. The call site is the single dispatch funnel every subcommand passes through, so coverage is complete by construction.

Other factors

  • My earlier nit (comment wording on the CMD readers) was addressed in bf704c4 and the diff reflects it; that thread is resolved.
  • The one remaining inline nit (no-op GITHUB_ACTIONS: undefined / CI: undefined in the test env) is explicitly pre-existing — copied verbatim from run-crash-handler.test.ts — and has zero functional effect since BUN_ENABLE_CRASH_REPORTING=1 forces the path. Non-blocking.
  • New tests are in a separate file specifically because the obvious home is skip-listed in test/expectations.txt; the author caught and fixed this so the tests actually run in CI.
  • CI: 72 lanes green including clippy/miri and the new tests; darwin reds were agent-starvation expiries and unrelated infra flakes (postgres unreachable, autobahn, etc.), none in this PR's area.

mergeWindowEnvs skips falsy values, so GITHUB_ACTIONS/CI undefined
entries never applied; BUN_ENABLE_CRASH_REPORTING=1 alone forces the
reporting path.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — both nits addressed; the fix is a minimal atomic-store mirroring the adjacent set_main_thread_id pattern, with tests that CI actually runs.

Extended reasoning...

Overview

Five lines of production code: a new cli_state::set_cmd_char(u8) setter in src/crash_handler/lib.rs (a single AtomicU8::store with Ordering::Relaxed), and one call to it from create_context_data in src/runtime/cli/mod.rs. One comment line is reworded. A new 59-line test file exercises three subcommands and asserts the command byte in the crash-report trace string.

The setter is byte-for-byte the same shape as the adjacent set_main_thread_id (same module, same ordering, same atomic type family), and the call site sits immediately after the existing CMD.write(Some(cmd)) it mirrors. Tag::char() was already ported and returns non-zero ASCII for every variant, so the 0 => None sentinel in cmd_char() is preserved.

Security risks

None. This writes a single diagnostic byte into a process-local atomic during single-threaded startup; the only consumer is the crash-report trace-string encoder. No auth, crypto, permissions, or user input is involved. Worst-case failure mode is a wrong character in a crash report URL.

Level of scrutiny

Low. The change is mechanical (wire an existing reader to a new writer following an established adjacent pattern), self-contained, and observability-only — it does not affect runtime behavior outside the crash path. The blast radius is limited to crash-report metadata.

Other factors

  • Both of my prior inline nits (the CMD comment wording and the no-op GITHUB_ACTIONS: undefined / CI: undefined env entries) were addressed in follow-up commits and are resolved.
  • New tests live in their own file specifically so CI executes them (the obvious home, run-crash-handler.test.ts, is skip-listed); the author caught and fixed this mid-PR.
  • The bug hunter found no issues on the current revision.
  • CI was green on Linux/Windows/clippy/miri; mac reds were documented as agent-starvation/infra and unrelated to this change.

On Windows the crash reporter spawns a detached child that inherits the
crashing process's cwd; with cwd inside the tempDir, the directory was
still busy when the test disposed it, failing cleanup with EBUSY. Pass
the temp test file to 'bun test' by absolute path instead.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — both nits addressed; the setter mirrors set_main_thread_id exactly and the call site is the single dispatch funnel.

Extended reasoning...

Overview

Three files: a 3-line set_cmd_char(u8) setter in src/crash_handler/lib.rs (sibling to the existing set_main_thread_id), a single call to it from create_context_data in src/runtime/cli/mod.rs (plus a comment correction), and a new test file that crashes under three subcommands and decodes the command byte from the trace URL. CMD_CHAR (AtomicU8), its cmd_char() getter, and Tag::char() all already existed — the only thing missing was the store, which this PR adds.

Security risks

None. The change writes one byte (derived from the parsed subcommand enum, not user input) into a process-local atomic that is only read when formatting a crash-report trace string. No auth, crypto, permissions, or external I/O is touched.

Level of scrutiny

Low. The production diff is ~6 lines, purely additive, and shaped identically to the adjacent set_main_thread_id mirror that already exists for the same reason (crash handler is a lower-tier crate and can't read bun_runtime state). Failure mode is bounded to crash-report metadata staying _ — i.e., today's broken behavior — with no effect on normal execution.

Other factors

Both of my earlier nits (the CMD reader-list comment and the dead GITHUB_ACTIONS/CI env entries) were addressed and the threads are resolved. The new tests are in their own file specifically because run-crash-handler.test.ts is skip-listed in test/expectations.txt, so they actually run in CI; the timeline shows them green on all Linux/Windows lanes plus clippy/miri, with the one Windows EBUSY flake fixed by dropping the tempDir cwd. No outstanding reviewer comments.

@dylan-conway
dylan-conway merged commit 1f71ec3 into main Jul 20, 2026
75 of 78 checks passed
@dylan-conway
dylan-conway deleted the farm/b2c83d73/crash-report-cmd-char branch July 20, 2026 12:45
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.

2 participants