Skip to content

fix(chat): check the sender before a chat message's prompt is written - #1792

Merged
devswha merged 1 commit into
mainfrom
fix/chat-prompt-sender-guard
Oct 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/chat-prompt-sender-guard

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • server/core/composer.ts: the chat composer's agentPrompt call now passes the sender's live authorize as herdr's write guard, as the input line's long-line path does since fix(terminal-input): send a long input-line line to the pane's agent as its prompt #1791. herdr asks it once connected, right before the prompt is written. A sender that was revoked or switched to watching meanwhile gets that refusal (read_only or device_revoked), nothing is written, and nothing runs after it: no typing fallback, no Codex queue check. The guard and the refusal it records are declared once in submitText and shared by both agentPrompt calls.
  • server/core/chat-prompt-guard.test.ts: a chat message goes out with a guard; a sender that starts watching once herdr is reached gets read_only with nothing written or typed; a pane herdr finds no agent in is still typed into.
  • server/submit.contract.test.ts, next to fix(terminal-input): send a long input-line line to the pane's agent as its prompt #1791's observe case: writes no chat message for a sender that switched to observe while herdr was being reached. With Claude's input box read as empty, agentPrompt is held before it reaches the isolated test herdr, the sender switches to observe, then the real RPC runs. The test expects read_only, and that the recorder receives only another client's later line.
  • Nine assertions that pinned agentPrompt's two-argument call (six in server/submit.contract.test.ts, three in server/core/outcome-delivery.test.ts) now expect the guard as well.
  • changelog.d/chat-prompt-sender-guard.md.

Verification

  • On main, two of the three new unit cases fail and the new contract test fails with ok: true: the message was written after the sender switched to observe. All pass with this change.
  • server/core unit tests 88/88, server/submit.contract.test.ts 86/86, src/lib/compose.test.ts 51/51.
  • bun run check fast.

Not changed here: queued and held messages go through dispatchPendingText, not this call. The input line's typed fallback (paneSendText after mirrorInput), Claude's draft-clear keys and OpenCode's skill typing still check the sender without recording a refusal.

@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 ddb098b and 6ae3c18.

📒 Files selected for processing: 5
  • changelog.d/chat-prompt-sender-guard.md
  • server/core/chat-prompt-guard.test.ts
  • server/core/composer.ts
  • server/core/outcome-delivery.test.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; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Messages are no longer sent to an agent if the sending connection is revoked or switches to read-only mode while delivery is in progress. The unsent message is not typed in its place.
    • Other connections can continue submitting messages after a delivery is refused.

Prompt delivery now passes a sender-authorization callback to agentPrompt. If authorization changes to read-only during delivery, submission rejects without typing the message. Tests cover this behavior and preserve fallback typing when agentPrompt reports agent_not_found.

Changes: Chat prompt authorization

Layer / File(s) Summary
Prompt authorization guard
server/core/composer.ts, server/core/chat-prompt-guard.test.ts, changelog.d/chat-prompt-sender-guard.md
submitText shares an authorization callback across delivery paths. It rethrows captured authorization refusals. Focused tests cover the read-only transition and the agent_not_found fallback.
Submit and delivery contract coverage
server/core/outcome-delivery.test.ts, server/submit.contract.test.ts
Delivery expectations include the callback argument. A regression test checks that a sender switched to observe mode is rejected and that another connection can submit.

Priority: ➖ Normal

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

Change: Bug fix

Possibly related PRs

  • devswha/ovis#1791: It adds the long terminal-input path through createSubmitText and agentPrompt; this change adds the authorization callback to both prompt paths.

Suggested reviewers: jiunshinn

Merge Risk: ⚪ Minimal · up to 6ae3c

No actionable merge-blocking issue is established for the guarded chat submission change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: checking the sender before writing a chat prompt.
Description check Passed The description explains the problem, resulting behavior, implementation scope, regression tests, contract-test coverage, and verification results. It uses "Summary" and "Verification" instead of the …
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, implementation scope, regression tests, contract-test coverage, and verification results. It uses "Summary" and "Verification" instead of the template's "Change" and "Validation" headings, but the required information is present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 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 observe permissions, so this comment records the review. A gate reviewer on a different model than the author's found no blockers within this PR's scope.

What was checked:

  • The guard and its recorded refusal are scoped to each submit. The two agentPrompt branches are mutually exclusive, so a refusal can't leak into another call or a later message. Direct probes confirmed this.
  • A refusal (read_only or device_revoked) stops before the typing fallback and the Codex queue check.
  • The nine updated assertions only add the guard arguments.
  • 88 server/core tests, both typechecks and 86 isolated submit.contract tests pass.

Follow-up: an older race outside this PR. The input line's typed fallback (server/core/composer.ts ~540-546, paneSendText after mirrorInput) checks authorization before starting each RPC, but passes no write guard. With a mocked connection boundary, the reviewer reproduced pane.send_text landing after the sender switched to observe or was revoked. That path is excluded from this PR, so it needs its own fix: pass the same guard to paneSendText.

The reviewer found no matching hole in the other excluded paths. Queued and held delivery (dispatchPendingText), Claude's draft-clear keys and OpenCode's skill typing all keep write-boundary guards.

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

@devswha
devswha merged commit 4f8179c into main Oct 24, 2026
17 checks passed
@devswha
devswha deleted the fix/chat-prompt-sender-guard branch October 24, 2026 01:54
devswha added a commit that referenced this pull request Oct 24, 2026
… are written (#1796)

## Summary

- `server/core/composer.ts`: the typing that ends `submitText` now
writes the text and its Enter with the sender's live `authorize` as
herdr's write guard. #1791 and #1792 already do this for both
`agentPrompt` calls. herdr asks the guard once connected, right before
each write.
- If the sender was revoked, or switched to watching, while the text was
on its way, nothing is written.
- If it happened while the Enter was on its way, the text stays typed
and no Enter is pressed. This matches what the existing `authorize()`
check before the Enter already does.
- Either way the submit fails with the sender's own refusal (`read_only`
or `device_revoked`), not herdr's `cancelled`.
- This typing carries the terminal input line's short lines and
multi-line messages, chat messages to a pane without an agent (or where
`agent.prompt` answers `agent_not_found`, `agent_not_ready`, or
`agent_blocked` only by a Codex queue), and mirrored panes.
- `server/core/typed-send-guard.test.ts`:
  - both writes get a guard;
- a lapse while the text is on its way writes nothing and reports
`read_only`;
- a lapse while the Enter is on its way writes the text only and reports
`read_only`.
- `server/submit.contract.test.ts`, next to the observe cases of #1791
and #1792: `types nothing of an input line for a sender that switched to
observe while herdr was being reached`. A shell recorder pane is used,
and `paneSendText` is held before it reaches the isolated test herdr.
The sender switches to observe, then the real RPC runs. The test expects
`read_only`, and that the recorder receives only another client's later
line.
- Eight assertions that pinned the two-argument `paneSendText` and
`paneSendKeys` calls now expect the guard as well (`input-line-send`,
`chat-prompt-guard` and `outcome-delivery` tests).
- `changelog.d/typed-send-sender-guard.md`.

## Verification

- On main, the three new unit cases fail, and the new contract test
fails: the recorder receives the held line, then the other client's
line.
- With this change: `server/core` unit tests 91/91,
`server/submit.contract.test.ts` 87/87 (including the existing `still
sends the Enter after the sender is gone`), `src/lib/compose.test.ts`
51/51.
- `bun run check fast`.

Queued and held messages (`dispatchPendingText`) already pass a guard to
their paste, Enter and Escape writes. Claude's draft-clear keys and
OpenCode's skill typing pass one as well. A refusal there writes nothing
but is reported as `cancelled`; this PR does not change those two paths.
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