Skip to content

Keep typing in the clicked Agent area after an edge drag - #414

Merged
yansfil merged 4 commits into
mainfrom
fix/edge-drag-input-target
Oct 4, 2026
Merged

yansfil merged 4 commits into
mainfrom
fix/edge-drag-input-target

Conversation

@yansfil

@yansfil yansfil commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #413
Refs #303, #400

Summary

Agent 탭을 새 영역으로 드롭한 직후 첫 영역을 클릭해 입력하면, 입력한 줄의 일부가 다른 영역의 pane으로 갔습니다.
CI에서 desktop-group-live가 desktop-grouve로 실행된 실패(agent-tab-groups.spec.ts:40)가 이 결함입니다.
원인은 core에 있었습니다. 드롭이 보낸 tab.focus t2에 대한 Herdr의 답이 클릭(tab.focus t1) 뒤에 도착했는데, core가 이를 외부 focus로 보고 따라갔습니다(tab.focus.followed). 그 결과 snapshot의 keyboard pane이 바뀌었고, PaneView가 입력 도중 DOM focus를 옮겼습니다.
이제 core는 더 새 요청으로 대체됐지만 Herdr가 아직 답하지 않은 탭 focus 요청을 기억합니다(superseded_tab_focus, 최대 16개, 3초). Herdr가 그런 탭으로 이동했다고 알리면 그 요청의 늦은 답으로 소비하고, 따라가지 않습니다.

수정 전, 실패한 실행 (렌더러 시각, ms)
324 p1 focused   358 p3 focused  -> 'p' '-' 가 p3로 전송
364 p1 focused   374 p3 focused   378 p1 focused
p1: printf 'desktogroup-live\n'    p3 프롬프트: p-

Review

  • 판단해 주세요: Hide가 대체한 탭 요청은 3초 동안 그 탭에 대한 권리를 가집니다. 그 사이 Herdr 밖에서 같은 탭으로 진짜 이동해도 한 번은 따라가지 않습니다. 대신 이 일은 tab.focus.late_answer로 기록됩니다.
  • 판단해 주세요: desktop/e2e/terminal-input-observation.ts(Observe terminal input and announce Windows fixture readiness #372)를 지웠습니다. 이 관측기는 페이지가 shell로 이동하기 전에 설치돼서 아무것도 기록하지 못했고(renderer-unavailable), 쓰는 곳은 이 테스트뿐이었습니다.
  • 조심해서 볼 파일: herdr-core/src/runtime/session.rs reconcile_visible_tabs - Herdr/core ownership. 외부 focus를 따라갈지 정하는 분기를 하나 추가했습니다.
  • 조심해서 볼 파일: 같은 파일의 FocusTab 실패 처리 - failure path. 확정된 거절이면 기록을 지우고, 결과를 알 수 없으면(ambiguous) Herdr가 적용했을 수 있으니 만료까지 유지합니다.
  • 비용 검토: 탭 전환 이벤트마다 상한 16개인 Vec에 push/retain을 한 번씩 하고, session reconcile마다 checkout당 한 번 선형 검색합니다. 만료는 기존 view-focus 만료 경로에서 처리하고, 상한을 넘기면 진단 로그를 남깁니다.

Evidence

  • 확인한 것: 결정적 core 테스트 view_authority_a_late_answer_to_a_superseded_switch_is_not_followed는 수정 전 CI와 같은 방식(t2로 이동)으로 실패하고, 수정 후 통과합니다.
  • 확인한 것: 상한, 만료, 확정된 거절, ambiguous 실패를 검사하는 테스트를 추가했고 통과합니다. main 59d13d9 위로 rebase한 뒤 herdr-core 전체 1370개 통과, verify-cargo.sh lint 통과, desktop typecheck/lint 통과.
  • 확인한 것: 로컬 macOS에서 debug hided와 pinned Herdr 0.9.1로, 14코어 중 4개에 부하를 걸고 원래 테스트 흐름을 반복했습니다. 수정 전 8회 중 1회 실패, 수정 후 16회 모두 통과.
  • 확인한 것: 수정 후 16회에서 늦은 답은 7회 발생해 모두 따라가지 않았고, keyboard pane은 클릭마다 정확히 한 번만 바뀌었습니다.
  • 확인한 것: 원래 테스트를 retry 0, 기존 deadline으로 통과했습니다. 두 그룹 각각 출력 줄이 정확히 한 번인지 검사하는 단계를 추가했습니다.
  • 확인하지 못한 것: Linux와 Windows desktop, 그리고 CI의 전체 background suite 뒤 실행은 이 PR의 CI 결과로 확인합니다. 이 테스트는 PR A(Quarantine the repeated main failures and keep the original Windows fixture error #398)에서 격리되지 않았으므로 해제할 격리가 없습니다.
  • 확인하지 못한 것: 새 탭을 연달아 두 번 만들면 탭 하나가 유실된다 #400(새 탭 유실)의 실패 로그에도 오래된 focus를 Herdr 이동처럼 따라가는 단계가 있어서 Refs로 연결했습니다. 이 수정이 #400을 고치는지는 별도 비교로 확인합니다.
  • 확인하지 못한 것: 탭 focus 요청은 요청마다 스레드 하나로 나가므로, Herdr가 순서를 바꿔 적용하면 Hide와 Herdr의 active 탭이 만료 전까지 어긋날 수 있습니다(코드에서 추론). pane focus처럼 직렬화하는 것은 후속 작업입니다.
추가 증거
  • 로컬 재현의 사건 순서: Herdr tab.focus t2(드롭) 02.084, tab.focus t1(클릭) 02.158. core tab.focus.followed t1→t2 02.195, t2→t1 02.298.
  • core 테스트 중 repository_clone 1건이 전체 suite 부하에서 한 번 실패했습니다. fixture의 git commit 단계였고, 단독 실행과 재실행에서는 통과했습니다. 이 변경과는 무관합니다.

A tab focus the operator replaced before Herdr answered it is now
remembered as superseded. A session from before both requests can
confirm the newer one, and Herdr's answer to the older one then names a
tab Hide has left; following it as an outside move put the keyboard in
the other Agent area in the middle of typed input.
The renderer input observer installed before the page left the status
page, so it never recorded anything; the cause it was added to find is
now fixed and covered by a core test, so it goes.
A refused superseded request is dropped, but one whose answer was lost
may still have been applied by Herdr, so it keeps its claim until it
expires. The late-answer record is written only where the answer would
have been followed, and the cap, expiry and refusal are tested.
@yansfil
yansfil merged commit 079b6f2 into main Oct 4, 2026
28 checks passed
@yansfil
yansfil deleted the fix/edge-drag-input-target branch October 4, 2026 23:18
yansfil added a commit that referenced this pull request Oct 5, 2026
Related: follows #420 (merged); R1 of the control-order split. Issues
whose cause this removes are listed under Review.

## Summary

Hide sent each local Herdr tab control (focus, create, move, rename) and
each pane focus from a thread of its own, so controls sent moments apart
reached Herdr in either order and the screen followed the wrong one.
They now travel one ordered lane in the core
(`runtime/control_lane.rs`): one socket operation at a time, the rest in
arrival order, at most 16 waiting.
Each request is queued, in flight, superseded or settled: a queued focus
is replaced without leaving a late answer, a replaced in-flight one is
Hide's own late answer, and a lost answer holds back what could be
overwritten by it.
This includes the #414 follow-up: tab focus is serialized like pane
focus.

Before the change, three rapid tab clicks sent Herdr `t2, t3, t1`; they
now send `t2, t1`, the second only after the first was answered.

## Review

- **판단해 주세요**: a lost tab or pane focus answer drops both the queued tab
focus and the queued pane focus (`tab.focus.unknown`,
`pane.focus_unknown`); the next click starts a new request.
- **조심해서 볼 파일**:
- `herdr-core/src/runtime/control_lane.rs` - ownership of the lane;
every exit path of a job (spawn failure, skipped start, lost answer) has
to release what the start marked as sent.
- `herdr-core/src/live.rs` (`spawn_control_lane`) - the one worker per
busy lane; it carries the next job under the runtime lock and does the
socket work outside it.
- `herdr-core/src/runtime/session.rs` - a local tab move carries no
deadline while it waits; `start_job` arms the 5 s wait when it leaves
and does not send a move that is stale or no longer transmitting.
- `docs/ARCHITECTURE.md` - the pending rules (queued, in flight,
superseded, settled) are rewritten with the code.
- **비용 검토**: no work is added per input on the lock; the lane is capped
at 16 and a request past it is refused where it was asked
(`control.lane_full`); one worker thread runs only while the lane is
busy and ends when it drains.
- **H2: the 12 "chord right after a pane click" sites (5 `close_tab`
files)** are a test-ordering assumption, not a product race, judged from
the code and not run on CI.
`closeFocused` and `newTabFocused` read the page-local keyboard owner,
which a click sets synchronously, and `close_pane` names the pane by id,
so a chord after a click does not wait on a core round trip to choose
its target.
The real product race behind `new-tab:72` and its relatives was the
created tab's placement against Herdr's events and a later click, which
the lane and #420 close.
The `toPass` retry in `close-subtree.spec.ts:133` hides the ordering
rather than needing it; PR 2 handles those specs.
- **Worker panic**: a panic inside a socket call settles the job as an
unknown result (`control.worker_panicked`), so the lane cannot stay busy
behind a dead worker.
- **CI failures that are not the lane**: `s6.spec.ts:157` read the
node-side `last` map synchronously after a key press; the page's
`views:true` send was logged in the same millisecond, so the spec now
polls (fixed here).
`s2.spec.ts:55` (macOS: pane count 2 vs 3; Windows: `data-zoomed` stayed
`true`) is the existing flaky #424: both runs show the core's update
arriving 4.3 to 4.7 s after the control was sent (`close_pane` 31.947 to
36.27; `toggle_zoom` 53.387 to 58.08), past the 5 s expect.
Core tests show close, zoom and resize start while the lane is busy and
are not queued behind it
(`a_pane_close_starts_while_an_unanswered_tab_focus_holds_the_lane`,
`a_zoom_and_resize_in_other_tabs_start_while_an_unanswered_pane_focus_holds_the_lane`).
The delay itself is handled in its own PR
(`fix/focus-readback-blocks-ingest`).
- **Closing the quarantine issues**: this PR changes the ordering the
targets depend on but removes no `@flaky` tag.
`new-tab:72`, `agent-tab-groups:159/:247` and `keys:116` (quarantined by
`ci/quarantine-batch-2`) can be closed once the Linux and Windows
`verify` runs of the PR that removes their tags pass on two consecutive
main runs.
`agent-close-contract:13` (#231), `agent-tab-groups:216` (#287) and
`sidebar-menus:80` (#308) are split and un-tagged in the follow-up PR
with the same condition.

## Evidence

- **확인한 것**:
- 19 deterministic core tests in
`herdr-core/src/runtime/tests/control_order.rs`, where the test decides
Herdr's answer order through `FakeHerdr`: late answer, superseded
(replaced before sent and after), refused and unknown result for tab
focus, create and pane focus, plus the cap, join order and stale move.
- With the lane reverted, the rapid-focus test fails (`["t2","t3","t1"]`
against `["t2","t1"]`).
- `scripts/verify-cargo.sh test-scoped -p herdr-core`: 1412 passed;
`fmt-check` and `clippy -D warnings` clean.
- Web e2e on macOS against the pinned Herdr 0.9.1, 2 repeats each:
`pane-focus-ordering`, `new-tab`, `agent-close-contract`,
`agent-tab-groups`, `sidebar-menus` - 20 passed.
- The shared gate (`web/e2e/herdr-gate.ts`) holds any Herdr method;
`pane-focus-ordering.spec.ts` uses it as the one representative journey,
and ordering rules moved to the core tests.
- **확인하지 못한 것**:
  - Linux and Windows runs; no CI result for this head yet.
  - `desktop/e2e/keys.spec.ts:116` was not run locally.
- The H2 classification is from reading the code, not from a failing
run.
- Known gaps left as follow-ups: a lost focus answer leaves
`last_view_intent_serial` at a dropped focus (a created tab can be held
back with a stale `tab.create.focus_superseded` note), and
`ingest_pane_focus_completion` ignores a `Full` refusal when it
re-queues a turn.
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.

Typing after an Agent edge drag goes partly to the other area's pane

1 participant