Skip to content

Implement PtyWrite event - #16

Merged
Pajn merged 1 commit into
mainfrom
pty-write
Jul 10, 2026
Merged

Implement PtyWrite event#16
Pajn merged 1 commit into
mainfrom
pty-write

Conversation

@Pajn

@Pajn Pajn commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Stack

Summary by CodeRabbit

  • New Features

    • Child terminal sessions now receive sensible TERM and COLORTERM defaults (with xterm-256color / truecolor).
    • User-provided terminal environment values override the defaults.
  • Bug Fixes

    • Improved handling and delivery of terminal query replies (e.g., cursor-position and device/status responses) without stalling PTY activity.
  • Tests

    • Added integration coverage for cursor-position reply capture and for default/overridden terminal environment propagation.

@Pajn Pajn mentioned this pull request Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1c6737be-66bc-411a-a978-73566cb2b465

📥 Commits

Reviewing files that changed from the base of the PR and between b115e38 and ce358f7.

📒 Files selected for processing (4)
  • crates/embers-server/src/buffer_runtime.rs
  • crates/embers-server/src/config.rs
  • crates/embers-server/src/terminal_backend.rs
  • crates/embers-test-support/tests/buffer_runtime.rs

📝 Walkthrough

Walkthrough

The terminal backend now drains emulator replies with activity state. The runtime keeper writes replies on a dedicated bounded-channel thread, while buffer configuration adds default terminal environment hints with caller overrides.

Changes

Terminal runtime and environment

Layer / File(s) Summary
Backend event draining
crates/embers-server/src/terminal_backend.rs
TerminalBackend::take_events returns activity state and accumulated PTY replies, with backend state, event handling, implementations, and tests updated accordingly.
Asynchronous runtime reply routing
crates/embers-server/src/buffer_runtime.rs
Runtime keeper replies are forwarded through a bounded non-blocking channel to a dedicated writer thread, with reply drops and shutdown handling.
Terminal environment propagation
crates/embers-server/src/config.rs, crates/embers-test-support/tests/buffer_runtime.rs
Default TERM and COLORTERM values are added with caller overrides, and integration tests cover environment propagation and CPR round trips.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Shell
  participant PTY
  participant KeeperSurface
  participant TerminalBackend
  participant ReplyWriter
  Shell->>PTY: emit terminal query
  PTY->>KeeperSurface: route_output(query)
  KeeperSurface->>TerminalBackend: take_events()
  TerminalBackend-->>KeeperSurface: reply bytes
  KeeperSurface-->>PTY: activity and replies
  PTY->>ReplyWriter: enqueue reply bytes
  ReplyWriter-->>PTY: write reply
  PTY-->>Shell: deliver terminal response
Loading

Possibly related PRs

  • Pajn/Embers#7: Introduces the runtime-keeper architecture used by the updated PTY reply routing.
  • Pajn/Embers#13: Uses the related PTY reply and byte-write forwarding path in output-pipe support.

Poem

I’m a bunny with bytes in my burrow tonight,
Replies hop swiftly from query to write.
Bells ring, cursors report, terminals gleam,
TERM finds its way through the environment stream.
Async paws keep the reader loop free—
A carrot for every PTY! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding and routing PtyWrite event handling.
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.

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.

Base automatically changed from term-color to main July 10, 2026 12:42
This was referenced Jul 10, 2026
@Pajn

Pajn commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/embers-server/src/buffer_runtime.rs`:
- Around line 1328-1342: Shared PTY writes currently block while holding
runtime.writer, allowing keeper_reply_write_loop to stall KeeperRequest::Write
and client requests. Refactor keeper_reply_write_loop and KeeperRequest::Write
to submit all PTY writes through a single bounded queue serviced by a dedicated
writer task/thread, so request handlers only perform a non-blocking or bounded
handoff and never hold the writer mutex during write_all or flush.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ca55d162-9335-4c6b-a6cf-8c4c50a04c53

📥 Commits

Reviewing files that changed from the base of the PR and between c7cafe6 and b115e38.

📒 Files selected for processing (4)
  • crates/embers-server/src/buffer_runtime.rs
  • crates/embers-server/src/config.rs
  • crates/embers-server/src/terminal_backend.rs
  • crates/embers-test-support/tests/buffer_runtime.rs

Comment thread crates/embers-server/src/buffer_runtime.rs Outdated
@Pajn

Pajn commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Pajn
Pajn merged commit 1cbe408 into main Jul 10, 2026
4 checks passed
@Pajn
Pajn deleted the pty-write branch July 10, 2026 15:09
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