Skip to content

fix(chat): report the sender's refusal when clearing Claude's restored copy is stopped - #1798

Merged
devswha merged 1 commit into
mainfrom
fix/claude-clear-refusal
Oct 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/claude-clear-refusal

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • server/core/composer.ts freeClaudeBox: the two Esc presses that clear Claude Code's restored copy of the chat's last message already pass the sender's authorize as herdr's write guard, but the guard dropped the refusal. A sender revoked or switched to watching while an Esc was on its way got herdr's cancelled ("herdr pane.send_keys was not sent"). The guard now records the sender's refusal, and both Esc writes fail with it: read_only or device_revoked. Nothing more is written either way. freeClaudeBox serves immediate chat sends and queued delivery (server/core/pending.ts, unchanged here). In queued delivery, a launched agent's first message whose page is still open now treats such a lapse like one just before the Esc: its code (read_only, input_not_ready, pending_lease_lost, disconnected) is a first-message retry code (FIRST_MESSAGE_RETRY_CODES), so the message stays queued instead of being held as cancelled. Other queued messages are held as before, now with the sender's code.
  • server/submit.contract.test.ts, next to the existing restored-copy case: answers a sender that switched to observe while an Esc for Claude's restored copy was on its way with its own refusal. In this test the sender's connection switches to observe while herdr is reached for the first Esc, and the guard is asked as herdrRpc asks it. The test expects read_only, no Esc written and no prompt sent.
  • changelog.d/claude-clear-refusal.md.

Verification

  • On main the new contract test fails: the submit answers cancelled. It passes with this change.
  • server/submit.contract.test.ts 88/88, server/pending-input.contract.test.ts 85/85, server/core unit tests 91/91.
  • bun run check fast.

OpenCode's skill typing still reports such a refusal as cancelled (its typing callback swallows it); it writes nothing either, and is not changed here.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f69488f and 1dcbb40.

Files selected for processing: 3
  • changelog.d/claude-clear-refusal.md
  • server/core/composer.ts
  • server/submit.contract.test.ts

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

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • When a message cannot be sent because access was revoked or the chat switched to observe-only mode while Claude Code cleared a restored message, the chat now explains why it was not sent instead of showing only a generic notice. The message remains unsent when the chat is read-only.

The Claude draft-clearing path now preserves the sender’s authorization refusal when an Esc write is cancelled. A contract test covers switching to observe mode during the write and verifies that the submit returns read_only without calling agent.prompt. A changelog entry describes the updated not-sent message.

Changes: Claude restored-draft clearing

Layer / File(s) Summary
Preserve authorization refusal during draft clearing
server/core/composer.ts, server/submit.contract.test.ts, changelog.d/claude-clear-refusal.md
freeClaudeBox now routes Esc write failures through a refusal handler that preserves an authorization error. The contract test checks the observe-mode race, cancelled key write, read_only result, and skipped agent.prompt call. The changelog describes the updated not-sent message.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • Issue 1546 concerns same-release changelog entries for Claude Code refusal behavior; this change adds such an entry.

Possibly related PRs

  • devswha/ovis#1796: Both changes preserve live sender authorization refusals in writes from server/core/composer.ts.
  • devswha/ovis#1792: Both changes preserve sender authorization refusals during chat submission.
  • devswha/ovis#1791: Both changes address sender authorization during composer writes, including Claude draft-clear keys.
Merge Risk: Minimal · up to 1dcbb

The refusal is reported without sending the message, and queued messages are retained. No merge-blocking issue is established.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the main change: preserving and reporting the sender's refusal when clearing Claude's restored copy is stopped.
Description check Passed The description explains the problem, resulting behavior, affected code paths, regression test, changelog entry, and validation results. It uses "Summary" and "Verification" instead of the template's …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
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.
Full details: Description check

Explanation

The description explains the problem, resulting behavior, affected code paths, regression test, changelog entry, and validation results. It uses "Summary" and "Verification" instead of the template's "Change" and "Validation" headings, but it provides the required information.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

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

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: this touches queued delivery and observe permissions, so this comment records the review. A gate reviewer on a different model than the author's found no blocking issues.

Tests: all pass. That's 91 server/core unit tests, the typecheck, and 173 isolated contract tests (submit.contract and pending-input.contract).

What the reviewer checked:

  • Both refusal codes: the extra probes reached read_only and device_revoked at both Esc writes. The recorded refusal stays inside each freeClaudeBox call.
  • Queued delivery (pending.ts, unchanged here):
    • Ordinary queued messages stay held.
    • A launched agent's first message is retried only while its requester is still associated and present.
    • A real switch to observe removes that association, so the message is held as first_message_unattended.
    • device_revoked is never retried.
    • No path drops a message silently, types it for an unauthorized sender, or sends it twice.

Not checked by hand: keeping the draft in the browser. The reviewer read that code but didn't exercise it manually.

All required checks are green and no review thread is open.

@devswha
devswha merged commit 8511a54 into main Oct 24, 2026
17 checks passed
@devswha
devswha deleted the fix/claude-clear-refusal branch October 24, 2026 02:37
devswha added a commit that referenced this pull request Oct 24, 2026
…stopped before anything is typed (#1799)

## Summary

- `server/core/composer.ts`, the OpenCode `@skill` typing in
`submitText`: every write already passed the sender's check as herdr's
write guard. Two problems remained.
  - The check dropped the refusal.
- `typed` was set as soon as the check before a write passed, before
herdr was reached.
- What a sender revoked or switched to watching while the first piece
was on its way got: `submit_partial`, "Part of the message was typed
into OpenCode's input, but sending was not confirmed... Check the
terminal", even though nothing was typed.
- Now:
- `typed` is set only once herdr's guard lets a write through: the skill
writes go through a `SkillAttachIo` that marks it.
- The check records its refusal (`read_only`, `device_revoked`, or
`submit_timeout`).
- A send that typed nothing fails with that refusal. Once something is
typed, `submit_partial` stays as before.
  - The same pattern as #1796 and #1798.
- `server/opencode-first-message.contract.test.ts`: `answers a sender
that switched to observe while its @skill was on its way with its own
refusal, typing nothing`.
- It uses the file's verified OpenCode 2.0.32 stand-in. The sender's
connection switches to observe right before `@effect` reaches the
isolated test herdr, and the real RPC then asks the guard.
- It expects `read_only`, and that no write went through and the
stand-in received nothing.
- The file's pane and connection setup moved into `openCodePane` and
`connect`, shared with the first-message cases.
- `changelog.d/opencode-skill-refusal.md`.

## Verification

- On main the new test fails: the submit answers `submit_partial`. It
passes with this change.
- `server/opencode-first-message.contract.test.ts` 5/5,
`server/submit.contract.test.ts` 88/88.
- Unit tests in `server/core`, `server/opencode-skill-attach.test.ts`,
`server/opencode-native.test.ts` and `server/conventions.test.ts`:
145/145.
- Typecheck, `bun run check fast`.

Not changed here: queued delivery types skills through its own guard in
`server/core/pending.ts` (open PR #1795 touches that file).
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.

1 participant