Skip to content

Send a fatal panic as the panic, not as the frameless abort it caused - #155

Merged
GLinnik21 merged 2 commits into
mainfrom
fix/panic-loses-to-native-abort
Sep 19, 2026
Merged

GLinnik21 merged 2 commits into
mainfrom
fix/panic-loses-to-native-abort

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A Rust panic that unwinds out of an extern "C" frame aborts, so one death writes two records: the panic hook's *** RUST PANIC [..] at file:line line in the crash log, and the Sentry daemon's SIGABRT envelope. The daemon's unwind stops at __libc_do_syscall, so the envelope has no useful frames.

At boot, native::import_pending queued the envelope first. consume_native_match then dropped every crash-log record matching it by (build id, signal), and it counted a panic as SIGABRT. So the one record that names a source line was always the one thrown away. In production: no panic issues in 90 days, and fatal panics show up as SIGABRTs grouped on a libc frame (PLX-NATIVE-W). The existing test one_native_envelope_suppresses_exactly_one_matching_fallback asserted that behavior.

Change

  • native::read_pending parses envelopes without queueing them. PendingNative::{append, delete} commits them.

  • crashreport::reconcile is a pure function that pairs fresh log records with envelopes one-to-one. A panic replaces its SIGABRT envelope. A fault (SIGSEGV, …) is still sent as the daemon's event, which carries frames and registers.

  • crashreport::execute runs the plan through a small Recovery trait, so the order of side effects is tested with a recording fake:

    1. queue the log reports being sent;
    2. append the envelopes that survive;
    3. delete each envelope replaced by a queued panic, before the watermark moves;
    4. advance the watermark;
    5. delete a fault's winning envelope only after the watermark write has persisted.

    A cut between any two steps leaves neither a lost report nor two events for one death. The log side re-reads with deterministic event_id_for ids, and the native side re-imports with the envelope's own id.

  • No fresh log, no log at all, or an empty parse: every envelope is still queued.

  • native::sync_change (mid-session opt-in) still imports envelopes on their own, as before, and does not reconcile against the live log. That log can contain this process's caught panics, which should not be reported as fatal.

Deliberately out of scope

These are unchanged from before this PR:

  • The spool append is still not fsync'd.
  • A transient read failure still deletes a pending envelope.
  • The log path gates on consent but not on DSN.
  • Pairing is still by (build, signal) only; there is no per-process crash id.

Also fixed (found on the device)

  • One fatal panic was two Sentry events. A panic that aborts at an extern "C" frame writes three crash-log records: the panic, then std's panic in a function that cannot unwind from core::panicking, then SIGNAL 6. parse already folded the abort into the panic, but not the middle record, so the follow-up went out as a second event. It now folds that record, and panic in a destructor during cleanup, into the panic immediately before it.
  • crashtest=panic could not reach the pairing. A bare panic! inside plex_run unwinds plex_run's own frame. That drops the telemetry Guard, which stops the native backend and deletes its database before the abort, so no envelope is ever written. The trigger now panics inside an extern "C" callback, which is the shape of ff::read_cb under libav.

Verification

Host

  • Regression tests were observed red before each fix:
    • a_panic_is_not_hidden_by_the_native_abort_it_caused failed with "the native SIGABRT hid the panic that caused it".
    • a_panic_its_cannot_unwind_followup_and_the_abort_are_one_report failed with "one death reported as 2 events", using the exact record the TV wrote.
  • Ordering tests use a recording fake. They cover:
    • replacing an envelope with a panic;
    • a panic that failed to queue;
    • a fault's winning envelope under a failed append;
    • a fault's winning envelope under a watermark that didn't persist;
    • a failed report alongside an unrelated envelope;
    • no fresh log.
  • make check: exit 0 (3738 + 3784 tests).
  • make lint: exit 0.
  • make: exit 0.
  • make RELEASE=1: exit 0.
  • --no-default-features: clean.

Device (dev set, webOS 4.10.2, debug install, dev DSN, crash consent on, TV lock held, 2026-09-19)

boot recovery line / action result in plx-native-dev
A (old binary) crashtest=panic inside plex_run no envelope: the Guard drop deleted the database
B crash log had 2 report(s) … native envelopes 0 dev.rs:377 and panicking.rs:225: two events for one death (this was the bug)
C crashtest=abrt envelope written after about 20 s
D 1 report(s), queued 0, native envelopes 1, native_wins=1 native SIGABRT sent, fallback suppressed ✔
E 1 report(s), queued 1, native envelopes 0 (boot D's panic) one dev.rs:377 event, follow-up folded ✔
F 1 report(s), queued 1, native envelopes 1, native_wins=0, panic_wins=1; pending dir empty dev.rs:380 panic sent; its native SIGABRT was not ✔

One review round with Codex. Its one real finding (a watermark write whose failure was ignored, which could have deleted a fault's winning envelope) is fixed and tested. Copilot couldn't review: quota exhausted.

🤖 Generated with Claude Code

A Rust panic that unwinds out of an `extern "C"` frame aborts, so one
death leaves two records: the panic hook's `*** RUST PANIC ... at
file:line` in the crash log, and the Sentry daemon's SIGABRT envelope,
whose unwind stops at `__libc_do_syscall`. Boot queued the envelope
first and then dropped every log record matching it by (build, signal),
counting a panic as SIGABRT. The one record naming a source line was
always the one discarded: production has not shown a single panic in 90
days, and fatal panics arrive as SIGABRTs grouped on a libc frame
(PLX-NATIVE-W).

The two channels are now recovered together. `native::read_pending`
parses envelopes without queueing them; `crashreport::reconcile` pairs
them with the log's fresh records; a panic replaces its SIGABRT
envelope, while a fault is still sent as the daemon's richer event.
`execute` owns the order of every append, delete and watermark write, so
a cut between any two steps yields neither a lost report nor two events:
a replaced envelope is deleted before the mark moves, a fault's winner
only after the mark is known to have persisted. The mid-session consent
path keeps importing envelopes alone, since the live log can hold this
process's caught panics.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 19, 2026 11:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Measured on the dev set: a panic that aborts at an `extern "C"` frame
writes three crash-log records, not two. Std cannot unwind out of the
frame, so it raises `panic in a function that cannot unwind` from
`core::panicking`, and the hook logs that as a second panic. Both were
sent: one death, two Sentry events. `parse` now folds that follow-up
(and `panic in a destructor during cleanup`) into the panic immediately
before it, by the same positional rule that already folds the abort.

`crashtest=panic` exercises the panic-versus-envelope pairing. A bare
`panic!` in `crash_on_purpose` unwinds `plex_run`'s own frame, which drops
the telemetry Guard and deletes the native database before the abort, so
no envelope is ever written. The panic now happens inside an
`extern "C"` callback, the shape of `ff::read_cb` under libav.

Co-Authored-By: Claude Opus 5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 05c198e into main Sep 19, 2026
5 checks passed
@GLinnik21
GLinnik21 deleted the fix/panic-loses-to-native-abort branch September 19, 2026 12:32
GLinnik21 added a commit that referenced this pull request Sep 19, 2026
… read no crash data without a DSN (#168)

Three follow-ups to the native crash-report import (#155):

- The telemetry Guard no longer stops the native backend or deletes its database while the
  thread is unwinding a panic. A panic that unwinds plex_run's frame aborts at the extern "C"
  boundary a moment later, and that abort is the crash the backend exists to capture. A clean
  exit still shuts it down as before.
- A pending native envelope that fails to READ (metadata, open or read I/O error) is left on
  disk for the next boot and counted as deferred=, instead of being deleted as malformed. Only
  a non-regular file, an oversized file, or bytes the parser refuses are deleted.
- Crash data (the crash log and the native envelopes) is read only when crash consent is given
  AND the build carries a Sentry DSN, through one gate, crashreport::may_read_crash_data. A
  no-DSN build reads nothing, moves no watermark and deletes no envelope.

Co-authored-by: Claude Opus 5 <[email protected]>
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.

2 participants