Skip to content

fix(terminal-input): check the sender before typed text and its Enter are written - #1796

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

devswha merged 1 commit into
mainfrom
fix/typed-send-sender-guard

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

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. fix(terminal-input): send a long input-line line to the pane's agent as its prompt #1791 and fix(chat): check the sender before a chat message's prompt is written #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 fix(terminal-input): send a long input-line line to the pane's agent as its prompt #1791 and fix(chat): check the sender before a chat message's prompt is written #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.

@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 a2ef2a5 and a81a1ce.

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

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Terminal input lines and pane chat messages are no longer sent when the sending device loses write access or switches to watch-only mode while a message is being delivered.
    • If access changes before a message is entered, the entry is blocked; if it changes before Enter is sent, the message is not submitted.

Terminal text and Enter writes now use sender authorization guards. The submitter preserves sender refusals when a guarded write fails. Unit and integration tests cover authorization changes during submission.

Changes: Typed terminal send guard

Layer / File(s) Summary
Guarded writes and refusal handling
server/core/composer.ts, server/core/typed-send-guard.test.ts, server/core/chat-prompt-guard.test.ts, server/core/input-line-send.test.ts, server/core/outcome-delivery.test.ts
Mirrored-pane text and Enter writes receive an authorization callback. The submitter checks authorization before Enter and returns the sender refusal when a guarded write fails. Unit tests and updated assertions cover guarded writes.
Submission race contract
server/submit.contract.test.ts, changelog.d/typed-send-sender-guard.md
An integration test holds a text write while its sender changes to observe mode. It checks for a read_only result, verifies that another client can submit, and confirms the held line was not typed. The changelog describes the affected inputs and timing condition.

Priority: ➖ Normal

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

Change: Bug fix

Possibly related PRs

  • devswha/ovis#1792: Both changes guard sends in server/core/composer.ts with the sender's live authorization. That PR guards agentPrompt for chat delivery.
  • devswha/ovis#1791: Both changes cover terminal input-line submission in createSubmitText. That PR adds the long-line agentPrompt path and its typed fallback.
Merge Risk: ⚪ Minimal · up to a81a1

Terminal sends now check the sender before writing text and Enter. No outstanding issue identified here prevents merging after normal checks.

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 6 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 names the main change: the sender is checked before typed text and its Enter are written. It matches the composer.ts change, the guard tests, and the contract test in the objectives. It uses…
Description check Passed The description follows the template. It has a Summary that explains the Change: the composer.ts guard, the refusal behavior for both the text and Enter writes, and the affected input paths. It also h…
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: Title check

Explanation

The title names the main change: the sender is checked before typed text and its Enter are written. It matches the composer.ts change, the guard tests, and the contract test in the objectives. It uses a conventional fix(scope) form and is 81 characters long, within a typical length.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the Change: the composer.ts guard, the refusal behavior for both the text and Enter writes, and the affected input paths. It also has a Verification section listing unit and contract test results and the check command. It links the related PRs #1791 and #1792 and the changelog entry, which the template asks for. It does not use the exact template headings (Change, Validation), and it lists 'Verification' instead of 'Validation'. Those are minor deviations because the content 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 6 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 blocking issues. This closes the follow-up raised in #1792's review.

What was checked:

  • Both writes are guarded: the fallback's text write and its Enter both get the live guard, mirrored panes included.
  • Closed connections still get their Enter: a closed connection isn't treated as revoked. The unchanged contract "still sends the Enter after the sender is gone" still asserts and receives gone\r.
  • A refused Enter matches main: it leaves the same half-typed state and error as main's existing authorize() check, with no automatic replay.
  • Updated assertions: the eight changed assertions only add guard arguments.
  • Tests: 91 server/core tests, the typecheck and 87 isolated submit.contract tests pass.

CI: the first Integration run failed one test, pending-input.contract "delivers queued /model as /model to codex": the recorder timed out after 8 s. A second review found it unrelated:

  • Different path: queued delivery goes drainPending → dispatchPending → dispatchPendingText with its own unchanged authorizePending guard, and never reaches the changed submitText fallback.
  • Clean local runs: 3 runs each on this head and on main passed, 18 passes with no failures including the neighbouring omp cases.
  • Re-run: the failed job passed on re-run.

Notes:

  • A later, deliberate Send can still retype text that was kept after a refused Enter. That predates this PR.
  • One guard-argument unit test is redundant.

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

@devswha
devswha merged commit f69488f into main Oct 24, 2026
23 of 25 checks passed
@devswha
devswha deleted the fix/typed-send-sender-guard branch October 24, 2026 02:14
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