Repository navigation
Record the running CLI command in crash report trace strings - #31688
Conversation
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Comment |
There was a problem hiding this comment.
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: addscli_state::set_cmd_char(u8), a one-lineAtomicU8::storethat exactly mirrors the adjacentset_main_thread_idsetter. The backingCMD_CHARstatic and itscmd_char()reader already existed; only the writer was missing.src/runtime/cli/mod.rs: one new callbun_crash_handler::cli_state::set_cmd_char(cmd.char())increate_context_data, right after the existingCMD.write(Some(cmd)), plus a comment tweak.Tag::char()already exists insrc/options_types/command_tag.rsand returns the bun.report-compatible byte (verifieda/r/tfor the tested commands; all variants are non-zero so the0 → '_'sentinel is preserved).Cargo.lock: one-line addition ofbstrunderbun_bin, matchingsrc/bun_bin/Cargo.toml:20which already declares it — pure lockfile catch-up.test/cli/run/run-crash-handler.test.ts: three new tests that crash underbun <file>/bun run/bun testand 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).
|
CI note: build 59762 went red only on |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
CMDwrite) was addressed in bf704c4 and is resolved. - The
Cargo.lockhunk just records an already-declaredbstrdep onbun_bin;bstris used workspace-wide.
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.
bf704c4 to
d5a4f8f
Compare
There was a problem hiding this comment.
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.
|
Status: done — new tests verified passing on every platform; remaining CI red is known-flaky/infra files only. Where Every remaining mac-lane failure across builds 59846/59904/59908 is the same set of unrelated files: The fix: adds the never-ported 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.
There was a problem hiding this comment.
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
CMDreaders) was addressed in bf704c4 and the diff reflects it; that thread is resolved. - The one remaining inline nit (no-op
GITHUB_ACTIONS: undefined/CI: undefinedin the test env) is explicitly pre-existing — copied verbatim fromrun-crash-handler.test.ts— and has zero functional effect sinceBUN_ENABLE_CRASH_REPORTING=1forces 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.
There was a problem hiding this comment.
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
CMDcomment wording and the no-opGITHUB_ACTIONS: undefined/CI: undefinedenv 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.
There was a problem hiding this comment.
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.
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
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 acmd_char()getter consumed by the trace-string encoder, but noset_cmd_charexists and nothing in the tree stores to it.bun_runtime::cli::CMDis written at dispatch (create_context_data, the port of Zig'sCli.cmd = command), but the crash handler is a lower-tier crate and can't read it —cli_stateexists precisely sobun_runtimecan mirror the value down, like the adjacentset_main_thread_idalready does.Fix
cli_state::set_cmd_char(u8).create_context_datawithcmd.char()— the single dispatch point every subcommand funnels through, matching Zig's write site.Tag::char()was already ported byte-for-byte fromCommand.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.lockwith thebstrdependency added tobun_binin 90f334a (lockfile wasn't regenerated in that commit).Verification
New tests in
test/cli/run/crash-report-command-char.test.tsself-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 intest/expectations.txt— its pre-existing segfault-reporter test is broken — so anything added there is silently skipped on every CI lane.