Skip to content

fix(diagnostics): record the previous run's main-thread hang after the trace sink exists - #26468

Closed
Fanzzzd wants to merge 2 commits into
stablyai:mainfrom
Fanzzzd:fix/hang-breadcrumb-after-trace-sink
Closed

Fanzzzd wants to merge 2 commits into
stablyai:mainfrom
Fanzzzd:fix/hang-breadcrumb-after-trace-sink

Conversation

@Fanzzzd

@Fanzzzd Fanzzzd commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

ELI5

When Orca freezes, a watchdog leaves a note on disk. The next launch reads the note and should write it into the log. It wrote it before the log was open, so the note was lost. This writes it after the log is open.

What Changed

main_thread_hang_detected is now emitted from initializeMainProcessObservers, after initObservability() and the main_process_lifecycle_started breadcrumb. Before, initializeReadyFoundation emitted it while the tracer had no sink, so the span was a no-op. The marker is still consumed in the same place, and the telemetry event already in the observers step is unchanged.

Before: after a hang, the next run's main.trace.ndjson has no record of it. After: it has a main_thread_hang_detected span with the previous pid, the stall duration and whether it recovered.

Why

Moving one emit is the smallest change that puts the breadcrumb behind the sink. Calling initObservability() earlier would also fix it, but that changes when every startup span starts recording. That is a larger change than this bug needs.

Linked Issue

Fixes #26466

Visual Proof

N/A. No UI change; this only affects what goes into the local trace file.

Testing

  • main-process-observers-hang-breadcrumb.test.ts checks the order: sink init, then main_process_lifecycle_started, then main_thread_hang_detected. It fails without the change.

  • The existing main-process-ready* tests pass. Typecheck (node), oxlint and the changed-code gate pass.

  • Platforms: macOS. The change is startup ordering only, with no platform-specific code.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Opus 5.5 (Claude Code). I reviewed the change and the test.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

https://claude.ai/code/session_01DvNJ16LEPYmdEkpQWtDL7n

…e trace sink exists

The ready foundation consumed the hang marker and emitted main_thread_hang_detected
before initObservability installed the tracer sink, so the span was a no-op and the
trace never showed the hang. Emit it from the observers step instead, after the sink
and the lifecycle_started breadcrumb.

Claude-Session: https://claude.ai/code/session_01DvNJ16LEPYmdEkpQWtDL7n
Fanzzzd added a commit to Fanzzzd/orca that referenced this pull request Oct 8, 2026
…uring a stall

Emit main_thread_hang_detected after the trace sink exists (upstream stablyai#26468), and
retry the main-thread stack read up to three times while the stall lasts, recording
how many reads were tried so a missing stack can be told apart from no attempt.

Claude-Session: https://claude.ai/code/session_01DvNJ16LEPYmdEkpQWtDL7n
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cb95767e-dfa7-435c-ab87-16b3524dc44e
📥 Commits

Reviewing files that changed from the base of the PR and between 3cee2ea and eb026ba.

📒 Files selected for processing (1)
  • src/main/startup/main-process-observers-hang-breadcrumb.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Startup still consumes the hang-detection marker during ready-foundation initialization. Observer initialization now records the durable main_thread_hang_detected breadcrumb with the unresponsive duration, parent PID, and self-recovery status. A new test checks that observability initialization and the lifecycle-started event occur before the hang breadcrumb.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to eb026

On successful startup with local tracing enabled, the next run records the previous hang details. The implementation order is correct, but the test does not verify the resulting trace record, leaving a bounded regression-detection gap that can be followed up without blocking merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: recording the previous run's main-thread hang after the trace sink is available.
Description check ✅ Passed The description covers the required explanation, change, rationale, linked issue, visual-proof exception, testing, AI disclosure, and checklist. It also states that manual testing was not performed an…
Linked Issues check ✅ Passed Issue #26466 requires the next run to write main_thread_hang_detected to the local trace with the previous PID and stall duration. initializeReadyFoundation still consumes the marker into `state.h…
Out of Scope Changes check ✅ Passed The changes are limited to moving the durable hang breadcrumb emission and adding a focused startup-order test. Marker consumption and the existing telemetry event remain unchanged. These changes dire…
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/main/startup/main-process-observers-hang-breadcrumb.test.ts (1)

65-85: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add assertions for the breadcrumb payload and trace sink

The test mock records only the breadcrumb name. It can pass when previousPid, unresponsiveMs, or selfRecovered is incorrect, and it does not inspect the trace output. Assert the mock call arguments and use a trace-backed fixture to verify that the breadcrumb is persisted.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f06d41b8-1132-44ed-8d15-74d2eb0fc8f3
📥 Commits

Reviewing files that changed from the base of the PR and between 46ef7c4 and 3cee2ea.

📒 Files selected for processing (3)
  • src/main/startup/main-process-observers-hang-breadcrumb.test.ts
  • src/main/startup/main-process-observers.ts
  • src/main/startup/main-process-ready-foundation.ts
💤 Files with no reviewable changes (1)
  • src/main/startup/main-process-ready-foundation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Fanzzzd

Fanzzzd commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai Added the payload assertion in eb026ba: the test now checks previousPid, unresponsiveMs and selfRecovered. I left out a trace-backed fixture. The bug was the call order relative to initObservability, and the test already pins that order. The tracer's no-op-before-sink behavior is covered by the tracer's own tests.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
ast-grep outline src/main/startup/main-process-observers-hang-breadcrumb.test.ts
sed -n '1,160p' src/main/startup/main-process-observers-hang-breadcrumb.test.ts
ast-grep outline src/main/startup/main-process-observers.ts
rg -n -C 8 'initObservability\(|main_process_lifecycle_started|main_thread_hang_detected' src/main/startup/main-process-observers.ts

Length of output: 6486


@Fanzzzd Thanks for the update and explanation. I verified that the test asserts previousPid, unresponsiveMs, and selfRecovered. It also checks that initObservability() and main_process_lifecycle_started precede the hang breadcrumb.

A trace-backed fixture is not needed for this startup-order regression, given the tracer test coverage you described.


✏️ Learnings added
Learnt from: Fanzzzd
URL: https://github.com/stablyai/orca/pull/26468

Timestamp: 2026-10-08T08:59:05.961Z
Learning: In stablyai/orca, src/main/startup/main-process-observers-hang-breadcrumb.test.ts covers the main-thread hang breadcrumb startup order relative to initObservability() and main_process_lifecycle_started, plus the previousPid, unresponsiveMs, and selfRecovered payload fields. The author explains that the tracer's own tests cover its no-op-before-sink behavior; a trace-backed fixture is therefore unnecessary for this startup-order regression.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

nwparker added a commit that referenced this pull request Oct 9, 2026
…ve operations

Enable the existing worker watchdog on Windows and retain a bounded name-only
snapshot from atomic shared slots when the main thread stops responding.
Preserve the previous marker until the startup trace sink exists, so a new
startup hang cannot overwrite the unreported previous run.

Adapt the startup-order regression coverage from community PR #26468.

Co-authored-by: fanzzzd <[email protected]>
nwparker added a commit that referenced this pull request Oct 9, 2026
…vidence (#26763)

Enable the independent hang watchdog on Windows and preserve the previous run's marker until the startup trace sink is ready. Retain local consent, heartbeat timing, worker cleanup and bounded marker validation. Operation tracking is deferred.

Adapt the startup-order regression coverage from community PR #26468.

Co-authored-by: fanzzzd <[email protected]>
@nwparker

nwparker commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @Fanzzzd — your startup-order fix and regression coverage were incorporated into #26763, which is now merged. The squash commit includes your co-author credit. Closing this as superseded.

@nwparker nwparker closed this Oct 9, 2026
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.

Hang watchdog breadcrumb from the previous run never reaches the trace

2 participants