Skip to content

Take a closing tab out of its Agent area at once - #554

Merged
yansfil merged 5 commits into
mainfrom
close-hides-at-once
Oct 5, 2026
Merged

yansfil merged 5 commits into
mainfrom
close-hides-at-once

Conversation

@yansfil

@yansfil yansfil commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

탭을 닫으면 Herdr가 탭이 사라졌다고 확인할 때까지 칩이 closing…으로 남았습니다.
Claude Code pane은 Herdr가 SIGHUP 유예(~500 ms)를 기다리므로 닫기마다 최소 0.6초가 보였습니다.
이제 탭 닫기와 탭의 유일한 pane 닫기는 승인되는 순간 Agent 영역에서 칩을 빼고, Herdr 확인은 뒤에서 기다립니다.
거절되거나 실패하면 탭이 원래 자리로, 포커스도 원래 탭으로 돌아오고, 결과를 모르면 탭이 다시 보입니다.

칩이 사라지는 시간 (격리된 Herdr 0.9.1, 탭 6개 순서대로 닫기)
                      일반 셸      SIGHUP 무시 pane(Claude Code 유사)
설치본 769f34b8       84-93 ms     571-631 ms
이 PR (debug hided)   16-19 ms     12-17 ms

같이 바뀐 동작:

  • 닫힌 탭에 키보드가 있었으면 Herdr 순서의 첫 탭이 아니라 그 영역이 다음에 보여주는 탭으로 갑니다.
  • 그 이동은 클릭과 같은 tab focus로 Herdr에 알립니다. Herdr 0.9.1은 활성 탭을 닫으면 왼쪽 이웃으로 스스로 포커스를 옮기는데, 이 이동을 따라가지 않고 답으로 읽습니다.
  • 보고 있지 않은 탭을 닫으면 포커스가 움직이지 않습니다(이전엔 첫 탭으로 옮겨졌습니다).
  • 닫은 직후 ⌘⇧T: 닫기가 확인 중이어도 받아 두었다가 확인되면 다시 엽니다. 이전엔 칩이 남아 있어 드러나지 않던 거절입니다.
  • 그대로 closing…을 유지: 분할된 탭 안의 pane 하나, 대체 셸이 필요한 primary 마지막 탭, SSH 기기 탭, 사이드바 agent 행.

Review

  • 판단해 주세요: 닫은 뒤 포커스가 같은 영역의 "최근 포커스 순, 없으면 오른쪽" 탭으로 갑니다(기존 영역 규칙 B10). Herdr는 왼쪽 이웃을 고릅니다. 이 선택이 맞는지.
  • 판단해 주세요: 닫기 확인 중 누른 ⌘⇧T를 버리지 않고 대기시킵니다. 확인까지 탭이 0.5초쯤 늦게 다시 열립니다.
  • 조심해서 볼 파일:
    • herdr-core/src/runtime/agent_areas.rs shown_agent_layout - high-frequency path: 스냅샷 읽기마다 실행. 닫기가 없으면 복제 없음, 있을 때만 64개 이하 layout 복제 1회.
    • herdr-core/src/runtime/editor.rs move_from_closing_target, restore_close_selection - Herdr/core ownership: 닫기 안에서 FocusTab 이벤트를 적용합니다.
    • herdr-core/src/runtime/editor.rs reopen_closed, release_queued_reopen - failure path: 대기 중 reopen이 오래된 항목에 닿지 않게 하는 조건들.
  • 비용 검토: 새 상주 작업이나 cap 없음. 대기 reopen은 Option<String> 하나이고 다음 닫기·거절·실패에서 비워집니다.

Evidence

  • 확인한 것:
    • herdr-core 1428개, hided 180개 테스트 통과(verify-cargo.sh test-scoped), fmt와 clippy -D warnings 통과.
    • 새 런타임 테스트 6개(runtime::tests::agent_areas): 즉시 숨김과 거절 시 복귀, Herdr의 자체 포커스 이동 무시, 백그라운드 닫기, 대체 셸 유지, reopen 대기와 거절 시 폐기.
    • 결함 6종을 심어 각각 위 테스트가 실패하는 것을 확인(필터 끄기, Herdr 미통지, Herdr 순서 선택, 대체 셸 숨김, reopen 대기 없음, 거절에도 reopen 실행).
    • 닫기 관련 web e2e 6개 spec(s2, close-policy, agent-close-contract, close-subtree, agent-tab-groups, sidebar-menus) 38개 중 37개 통과.
    • 실패한 1개는 load average 43에서 hided 시작 5초 제한에 걸린 fixture 실패였고, 그 spec만 다시 두 번 돌려 3/3 통과.
    • Herdr 0.9.1 닫기 후 포커스: 격리 서버에서 탭 5개로 측정(활성 t3 닫기 -> t2, 첫 탭 t1 -> t2, 마지막 t5 -> t4, 백그라운드 t4 -> 유지).
    • 타이밍 표: 설치본과 이 브랜치를 같은 spec, 같은 Herdr로 headless Chromium에서 측정. 닫은 뒤 2초 동안 선택 탭이 다시 바뀌는 일 없음.
  • 확인하지 못한 것:
    • 데스크톱 앱 창에서의 실제 화면, release 빌드 수치(측정은 debug hided).
    • 백그라운드 탭 닫기가 이전에 포커스를 옮기던 것은 코드로 확인했고 설치본에서 재현하지는 않았습니다.
    • 전체 web/desktop e2e는 CI에 맡깁니다.

A tab close kept its chip in the strip, marked closing, until Herdr
confirmed the tab gone, which is at least half a second for a pane whose
process waits out SIGHUP (every Claude Code pane) and longer on a loaded
machine.

The Agent areas now publish and attach the stored layout less every tab
a running close removes whole (a tab close, or its only pane's), so the
chip leaves on the event that asked for it. The stored layout keeps the
tab, so a refusal, failure or unknown result puts it back where it
stood. A close that first opens a replacement shell keeps its tab until
Herdr confirms, so the area never stands empty.

When the closing tab holds the keyboard, the operator moves to what the
area now shows instead of the next tab in Herdr's order, through the
same tab focus a click sends. Herdr 0.9.1 focuses the closed tab's left
neighbour on its own; with Hide's focus pending, that move is read as
its answer instead of being followed, which used to move the screen a
second time after the close. Closing a tab in the background no longer
moves the operator, and a failed capture restores the selection as a
refusal does.
With the closed tab gone from the screen at once, Reopen Closed Tab
pressed right after a mistaken close reached the core before Herdr
confirmed the close, and the core refused it as "still being confirmed"
(the shell did not even send it, since can_reopen was false).

The core now offers reopen while this machine's newest close is
settling and holds the request until that close is promoted with a
captured item, then runs it. A refused or failed close, a close with
no captured item, a newer close, or another device in front drops it,
so it never reaches an older item on the stack. An unknown result keeps
it waiting for the status check.
@yansfil
yansfil merged commit 9d5072f into main Oct 5, 2026
78 of 82 checks passed
@yansfil
yansfil deleted the close-hides-at-once branch October 5, 2026 21:00
yansfil added a commit that referenced this pull request Oct 6, 2026
… keyboard tab (#600)

Refs #425
Related: #554

## Summary

`agent-tab-groups.spec.ts` "New tab and Reopen use the requested area"가
Reopen 직후 왼쪽 영역의 복원 탭 대신 오른쪽 영역 탭을 보여 주던 제품 원인을 고칩니다(`:285`).
#554의 회귀입니다: 이 실패 모양은 #554 PR 자신의 CI run(2026-10-05 18:31Z)에서 처음 나왔고,
#554가 머지된 뒤 세 번 더 나왔습니다.

- 원인: Reopen은 Herdr에서 `workspace.create`로 seed 탭(`w3:t1`)을 만들고
`layout.apply`로 그 탭을 복원 탭(`w3:t2`)으로 바꿉니다.
seed 탭의 이벤트는 Reopen의 답보다 늦게 도착할 수 있고, 그때 기다리는 알림이 없으므로 core는 seed 탭
focus를 Herdr의 이동으로 따라갑니다(`tab.focus.followed`).
seed가 사라지면 선택된 pane `w3:p1`이 은퇴하는데, 그 대체가 Herdr의 keyboard가 있던 다른 Agent
영역의 pane(`w1:p3`)을 골랐고, `tab.visible_aligned`가 화면을 `w3:t2`에서 `w1:t2`로
옮겼습니다.
- 수정: 은퇴한 선택의 대체 순서를 "선택이 있던 탭 -> 같은 session pass가 checkout에 보여 주기로 한 탭
-> Herdr의 keyboard 위치 -> 첫 pane"으로 바꿨습니다. 시간 조건은 없고 그 pass의 상태만 봅니다.
  같은 pass에서 Herdr의 이동을 따라갔다면 보이는 탭이 이미 Herdr의 탭이므로, 따라가기의 결과는 그대로입니다.

```
수정 전 hided log (CI run 37399148855, 로컬 실패 8건 모두 같은 순서)
tab.focus.followed      w1:t2 -> w3:t1 origin=herdr
pane.selection_retired  Retired pane w3:p1; selected w1:p3
tab.visible_aligned     w3:t2 -> w1:t2
```

## Review

- **판단해 주세요**: 대체 후보를 Herdr keyboard 앞에 하나 더 둔 것이
`docs/ARCHITECTURE.md`의 따라가기와 대기 중 알림 규칙과 맞는지 봐 주세요.
- 대기 중 알림이 있으면 Herdr의 이동은 확인으로 읽힙니다: 바꾸지 않았습니다. 보이는 탭은 여전히
`reconcile_visible_tabs`가 정하고, 이 수정은 그 결과를 읽기만 합니다.
- 대기 중 알림이 없으면 Herdr의 이동을 따라가고 diagnostic을 남깁니다: 바꾸지 않았습니다. 새 test도 seed
focus가 따라가졌다는 것을 먼저 확인합니다.
- "focused checkout은 선택된 pane을 가진 탭을 그린다"(retirement는 탭을 pane으로 옮김):
그대로이고, 은퇴 대체를 고르는 순서만 바뀝니다. 이 순서를 같은 문단에 적었습니다.
- **조심해서 볼 파일**:
- `herdr-core/src/runtime/session.rs` - runtime mutex 안. 은퇴가 있을 때만 map
조회 1번과 그 pass의 layout 목록 탐색 1번이 늘고, subprocess나 I/O는 없습니다.
- 같은 파일 - Herdr contract. 새 Herdr 호출은 없습니다. 은퇴 뒤 Herdr에 알리는 탭이 다른 영역 탭에서
복원 탭으로 바뀝니다.
- 같은 파일 - failure path. 보이는 탭이 그 pass의 layout에 없거나 그 focused pane이
checkout pane이 아니면 기존 순서(Herdr keyboard, 첫 pane)로 내려갑니다.

## Evidence

- **확인한 것**:
- 새 core test
`a_followed_reopen_seed_that_goes_leaves_the_operator_on_the_restored_tab`:
FakeHerdr로 Reopen 답 -> seed 생성과 focus(따라가짐 확인) -> seed가 사라지고 복원 탭 도착 +
Herdr keyboard는 오른쪽 영역 순서를 재현합니다.
수정 전에는 checkout 활성 탭이 `t2`(기대 `t4`)로 실패하고 hided와 같은
`pane.selection_retired`, `tab.visible_aligned`를 남깁니다. 수정 후 통과.
- e2e `agent-tab-groups.spec.ts` 전체를 `--repeat-each=40 --workers=8
--retries=0`, `yes` 4개 부하에서 같은 base로 비교:
수정 전 8/40 실패(`:285`, 실패 8건의 hided log 모두 위 순서), 수정 후 480/480 통과. 같은 조건
`--repeat-each=30` 360/360, 해당 test만 40/40.
- herdr-core 전체 1474/1475. 실패 1개는
`editor_preview::file_and_diff_previews_share_one_slot`로 이 변경과 무관하고 단독
3/3 통과했습니다.
  - `cargo fmt --check` 통과.
- **확인하지 못한 것**:
- 수정 후 처음 돌린 부하 없는 `--repeat-each=20` 한 번에서 `:285` 실패가 1건(239/240) 있었고,
log를 남기지 않아 원인을 확인하지 못했습니다. 그 뒤 수정 후 run 880번(부하 포함)에서는 다시 나오지 않았습니다.
- 로컬 측정은 #589와 #574가 들어오기 전 main(ca0a994) 위에서 했습니다. 이 브랜치는 그 위로
rebase했고 두 PR은 이 경로를 건드리지 않습니다. rebase 뒤 build와 test는 CI가 확인합니다(기기 디스크 7
GiB로 로컬 build 하한 아래).
  - 로컬 clippy는 같은 이유로 돌리지 않았습니다.
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