Skip to content

fix(claude): fail a start whose provider refusal landed before onRefusal was installed - #48448

Merged
nwparker merged 1 commit into
stablyai:mainfrom
2SinceJuly:fix/48402-late-refusal-recheck
Nov 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
2SinceJuly:fix/48402-late-refusal-recheck

Conversation

@2SinceJuly

@2SinceJuly 2SinceJuly commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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: 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.

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

  • 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)

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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: Passed 4

Check name Status Explanation
Linked Issues check Passed 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 Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b907538f-5ed2-4e47-9496-11619daa2438
Commits

Reviewing files that changed from the base of the PR and between d6f9ae1 and feade86.

Files selected for processing: 3

  • src/main/claude/structured/startup/claude-structured-init-proof.ts
  • src/main/claude/structured/startup/claude-structured-session-startup.test.ts
  • src/main/claude/structured/startup/claude-structured-session-startup.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.

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8d720426-5514-42c9-b8ac-e0cb79291480
Commits

Reviewing files that changed from the base of the PR and between d286347 and d6f9ae1.

Files selected for processing: 3

  • src/main/claude/structured/startup/claude-structured-init-proof.ts
  • src/main/claude/structured/startup/claude-structured-session-startup.test.ts
  • src/main/claude/structured/startup/claude-structured-session-startup.ts

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

it('keeps the refusal for the session exit when this start is no longer the current one', async () => {
const { initProof, opened, late } = opening(() => false)
initProof.refuse()
await expect(opened).rejects.toBeInstanceOf(Error)

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.

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.

Fixes stablyai#48402

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/48402-late-refusal-recheck branch from d6f9ae1 to feade86 Compare November 24, 2026 21:28
@nwparker 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
@nwparker
nwparker merged commit 99d6252 into stablyai:main Nov 24, 2026
55 of 56 checks passed
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.

Claude start can open after a foreign system/init that lands before the refusal callback is installed

2 participants