Skip to content

Fix chroot helper with Sentry#433

Merged
edolstra merged 1 commit into
mainfrom
eelcodolstra/nix-382
Apr 23, 2026
Merged

Fix chroot helper with Sentry#433
edolstra merged 1 commit into
mainfrom
eelcodolstra/nix-382

Conversation

@edolstra

@edolstra edolstra commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Motivation

The chroot helper only works if there are no other threads, but Sentry creates a worker thread. So don't start Sentry in the chroot helper.

Context

Summary by CodeRabbit

  • Refactor

    • Startup sequence adjusted so the environment helper runs earlier during launch, affecting early initialization and startup behavior.
  • Tests

    • Added a functional test that sets a Sentry endpoint for sandboxed shell runs to validate error-reporting behavior in that environment.

@edolstra edolstra requested a review from cole-h April 23, 2026 09:37
@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The non-Windows chroot helper early-return in mainWrapped was moved to run immediately after saving argv, before Sentry initialization and crash handler registration. A test was added to set a Sentry endpoint environment variable when invoking the sandboxed nix shell.

Changes

Cohort / File(s) Summary
Chroot Helper Initialization
src/nix/main.cc
Relocated the non-Windows chroot helper invocation to immediately after savedArgv = argv in mainWrapped, removing the later conditional that ran after Sentry/crash-handler setup.
Functional Test
tests/functional/shell.sh
Added NIX_SENTRY_ENDPOINT=file://$TEST_ROOT/sentry-endpoint environment override immediately before the sandboxed nix shell invocation to exercise Sentry endpoint handling in the chroot helper.

Sequence Diagram(s)

sequenceDiagram
    participant Init as Init (mainWrapped)
    participant Chroot as ChrootHelper
    participant Sentry as Sentry Init
    participant Crash as Crash Handler

    rect rgba(200,200,255,0.5)
    Init->>Chroot: (new) check argv[0] == chrootHelperName -> early-return
    end

    rect rgba(200,255,200,0.5)
    Init->>Sentry: Initialize
    Init->>Crash: Register handlers
    end

    note over Init,Chroot: Old flow: Init -> Sentry -> Crash -> Chroot (early-return)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I’m a rabbit in the startup race,
I nudged the chroot to the very first place.
No waiting, no tumble, just hop and cheer—
Sentry and handlers can start up clear. 🐇✨

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix chroot helper with Sentry' is directly related to the main change: moving chroot helper invocation before Sentry initialization to prevent worker thread creation that breaks the helper.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch eelcodolstra/nix-382

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

@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request April 23, 2026 09:40 Inactive
The chroot helper only works if there are no other threads, but Sentry
creates a worker thread. So don't start Sentry in the chroot helper.
@edolstra edolstra force-pushed the eelcodolstra/nix-382 branch from f1935bc to 8008e4d Compare April 23, 2026 09:54

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

🧹 Nitpick comments (1)
tests/functional/shell.sh (1)

68-71: Line 68: Prefer one-shot env assignment instead of export.

This keeps the regression trigger scoped to the intended nix shell call and avoids future cross-test side effects from a persistent exported variable.

Suggested diff
-export NIX_SENTRY_ENDPOINT=file://$TEST_ROOT/sentry-endpoint # test whether Sentry is disabled in the chroot helper
-nix shell --sandbox-build-dir /build-tmp \
+NIX_SENTRY_ENDPOINT="file://$TEST_ROOT/sentry-endpoint" \ # test whether Sentry is disabled in the chroot helper
+nix shell --sandbox-build-dir /build-tmp \
     --sandbox-paths '/nix? /bin? /lib? /lib64? /usr?' \
     --store "$TEST_ROOT/store0" -f shell-hello.nix hello -c hello | grep 'Hello World'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/functional/shell.sh` around lines 68 - 71, Replace the persistent
export of NIX_SENTRY_ENDPOINT with a one-shot environment assignment scoped to
the nix shell invocation so the variable only affects that single command;
locate the export line that sets
NIX_SENTRY_ENDPOINT=file://$TEST_ROOT/sentry-endpoint and move it inline
immediately before the `nix shell --sandbox-build-dir ... -f shell-hello.nix
hello -c hello | grep 'Hello World'` invocation so the environment is applied
only to that process.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/functional/shell.sh`:
- Around line 68-71: Replace the persistent export of NIX_SENTRY_ENDPOINT with a
one-shot environment assignment scoped to the nix shell invocation so the
variable only affects that single command; locate the export line that sets
NIX_SENTRY_ENDPOINT=file://$TEST_ROOT/sentry-endpoint and move it inline
immediately before the `nix shell --sandbox-build-dir ... -f shell-hello.nix
hello -c hello | grep 'Hello World'` invocation so the environment is applied
only to that process.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 591e87d6-94bd-49bd-8c04-698c454b7bf6

📥 Commits

Reviewing files that changed from the base of the PR and between f1935bc and 8008e4d.

📒 Files selected for processing (2)
  • src/nix/main.cc
  • tests/functional/shell.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/nix/main.cc

@github-actions github-actions Bot temporarily deployed to pull request April 23, 2026 09:58 Inactive
@edolstra edolstra added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit 49bd851 Apr 23, 2026
31 checks passed
@edolstra edolstra deleted the eelcodolstra/nix-382 branch April 23, 2026 15:46
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