Skip to content

Confirm a tab or pane focus only after it has left - #635

Merged
yansfil merged 1 commit into
mainfrom
fix/confirm-only-sent-focus
Oct 6, 2026
Merged

yansfil merged 1 commit into
mainfrom
fix/confirm-only-sent-focus

Conversation

@yansfil

@yansfil yansfil commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Refs #629
Related: #631

Summary

나가지 않은 tab focus나 pane focus를 session이 확정하던 core 결함을 고칩니다. #631(늦게 나간 tab focus를 superseded로 기억)과 같은 뿌리입니다.

  • 기전: lane에서 기다리는 요청이 나가기 전에 온 session은 그 요청 전의 Herdr입니다. 그런데 그 session이 요청의 대상을 보이고 있으면 답으로 읽혔습니다.
  • 증상 1: 대기 중인 pane focus가 확정되어 끝내 Herdr에 가지 않았습니다. Flaky test: cycles: ⌃Tab and ⌥Tab commit once, on releasing the held modifier #629 재현에서 Remember a tab focus that leaves after its wait was replaced #631 뒤에도 12번 중 10번, Hide는 t3을 보이는데 Herdr는 다음 조작까지 t1에 남았습니다.
  • 증상 2: Herdr가 스스로 옮겨 간 tab이 대기 중인 tab focus를 확정해 지우고, 그 요청이 나가면 #631이 superseded로 기억해 3초 안의 Herdr 진짜 이동을 답으로 소비했습니다.
  • 고침: 확정은 나간 요청만, 두 경로로 합니다. (a) 그 tab을 보이는 session(pane은 그 tab의 layout), (b) Herdr의 성공 답이 왔을 때 Hide가 마지막에 읽은 session이 이미 그 tab을 보이면 그 답. 거절과 3초 deadline은 기존 규칙 그대로입니다.
  • (b)가 필요한 이유: pinned Herdr 0.9.1은 이미 보이는 tab을 focus하면 event를 내지 않습니다. private server로 확인했고(다른 tab으로 이동은 tab_focused와 pane_focused, 같은 tab 재focus는 없음), docs/ARCHITECTURE.md의 Herdr wire boundary 동작 gap에 적었습니다.
  • docs/ARCHITECTURE.md control lane 문단에 확정 규칙과 그 이유를 더했습니다.

Review

  • 조심해서 볼 파일: herdr-core/src/runtime/session.rs reconcile_visible_tabs, session_confirms_pending_pane - runtime mutex 안. 더한 일은 sent 확인뿐입니다.
  • 조심해서 볼 파일: session.rs confirm_tab_focus_already_shown, terminal.rs pane focus 답 - failure path가 아닌 성공 답에서만, herdr_active_tab_ids 조회 하나. I/O 없음.
  • 판단해 주세요: 기존 test 2개의 준비 단계를 고쳤습니다. 둘 다 lane이 영영 바쁜 fixture에서 나가지 않은 요청을 session이 확정하는 데 기대고 있었습니다(바로 이번에 없앤 동작). 기대값은 그대로입니다.

Evidence

  • 확인한 것 (수정 전 실패): 새 core test 3개가 수정 전 코드에서 각 증상으로 실패하고 수정 후 통과합니다.
    • view_authority_a_pane_focus_that_has_not_left_is_not_confirmed_by_an_earlier_session: "the pane focus leaves after the tab focuses ahead of it"(수정 전 None).
    • view_authority_a_tab_focus_that_has_not_left_is_not_confirmed_by_herdr_s_own_move: "Herdr moving to w-order:t3 on its own is followed"(수정 전 t1에 남음).
    • view_authority_a_tab_focus_on_the_tab_herdr_shows_is_confirmed_by_its_answer: "Herdr's own move is followed at once, not after the deadline"(수정 전 t1에 남음).
  • 확인한 것 (재현): Flaky test: cycles: ⌃Tab and ⌥Tab commit once, on releasing the held modifier #629 web e2e probe(private hided와 Herdr, t2 click 직전 SIGSTOP, commit 뒤 SIGCONT) 12번: cycle 2 12/12 일치, Herdr가 받은 pane.focus는 12번 모두 2개(cycle 1과 2). #631만 있을 때는 12번 중 10번이 1개였습니다.
  • 확인한 것: main 위로 rebase 뒤 nextest -p herdr-core 1498개 통과(Read a pane focus's late tab move as its answer #612 test 2개, Remember a tab focus that leaves after its wait was replaced #631 test 포함), clippy -D warnings, fmt, off-lock reader 검사 통과.
  • 확인하지 못한 것: keys.spec.ts(desktop)는 로컬에서 돌리지 않습니다. 이 PR의 CI desktop lane으로 봅니다.

A session that arrived before a queued request left was read as its
answer: a queued pane focus was then never sent, leaving Herdr on another
tab, and a queued tab focus Herdr reached on its own left anyway and was
remembered as superseded, consuming Herdr's next real move to that tab.
A focus is now confirmed only once it has left, by a session that shows
it or, since Herdr publishes no event for focusing the tab it already
shows, by Herdr's success answer when the last session already shows it.

Refs #629
@yansfil
yansfil merged commit a136318 into main Oct 6, 2026
19 checks passed
@yansfil
yansfil deleted the fix/confirm-only-sent-focus branch October 6, 2026 10:55
yansfil added a commit that referenced this pull request Oct 6, 2026
…#667)

Closes #653
Related: #612, #631, #635 (같은 장치의 이전 수정, 이 PR이 대체)

## Summary

`view-bookmarks.spec.ts`의 Agent tab View 복원이 t2, t1, t2 빠른 클릭 뒤 화면을 t1에
남기는 문제입니다.
CI hided 로그(run 37508081360)의 순서는 `tab.focus.late_answer` ->
`tab.focus.confirmed_by_answer` -> `tab.focus.followed`였습니다.
첫 t2 클릭 시점의 session이 마지막 t2 요청의 확정으로 읽혔고, 그 뒤 도착한 t1, t2 이동이 Herdr 스스로의
이동으로 따라가졌습니다.
규칙을 하나 더 얹는 대신 checkout의 tab 권한을 "보낸 순서의 미답 tab 이동 목록"
하나(`tab_focus_requests`, `herdr-core/src/runtime/tab_focus.rs`)에서 유도하도록
바꿨습니다.

순서 보장의 근거:
- control lane은 Herdr가 앞 요청에 답한 뒤에만 다음 요청을 보냅니다. 그래서 Herdr는 보낸 순서대로
적용합니다.
- Herdr [Socket API](https://herdr.dev/docs/socket-api/), Event
subscriptions: "Lifecycle and agent-status events are drained in bounded
batches, in order within each subscription." 그래서 이동 event도 그 순서로 도착합니다.

모델:
- Herdr 이동(workspace에서 새로 active가 된 tab, 또는 새 focus event)은 그 tab의 가장 이른
요청에 대한 답입니다. 그보다 먼저 보낸 요청도 함께 빠집니다.
- 이미 그 tab에 있던 요청은 Herdr가 event를 내지 않습니다. 그래서 답이 오면 그 자리에서 끝납니다. "이미 있던
tab"은 같은 workspace의 바로 앞 요청이고, 앞 요청이 없으면 마지막으로 읽은 Herdr입니다.
- 확실한 거절은 즉시 빠집니다. 답이 유실되었거나 보고가 없는 요청은 3초 deadline까지 남습니다. 목록 상한은
16개이고, 넘치면 가장 오래된 요청을 내보내며 `tab.focus.request_evicted`를 남깁니다.
- checkout에 보냈거나 lane에서 기다리는 요청이 남아 있으면 Herdr 이동을 따라가지 않습니다.

지운 규칙(모두 위 목록이 같은 답을 유도함):
- #612 `await_pane_focus_tab` / `drop_pane_focus_tab_wait`: submit 전에 거는
pane focus의 tab 대기. 이제 pane focus가 lane을 떠날 때 그 tab이 목록에
들어가고(`send_pane_focus_tab`), 답이나 거절로 빠집니다.
- #631 `mark_tab_focus_sent`: lane을 떠날 때 superseded로 표시하기. 목록은 보낸 요청을 모두
순서대로 갖고 있어서 따로 표시할 필요가 없습니다.
- #635 보낸 요청만 session으로 확정하기, `confirm_tab_focus_already_shown`:
session만으로는 아무것도 확정하지 않습니다. 이것이 이번 결함의 원인이었습니다. "이미 보이는 tab" 확정은 앞 요청이나
마지막 Herdr에서 유도합니다(`settle_where_herdr_already_was`).
- `superseded_tab_focus` 목록과 같은 tab 중복 제거(`retain`): 같은 tab 요청이 둘이면 이른
것이 먼저 답을 받습니다. 중복 제거가 그 순서를 지웠습니다.
- `pending_tab_focus` 슬롯, `PendingViewFocus`의 `scope_id`/`already_sent`,
`await_tab_focus`, `supersede_tab_focus`, `agent_areas`와 events의 pending
비우기. pane focus 슬롯(`pending_pane_focus`)은 pane 확정용으로 남깁니다.

## Review

- **조심해서 볼 파일**:
- `herdr-core/src/runtime/tab_focus.rs`: 새 모델 전체. runtime mutex 안에서 도는
작업이며 목록 상한은 16입니다.
- `herdr-core/src/runtime/session.rs` `reconcile_visible_tabs`:
Herdr/core ownership 경계입니다. 따라갈지, 답으로 읽을지를 여기서 정합니다.
- `herdr-core/src/runtime/control_lane.rs`: lane을 떠나는 시점(`start_job`)과
보내지 않은 claim을 되돌리는 시점입니다.
- `herdr-core/src/runtime/terminal.rs`: pane focus 답과 거절이 목록에 닿는 failure
path입니다.
- **비용 검토**:
- session 하나당 추가 작업은 active tab 집합과 지난 집합의 비교, 그리고 16개 이하 목록 순회입니다.
subprocess, I/O, 직렬화는 없습니다.
  - 새 timer, timeout, sleep은 없습니다. 3초 deadline과 16 상한은 그대로입니다.
- **질문**: ARCHITECTURE의 역사 문장은 이슈 번호(#413, #594, #629, #635)로 적었습니다. PR
번호로 바꿀지 판단해 주세요.

## Evidence

- **확인한 것**:
- 결정적 재현:
`view_authority_a_session_from_before_an_earlier_request_does_not_answer_a_later_one`은
수정 전 main에서 실패했습니다(left t2, right t1). 로그 순서 late_answer ->
confirmed_by_answer -> followed가 CI와 같았습니다. 수정 후에는 통과합니다.
- 순서 표 test
`view_authority_the_screen_stays_on_the_last_request_whatever_order_herdr_answers_in`은
6행입니다: 정순, 접힌 burst, A-B-A 접힘, 보이는 tab 재focus(event 없음), 다음 요청이 기다리는 중의
거절, deadline. 각 행의 기대값은 "마지막으로 보낸 요청의 tab"입니다.
- 상한, 만료, 거절 test 이름을
`view_authority_sent_tab_moves_stop_claiming_their_tab_when_capped_expired_or_refused`로
바꿨습니다. 확실한 거절과 애매한 유실을 모두 다룹니다.
  - 로컬 herdr-core nextest 1551개, clippy `-D warnings`, fmt를 모두 통과했습니다.
- **확인하지 못한 것**:
- `web/e2e/view-bookmarks.spec.ts`는 로컬에서 돌리지 않았습니다. 디스크 여유가 부족해 hided를
다시 빌드할 수 없어서, CI web e2e에 맡깁니다.
- `scripts/check-runtime-gates.sh`의 `hide-platform --test watch` 1건 실패는
이 diff가 hide-platform을 건드리지 않아서 조사하지 않았습니다.
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