You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(claude): fail a start whose provider refusal landed before onRefusal was installed - #48448
When Orca starts a Claude chat, it checks that the Claude process answering is the one it started. If not, Orca refuses it. During startup there is a short window where that refusal could be recorded before anything was listening for it. The "no" was written down but nobody acted on it, so the chat opened anyway and only failed one turn later. Now the start checks for a refusal that was already recorded and fails right away.
What Changed
Before:readClaudeStartupFacts can resolve on the initialize answer while a foreign system/init is still queued. If that frame arrived before openClaudeSession installed initProof.onRefusal, refuse() recorded the error with no callback to run. Nothing checked the proof again, so the open succeeded and the session was ended later by the next foreign init.
After:ClaudeInitProof has a new refusal() that returns the first refusal recorded by refuse(). Child faults and journal rejections are not counted, so this returns only what onRefusal would have received. openClaudeSession checks refusal() after its existing isCurrent() guard and before it installs onRefusal. If a refusal is already recorded, it reports it through onLateRefusal and throws it, so the open fails. This is the same exit path that a refusal arriving after the callback is installed already takes. Because the check runs before the callback is installed, the refusal is reported only once.
Files:
src/main/claude/structured/startup/claude-structured-init-proof.ts: records the first refusal and exposes refusal()
src/main/claude/structured/startup/claude-structured-session-startup.ts: checks it before installing onRefusal
src/main/claude/structured/startup/claude-structured-session-startup.test.ts: new regression test
Why
The early open path did not handle a refusal that was recorded before onRefusal was installed. That let a foreign session open as a working chat. Another option was to make onRefusal a setter that fires when it is assigned. That would change the shape of the callback without removing the need to check what was already recorded. Checking seen() instead would throw without calling onLateRefusal, and the host would see a failed open with no session exit. Reading the recorded refusal once, right before installing the callback, is the smallest change that covers the gap. It leaves the normal late-refusal path unchanged.
N/A. This is main-process startup ordering with no UI change. In the failing ordering, the chat that should never have opened now does not open. A screenshot cannot show this race, so the regression test below covers it.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
To reproduce, the new test refuses the init proof before calling openClaudeSession, which is the ordering described in #48402. It then expects the open to reject with claude provider session expected and onLateRefusal to be called exactly once with that error.
On main with only the source change reverted, the test fails because the open resolves with { reportedOptions: ... } instead of rejecting.
With this change, the test passes. vitest run src/main/claude/structured/ passes (5 files, 19 tests).
Static gates on the touched files pass: anti-slop oxlint, code-quality native plugins, ast-grep, check-changed-code-quality.mjs (0 new findings), oxlint, and oxfmt.
Platforms: macOS (unit tests). The logic is platform-independent main-process TypeScript.
Performance
None, because the change adds one closure read per Claude session open (not a hot path) and adds no I/O, subprocess work, polling, or allocations on the normal path. In a microbenchmark of 200k proof creations plus the check, the cost was about 1.0 µs/op both with and without the check, within run-to-run noise. The refused path costs about 4 µs/op, mostly from constructing the Error, which already happened before this change.
Risk
Level: Low
The riskiest part is the new early failure. If refusal() returned a refusal from a different attempt, a healthy start would fail. It cannot, for two reasons. The proof is created once per acquisition. The check also runs after the existing isCurrent() guard, in the same synchronous turn, so a replaced start throws before it reaches the check. refusal() counts only refuse() calls, so child faults and journal rejections still go through their own paths. The change does not touch saved data, settings, the wire format, or remote or SSH behavior. To back it out, revert this commit.
Review
Original fix by @2SinceJuly in #48448. A maintainer then narrowed refusal() to provider refusals only, moved the check before onRefusal is installed so the refusal is reported once, and changed the test so it opens a session the way main does.
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.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
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)
I stated the risk: what could break, for whom, and how to back it out
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)
No actionable comments were generated in the recent review.
Walkthrough
ClaudeInitProof now provides an accessor for the first recorded refusal. openClaudeSession checks for a recorded refusal after confirming that the session is current. If a refusal exists, startup reports it through onLateRefusal and throws it before applying initialization facts. A test covers a refusal recorded before openClaudeSession is called.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to feade
This change stops a Claude chat from opening when a foreign initialization is refused before the session open registers its refusal callback. The refusal is now reported and the open fails. The change is small and has no concrete merge-blocking risk remaining.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
Directly linked issue #48402 requires that, after openClaudeSession installs initProof.onRefusal, the start recheck the proof. If a refusal was already recorded, the start must fail or close. It a…
Out of Scope Changes check
The whole-PR change set, from the supplied summary, has three files. claude-structured-init-proof.ts adds refusal() to ClaudeInitProof. claude-structured-session-startup.ts adds the post-assig…
Title check
The title names the main change: a Claude start whose provider refusal was recorded before onRefusal was installed now fails. It is specific and matches the summary, the linked issue, and the objectiv…
Description check
The description follows the repository template and covers ELI5, What Changed, Why, Linked Issue (Fixes #48402), Visual Proof (N/A with reason), Testing, Performance, Risk with level, Review, and the …
Full details: Linked Issues check
Explanation
Directly linked issue #48402 requires that, after openClaudeSession installs initProof.onRefusal, the start recheck the proof. If a refusal was already recorded, the start must fail or close. It also requires a test for that ordering. The supplied whole-PR summary (base to head) states that ClaudeInitProof gains refusal(), which returns the recorded error when the outcome is an error and null otherwise. The summary states that openClaudeSession calls refusal() after assigning onRefusal, and that a recorded refusal goes to onLateRefusal and fails the open when isCurrent() is true. The PR reports a test, fails the start with the recorded refusal and reports it as a late refusal, which it states fails without the source change. The PR also reports a second test for the non-current case. The raw diff for these files could not be read at head, because the changed blobs were missing from the checkout. I did not read the test file. The test result therefore rests on the PR's reported evidence and the supplied summary. The implementation uses refusal() rather than a literal seen() recheck. This meets the issue's expected behavior, because the check reads the same recorded refusal. No coding requirement from #48402 is unmet. No parent or contextual issues were supplied.
Full details: Out of Scope Changes check
Explanation
The whole-PR change set, from the supplied summary, has three files. claude-structured-init-proof.ts adds refusal() to ClaudeInitProof. claude-structured-session-startup.ts adds the post-assignment refusal check in openClaudeSession. claude-structured-session-startup.test.ts adds tests for that check. Each change implements the #48402 fix or tests it. The summary shows no unrelated code, refactoring, or configuration change. The PR description states that the check and the callback can both report one refusal. This is a documented double report. It does not add unrelated scope and does not change this verdict. I could not read the changed blobs at head, so this verdict rests on the supplied summary.
Full details: Title check
Explanation
The title names the main change: a Claude start whose provider refusal was recorded before onRefusal was installed now fails. It is specific and matches the summary, the linked issue, and the objectives. It is a long, single sentence but the scope is clear.
Full details: Description check
Explanation
The description follows the repository template and covers ELI5, What Changed, Why, Linked Issue (Fixes #48402), Visual Proof (N/A with reason), Testing, Performance, Risk with level, Review, and the checklist. The AI Disclosure section is left empty, which the template marks as optional for internal contributors. The final lint/typecheck/test/build checklist item is unchecked, but the template allows CI to cover it. The description is thorough and specific.
Autofix · 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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Assert the intended obsolete-start error.
When isCurrent() returns false, openClaudeSession reads session.connection.startupFailure. The fixture has no connection, so this test rejects with TypeError. This assertion accepts that unrelated error and leaves the intended exit untested.
Add a connection.startupFailure stub that returns a known error. Assert that opened rejects with that exact error. Keep the assertion that late is empty.
… installed
readClaudeStartupFacts can resolve on the initialize answer while a foreign
system/init is still queued. If it arrives before openClaudeSession installs
initProof.onRefusal, refuse() records the error with no callback to run,
nothing rechecks the proof, and the session opens only to be ended by the
next foreign init one turn later.
The init proof now exposes the first refusal recorded by refuse() (not child
faults or journal rejections). openClaudeSession checks it before installing
onRefusal: a recorded refusal is reported through onLateRefusal and fails the
open, the same path a refusal arriving after the assignment takes.
Fixesstablyai#48402
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(claude): answer a start whose refusal landed before onRefusal was installed
fix(claude): fail a start whose provider refusal landed before onRefusal was installed
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When Orca starts a Claude chat, it checks that the Claude process answering is the one it started. If not, Orca refuses it. During startup there is a short window where that refusal could be recorded before anything was listening for it. The "no" was written down but nobody acted on it, so the chat opened anyway and only failed one turn later. Now the start checks for a refusal that was already recorded and fails right away.
What Changed
Before:
readClaudeStartupFactscan resolve on the initialize answer while a foreignsystem/initis still queued. If that frame arrived beforeopenClaudeSessioninstalledinitProof.onRefusal,refuse()recorded the error with no callback to run. Nothing checked the proof again, so the open succeeded and the session was ended later by the next foreign init.After:
ClaudeInitProofhas a newrefusal()that returns the first refusal recorded byrefuse(). Child faults and journal rejections are not counted, so this returns only whatonRefusalwould have received.openClaudeSessionchecksrefusal()after its existingisCurrent()guard and before it installsonRefusal. If a refusal is already recorded, it reports it throughonLateRefusaland throws it, so the open fails. This is the same exit path that a refusal arriving after the callback is installed already takes. Because the check runs before the callback is installed, the refusal is reported only once.Files:
src/main/claude/structured/startup/claude-structured-init-proof.ts: records the first refusal and exposesrefusal()src/main/claude/structured/startup/claude-structured-session-startup.ts: checks it before installingonRefusalsrc/main/claude/structured/startup/claude-structured-session-startup.test.ts: new regression testWhy
The early open path did not handle a refusal that was recorded before
onRefusalwas installed. That let a foreign session open as a working chat. Another option was to makeonRefusala setter that fires when it is assigned. That would change the shape of the callback without removing the need to check what was already recorded. Checkingseen()instead would throw without callingonLateRefusal, and the host would see a failed open with no session exit. Reading the recorded refusal once, right before installing the callback, is the smallest change that covers the gap. It leaves the normal late-refusal path unchanged.Linked Issue
Fixes #48402
Visual Proof
N/A. This is main-process startup ordering with no UI change. In the failing ordering, the chat that should never have opened now does not open. A screenshot cannot show this race, so the regression test below covers it.
Testing
To reproduce, the new test refuses the init proof before calling
openClaudeSession, which is the ordering described in #48402. It then expects the open to reject withclaude provider session expectedandonLateRefusalto be called exactly once with that error.mainwith only the source change reverted, the test fails because the open resolves with{ reportedOptions: ... }instead of rejecting.vitest run src/main/claude/structured/passes (5 files, 19 tests).check-changed-code-quality.mjs(0 new findings), oxlint, and oxfmt.Platforms: macOS (unit tests). The logic is platform-independent main-process TypeScript.
Performance
None, because the change adds one closure read per Claude session open (not a hot path) and adds no I/O, subprocess work, polling, or allocations on the normal path. In a microbenchmark of 200k proof creations plus the check, the cost was about 1.0 µs/op both with and without the check, within run-to-run noise. The refused path costs about 4 µs/op, mostly from constructing the
Error, which already happened before this change.Risk
Level: Low
The riskiest part is the new early failure. If
refusal()returned a refusal from a different attempt, a healthy start would fail. It cannot, for two reasons. The proof is created once per acquisition. The check also runs after the existingisCurrent()guard, in the same synchronous turn, so a replaced start throws before it reaches the check.refusal()counts onlyrefuse()calls, so child faults and journal rejections still go through their own paths. The change does not touch saved data, settings, the wire format, or remote or SSH behavior. To back it out, revert this commit.Review
Original fix by @2SinceJuly in #48448. A maintainer then narrowed
refusal()to provider refusals only, moved the check beforeonRefusalis installed so the refusal is reported once, and changed the test so it opens a session the waymaindoes.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)