Skip to content

fix: refresh host colors before focus returns - #2017

Open
matthiasSchedel wants to merge 1 commit into
herdrdev:masterfrom
matthiasSchedel:fix/refresh-host-colors-on-focus
Open

fix: refresh host colors before focus returns#2017
matthiasSchedel wants to merge 1 commit into
herdrdev:masterfrom
matthiasSchedel:fix/refresh-host-colors-on-focus

Conversation

@matthiasSchedel

Copy link
Copy Markdown

Summary

  • refresh the host terminal's OSC 10/11 colors after outer focus leaves Herdr
  • re-arm fragmented host-color reply framing for each query generation
  • keep color selection entirely host-driven, with no platform or fixed light/dark palette

Reproduction

On macOS with WezTerm, switch system appearance while Herdr is unfocused, then return to a Codex pane. The composer can retain stale host colors and render its background and text with insufficient contrast.

Verification

  • cargo test later_host_color_query_rearms_split_reply_framing
  • cargo test outer_focus_loss_requests_host_theme_query
  • ZIG=/opt/homebrew/opt/zig@0.15/bin/zig just ci 'all() - test(live_handoff_keeps_unmanaged_agent_name_bound_to_saved_session)'
  • ZIG=/opt/homebrew/opt/zig@0.15/bin/zig just windows-lint
  • repository maintenance unittest suite (93 tests)

live_handoff_keeps_unmanaged_agent_name_bound_to_saved_session fails on this macOS host with agent_not_found; the identical failure reproduces from a detached, pristine upstream master worktree.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Host terminal theme querying now uses an atomic generation counter shared between the client loop and stdin reader. Unix input framing re-arms when the generation changes, and outer focus loss now triggers theme queries.

Changes

Host theme query coordination

Layer / File(s) Summary
Theme query triggers
src/raw_input.rs
OuterFocusLost now requires a host terminal theme query, with corresponding test coverage.
Generation propagation
src/client/mod.rs
The client creates and shares an AtomicU64; theme query requests increment it before emitting the OSC sequence.
Unix framer re-synchronization
src/client/input.rs
The stdin reader detects generation changes, re-arms host color query framing, and tests follow-up output after a generation bump.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClientLoop
  participant ThemeQuery
  participant Generation
  participant StdinReader
  participant RawInputFramer
  ClientLoop->>ThemeQuery: request host terminal theme
  ThemeQuery->>Generation: increment generation
  ThemeQuery->>StdinReader: shared generation becomes observable
  StdinReader->>RawInputFramer: re-arm query framing
  RawInputFramer-->>StdinReader: forward re-sent query response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: refreshing host colors when focus returns.
Description check ✅ Passed The description matches the changeset and explains the host color refresh, re-arming, reproduction, and verification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@kangal-bot kangal-bot added coderabbit-review greptile-review Trigger Greptile review for contributor-approved pull requests labels Jul 29, 2026
@matthiasSchedel

Copy link
Copy Markdown
Author

@coderabbitai review

@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

Refresh host OSC 10/11/palette colors when outer focus is lost, and re-arm fragmented host-color reply framing via a generation counter shared with the stdin reader.

  • events_require_host_terminal_theme_query now treats OuterFocusLost like scheme-change reports.
  • query_host_terminal_theme bumps an AtomicU64 generation before writing the query; the Unix stdin loop syncs and re-arms the framer on each generation change.
  • Unit tests cover re-arm after split ESC replies and focus-loss theme query selection.

Confidence Score: 5/5

This PR appears safe to merge; the focus-loss theme refresh and generation-based framer re-arm match the stated stale-color fix without a concrete blocking defect in the changed path.

Generation is observed and the framer is re-armed immediately before push on the same read that delivers replies; complete OSC color sequences parse without relying on lone-ESC hold; OuterFocusLost querying is covered by tests and aligns with refreshing colors before return focus.

Important Files Changed

Filename Overview
src/client/input.rs Replaces one-shot host_color_query_sent bool with generation sync so later theme queries re-arm lone-ESC holding and scheme-change tracking before push.
src/client/mod.rs Shares AtomicU64 generation with the stdin thread and increments it on each host theme query (startup and event-driven).
src/raw_input.rs OuterFocusLost now requests a host theme re-query; tests assert focus-gain does not and focus-loss does.

Reviews (1): Last reviewed commit: "fix: refresh host colors before focus re..." | Re-trigger Greptile

@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

🧹 Nitpick comments (1)
src/client/input.rs (1)

133-146: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Move Unix-specific framing coordination behind src/platform/.

This new Unix-only helper extends platform behavior in src/client/input.rs; keep the platform adapter here generic and isolate the Unix implementation under src/platform/.

As per coding guidelines, “Keep core modules free of #[cfg(target_os)]; isolate platform checks and behavior under src/platform/.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ace6ae8e-2c06-43c0-ad6b-b8723831d216

📥 Commits

Reviewing files that changed from the base of the PR and between 73d9200 and 1780185.

📒 Files selected for processing (3)
  • src/client/input.rs
  • src/client/mod.rs
  • src/raw_input.rs

Comment thread src/client/input.rs

@ogulcancelik ogulcancelik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this queries on focus loss, before the appearance changes. wezterm does not emit csi 2031 notifications, so please query on focus gain instead and add a regression test for loss → appearance change → gain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review greptile-review Trigger Greptile review for contributor-approved pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants