Skip to content

fix(grid): accept OSC 7 from every hostname the machine has gone by - #84

Merged
simota merged 2 commits into
mainfrom
fix/osc7-hostname-drift
Sep 10, 2026
Merged

simota merged 2 commits into
mainfrom
fix/osc7-hostname-drift

Conversation

@simota

@simota simota commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • New tabs, splits, and the scratch terminal stopped inheriting the focused shell's cwd.
  • Root cause: the OSC 7 host gate (host_is_local) cached gethostname(2) once per process, but macOS rewrites the hostname on every network change (DHCP reverse-DNS name online, <name>.local offline) while a shell's $HOST is frozen at its own startup. After a change every cwd report was rejected as non-local, so Terminal.cwd stayed None.
  • Fix: re-query on each OSC 7 (cheap sysctl) and match against a bounded set (8) of every hostname observed during the process lifetime, so shells started before and after a change both pass. Fail-toward-accept, as REQ-OSC-2 intends.

Test plan

  • cargo test -p noa-grid (632 passed) incl. new hostname_matches_any_local_accepts_names_the_machine_went_by_earlier
  • cargo clippy --workspace — no new warnings
  • Manual: on a machine whose hostname changed since app launch, cd somewhere and ⌘T opens the new tab in that directory

https://claude.ai/code/session_01YTGJ217L3Zc1eZAGeyftpm

The OSC 7 host gate cached gethostname(2) once per process, but macOS
rewrites the hostname on every network change (DHCP reverse-DNS name
online, <name>.local offline) while a shell's $HOST is frozen at its own
startup. After a change every cwd report was rejected as non-local, so
Terminal.cwd stayed None and new tabs, splits, and the scratch terminal
no longer inherited the focused shell's directory.

Re-query on each OSC 7 and match against a bounded set of every name
observed during the process lifetime, so shells started before and after
a change both pass.

Claude-Session: https://claude.ai/code/session_01YTGJ217L3Zc1eZAGeyftpm
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T06:06:36.771470Z ae1a183 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae1a183901

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/noa-grid/src/osc.rs Outdated
let mut observed = OBSERVED
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
if !observed.contains(&current) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refresh re-observed hostnames before eviction

When hostname changes follow A, B, …, H, A, I, reconnecting to A leaves it at the front because contains does not refresh its position. Observing I then evicts A, so a shell started during the second A period has its OSC 7 updates rejected immediately after the next network change, recreating the regression this cache is intended to prevent. Move a re-observed entry to the back before applying the bounded eviction policy.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed in 25c8d23: a re-observed name is moved to the back before eviction (LRU).

@simota
simota merged commit 20eeb3f into main Sep 10, 2026
1 check passed
@simota
simota deleted the fix/osc7-hostname-drift branch September 10, 2026 06:17
@simota simota mentioned this pull request Sep 10, 2026
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