Skip to content

kicad: a KiCad left by a thread switch is out of the pane for the idle close and the cap (#1345, PR C) - #1470

Merged
i2cjak merged 17 commits into
mainfrom
fix/1345-leave-idle
Nov 21, 2026
Merged

i2cjak merged 17 commits into
mainfrom
fix/1345-leave-idle

Conversation

@i2cjak

@i2cjak i2cjak commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1345. This is the KiCad lead's PR C.

Cause. idle_victims and evict_warm treated a KiCad as "in no pane" only after editor.kicad.detach (container == 0 || parked). A thread switch keeps the pane entity and only flips KicadPane.in_page, and sent nothing. So a KiCad left that way was never idle-closed and never evicted.

Change

Client:

  • ui.rs: when the pane's in_page changes, it calls KicadPane::set_in_page(in_page, why).
    • why is "thread" for a thread other than the one where the pane was last on screen, the same project's included. It is "viewer" when the same thread's viewer was closed or moved to another page.
    • A Backplane sheet or dialog over the pane does not change in_page, so it is not a leave.
  • LeaveState (pure, tested):
    • the leave goes to the hub only after 300 ms off screen (LEAVE_SETTLE), and only once;
    • the back goes at once, and only after a leave was sent;
    • a quick away-and-back sends nothing.
  • The message is editor.kicad.leave {project, left, why, generation}. It is a plain try_send: no keyboard, no window call, nothing that waits on KiCad's UI thread (Windows: KiCad windows' placements run off Backplane's UI thread, so a tab switch during KiCad's DRC no longer freezes Backplane (#1343) #1401/Windows: 243 ms SetFocus on the UI thread during a cold KiCad construction (follow-up to #1343) #1403).
  • kicad_info: if KiCad is closed as idle while the pane is off screen (closed_idle_away), the pane goes as a View does. Coming back shows Backplane's viewer, not a dead pane.
    • main has no automatic attach on return (kicad_attach is only driven by scripts), so the viewer is what the person gets.
    • A person-closed KiCad (closedByPerson) keeps its own path.

Hub (kicad/embed.rs):

  • New field Session.left (the reason; empty while on screen).
  • out_of_pane means detached, or parked, or left with no dialog of KiCad's up. It feeds both idle_victims and evict_warm. Unsaved work stays exempt, as before.
  • Only the holder's leave counts (leave_counts: the caller's cid must be the pane's pane_cid). A leave from any other connection is answered and changes nothing.
  • A leave with a stale generation is answered stale and changes nothing (kicad pane + hub: an automatic attach carries its session's generation; the person's close holds it off (default flip, PR B) #1435's rule, extended to editor.kicad.leave).
  • A second leave never restarts the idle clock (Session::leave, tested).
  • attach, detach and stop clear left.
  • If the holder's connection is gone for 15 s (HOLDER_GONE_S: a crash or the network), the KiCad counts as left (holderGone). It does not stay held in a pane nobody shows.
  • Use is not idle (note_use, run each tick and before the cap picks a victim). touched_at is now the last use:
    • an agent's or a panel's request to that KiCad (a named gui_call_in client, at its start and end);
    • a job of KiCad's running (ET_PROGRESS: DRC, zone fill, plot; progress::has_jobs);
    • besides attach, show and warm-Have as before.
    • Follow's own reads are unnamed and don't count; the agent requests it follows do.
  • The cap evicts the least recently used KiCad first. It never evicts one with a dialog up or unsaved work (tested).
  • The idle-close log line now gives the reason, e.g. idle, closing … (left the pane: thread, unused for 300 s).
  • retire and the close path are unchanged; only eligibility changed.
  • The idle time is still 300 s. Only the existing BACKPLANE_KICAD_IDLE_S test variable changes it.
  • editor.kicad.leave is added to METHODS. No generated catalogs or bindings list the editor.kicad.* methods.

Use is not idle, for every KiCad (a finding). Before this PR nothing an agent or a panel sent to an open KiCad, and no KiCad job (DRC, zone fill, plot), counted as use: touched_at moved only on attach, show, warm-Have, detach and park, so a detached KiCad an agent was working in could be idle-closed under it. note_use makes those count for every live session, detached and parked included, not only left ones: a detached KiCad an agent keeps calling never idles out. That is intended.

left is not in viewer.runtime. leave() does not publish the session and nothing on the client reads left. Carrying it (say, for the right-rail tiles to show a KiCad as "left, warm") would need a publish on each leave and back; that is a small follow-up if the tiles want it, not part of this PR.

Same project, two threads. A second thread of the same project whose viewer is on a design page shows the editor too: the KiCad is on screen there, so no leave is sent, as intended. The leave comes when the last page showing it goes (e2e L6).

The always-on kicad_leave log line (the pane's others are behind BACKPLANE_KICAD_DEBUG): at most one line per leave and one per back, and it is what the e2e counts; the code says so.

Functions touched

  • ui.rs: the in_page block in render.
  • kicad_pane.rs: new set_in_page, send_leave, LeaveState, closed_idle_away; a few lines in kicad_info.
  • embed.rs: Session (new/detached/ended/leave), out_of_pane, leave_counts, last_use, idle_victims, evict_warm, attach (clears left), detach (clears left), new leave/note_use/note_holders, the Tick, METHODS, the RPC dispatch.
  • progress.rs: has_jobs.
  • Nothing on the placement or first-show path: KicadPane::detach, show_settled and native_child.rs are untouched.

Tests

  • Hub unit tests:
    • a_kicad_left_by_a_thread_switch_closes_as_idle_but_not_with_a_dialog_or_unsaved_work
    • only_the_holders_leave_counts
    • a_kicad_in_use_is_not_idle_left_or_not
    • the_cap_evicts_the_left_kicad_used_longest_ago_never_one_with_a_dialog_or_unsaved_work
  • Client unit tests:
    • a_pane_off_screen_is_told_to_the_hub_once_settled_and_back_at_once
    • a_kicad_closed_as_idle_while_away_gives_the_viewer_back
  • cargo test --all-targets in native/host with its own CARGO_TARGET_DIR: 4037 passed, 1 failed.
    • The failure is kicad::install::tests::a_stopped_download_is_kept_said_and_continued: a curl download fixture, untouched here. It passed 3 of 3 alone.
  • The client's cargo test --bin backplane-gpui: 867 passed.
  • scripts/windows-check.sh all (hub and client, x86_64-pc-windows-gnu): clean.
  • Mac mini (hs-mac-mini, aarch64, rustc 1.96.0), head 17c112c: cargo check --release --features cef of native/gpui under mac-heavy finished clean. Built in one folder, ~/bp-1345, deleted afterwards. scripts/mac-build.sh does not copy native/winres.rs or the hub files the client includes (host/src/{mouse,scopeprobe,bots/cat}.rs); I copied them by hand. That gap is on main, not in this PR.

Linux e2e (test/kicad_embed/embed_leave_idle_e2e.sh, fork, bp.13.1, BACKPLANE_KICAD_IDLE_S=20): single runs on the desktop under kicad-embed-e2e, load checked.

Row Branch main 2b6f530
L2 away 6 s and back: same pid, exactly 1 leave + 1 back, 0 for a quick away-and-back PASS FAIL (0/0)
L4 away while an agent reads that KiCad every ~5 s past the idle time: same pid PASS PASS (main never closes it)
L1 then unused past the idle time: idle-closed, hub log says left the pane: thread PASS FAIL (still running)
L5 back after the idle close: the viewer, no pane, no error notice PASS FAIL
L3 unsaved agent track, the viewer on Files (a leave), past the idle time: same pid, leave heard PASS FAIL (no leave)

L4 and L3 are guards: main keeps those KiCads too.

L4's "a job in progress at the idle time" is covered by the last_use unit test, not the e2e: a DRC on the seed board ends in about 0.2 s, too quickly to stage at the tick.

Windows (Carbon, bp-win under bp-win-ui) and macOS (Lane M) rows are to be scheduled by the Integrator on the head SHA.

🤖 Generated with Claude Code

Head 9e3f5eb (rebased on main a44963a, after the bp.13.3 pin). Changes from 17c112c:

  • A default-idle unit test (on_the_default_idle_time_a_kicad_used_10_s_ago_is_kept_and_one_unused_301_s_is_closed).
  • e2e row L6.
  • The always-on log line's comment.
  • From Carbon's Windows rows: on Windows KiCad closes its frames (ET_FRAME_CLOSED) before it exits, so the viewer came back through PaneFrameClosed, which also set the person-closed hold. A frame closed while the pane is off screen is now taken as the idle close, with no hold. Both paths log kicad_idle_closed_away with by ("stopped" on Linux, "frames closed" on Windows).

Checks on 9e3f5eb:

  • Hub cargo test --all-targets (own target dir): 4051 passed, 0 failed (bin), and every other target passed.
  • Client tests: 872 passed.
  • windows-check.sh all: clean.
  • Linux e2e, run 7 (single run under kicad-embed-e2e): 9/9 passed, L1–L6 included; L5 by "stopped".

Not changed here: on Windows, a KiCad slow to exit after the hub's Close stays "ready" until its process ends, and an Edit in between attaches to it. attach does not look at closing. That is on main already (any Close, idle or the person's, followed by Edit before exit), and it is the close path, which this PR leaves alone.

Head 7e54879 (rebased on main ef145cd): an attach never reuses a KiCad that is closing (finding 1, the Lead's narrow form).

  • Carbon's Windows r1, and main's own r2: after the hub's idle Close, KiCad dropped its API but its process lived on, in r1 for 2.5 min (main's r2 was still alive at the run's end). The next Edit attached to it. The same happened here on Linux under load (run 8).
  • attach on a session that is closing while "ready" or "unresponsive" answers closing and changes nothing (closing_not_reused). That covers the hub's Close (idle, the cap, the person's, an agent's) and a runtime move. A restart's placeholder is joined as before.
  • The pane then says "KiCad is closing. The editor opens again once it has closed." (gpui.c.kicad.closing, en/es/ja). It maps nothing of the old KiCad, and attaches again once the picture no longer has that process live, which starts a fresh KiCad.
  • retire now publishes closing, and a pane that is off screen when its KiCad starts closing goes at once (closing_away). Coming back shows the viewer, never a pane on a KiCad still ending.
  • No kill, no time bound, and no change to how a close is recorded.
  • The gap, as it stands since d5582bb: for the hub's own idle and eviction closes, a KiCad still running 15 s after the Close is ended (see below), so the person waits on "KiCad is closing" for at most about 15 s plus a fresh start. Any other close (the person's or an agent's editor.kicad.close, the app quitting) is unchanged: if that KiCad doesn't exit, the pane says "KiCad is closing" until the old KiCad exits, which on Windows it sometimes doesn't, until the close-wait PR's hang kill. Nothing in the pane reaches it meanwhile. editor.kicad.restart would (it ends the old pid), but only the runtime update uses it today.
  • Tests:
    • hub: an_attach_never_reuses_a_kicad_that_is_closing (ready or unresponsive after our Close: not reused; stopped: a fresh start; a restart's placeholder: joined);
    • client: a_pane_waits_on_a_closing_kicad_until_its_process_is_gone;
    • e2e: test/kicad_embed/embed_closing_attach_e2e.sh. The slow exit is made with SIGSTOP at the idle close. C1: the Edit is answered closing, the pane says so, no second KiCad. C2: once the old KiCad ends, the pane attaches again and a fresh pid is on show. On main's build C1 and C2 fail; on this head both pass.

Checks on 7e54879:

  • Hub cargo test --all-targets: 4052 passed, 0 failed (bin), and every other target passed.
  • Client tests: 881 passed.
  • i18n-check: ok.
  • windows-check.sh all: clean.
  • e2e run 10 (L1–L6): 9/9.
  • e2e closing run 3: 5/5.

Head d5582bb: a bound on the hub's own idle and eviction closes (the KiCad lead's condition).

  • Why the existing 800 ms kill didn't end that KiCad: it isn't broken. It lives only in close() (editor.kicad.close, the person's or an agent's Close), after Close answers. retire() (idle, evicted, appClosed) sends Close and nothing else, so the idle path never had a kill.
  • The bound: for idle and evicted only, IDLE_CLOSE_BOUND (15 s) after the hub's Close, the same pid still running is checked again (bound_kill).
    • Still clean (nothing unsaved, no dialog up): killed, and logged "a hang after its idle close: pid N still running M ms after the hub's Close, killed". Its exit ends the session as a clean one does (stopped, idle reason kept), so the person's pending Edit starts a fresh KiCad.
    • Changed since (unsaved, or a dialog up): left alone, and logged with the reason.
  • Why this subset is safe: these closes are sent only to a KiCad that the eligibility rule found clean (nothing unsaved, no dialog of KiCad's up, in no pane), with CM_FAIL_IF_MODIFIED. The check runs again at the kill. A KiCad that is saving shows unsaved or a dialog, and is left.
  • Not changed: the person's or an agent's Close, the app quitting, a close with a save, and how any close is recorded (that is the close-wait PR's).
  • Only the person's own Edit waits on a closing KiCad and starts a fresh one. A pane Backplane opened by itself goes instead (waits_on_close), so nothing starts a KiCad by itself after a close.
  • Tests:
    • hub: a_kicad_still_running_at_the_bound_after_an_idle_close_is_ended_only_while_still_clean (clean: killed; unresponsive: killed; a dialog, or unsaved work: left; any other close: left; the exit afterwards gives stopped with the idle reason);
    • e2e embed_closing_attach_e2e.sh, where the frozen KiCad is never let go: C1 answered closing, the pane says so; C2 killed at 15000 ms and logged, a fresh KiCad on show (5/5);
    • embed_leave_idle run 11: 9/9.
  • Checks on d5582bb (rebased on main bca030b):
    • hub cargo test --all-targets: 4053 passed, 0 failed, and every other target passed;
    • client tests: 881 passed;
    • i18n-check: ok;
    • windows-check.sh all: clean.

Head 6a053a3 (rebased on main 02d4611; two conflicts in kicad_pane.rs with main's macOS 15 press change, both sides kept).

  • New since d5582bb: retire() now reads Close's answer. KiCad refusing it (an answer with a status: it became modified after it was chosen, or its task held it) clears closing. Before, every later Edit would have waited on a close that never came. No answer at all (a KiCad already going, or hung) is not a refusal, and the bound takes it. Test: a_refused_idle_close_ends_the_closing_but_no_answer_does_not.
  • Checks on 6a053a3:
    • hub cargo test --all-targets (own target dir): rc 0. 4057 passed, 0 failed (bin); every other target passed too.
    • client tests: 882 passed.
    • windows-check.sh all: rc 0.
    • i18n-check: ok.
    • e2e embed_closing_attach: 5/5. embed_leave_idle: 9/9.
  • Under the person's rule of Nov 20, Carbon's and Lane M's rows are release QA, not a merge condition.

Head 7708a5d: the cross-model review's findings (Fable), as the KiCad lead confirmed. Rebased on main.

  1. Two KiCads on one project. close() publishes the session stopped as soon as Close answers and kills 800 ms later, and the fresh-start path started the next KiCad at once.
    • Fix: a session keeps its last pid when it stops (last_pid, cleared by the real exit). The start path waits for that process to be gone (previous_alive, then gone_before_retry with restart's kill, Msg::AttachAfterGone) and never starts a second KiCad beside it. That also closes the window on main.
    • Test: a_fresh_start_waits_for_the_projects_previous_kicad_to_be_gone, with a real process as the previous KiCad.
  2. The bound's "not killed" left closing for ever. A KiCad that is no longer clean, has a dialog up, or is in use is now live again (Session::live_again, as for a refused Close), and isn't chosen again at the next tick. The app-gone close has the bound too.
    • Test: a_close_that_did_not_happen_leaves_the_kicad_live_and_not_closing.
  3. A waiting pane never saw a refusal. still_closing now reads closing too.
    • Test: a_pane_waits_on_a_closing_kicad_until_its_process_is_gone.
  4. Busy KiCads were fair game. busy (a named request in flight, or a KiCad job) keeps a KiCad from both the bound's kill and eviction.
    • Test: a_kicad_in_use_is_never_evicted_nor_ended_at_the_bound.
  • Also fixed: a re-attach while the pane is off screen (a reconnect) says the leave again (LeaveState::resend, tested).
  • Checks on 7708a5d:
    • hub cargo test --all-targets: rc 0. 4060 passed, 0 failed (bin); every other target passed.
    • client tests: rc 0, 884 passed.
    • windows-check.sh all: rc 0. The first try failed with "can't find crate for core" for windows-gnu while the toolchain was being updated under it; the rerun was clean.
    • i18n-check: ok.

Head 7716fc2: the delta review's three points (rebased on main de9296b; the struct's field line in kicad_pane.rs conflicted again, main's kept plus this PR's fields).

  1. A leave or a detach while a start waits on the previous KiCad is no longer lost. Deferred keeps it: a leave (or back) is applied once the held start has run, and a detach cancels the held start.
    • Test: a_leave_or_a_detach_while_a_start_waits_on_the_previous_kicad_is_kept_for_it.
  2. busy has a quiet window. It is now others_busy(sock, BUSY_QUIET_MS = 10 s), for eviction and the bound, because an agent's calls come one after another with gaps.
  3. AttachAfterGone forgets last_pid only when it is the pid it waited on (Session::waited_gone).
    • Test: a_held_start_clears_only_the_pid_it_waited_on.
  • Also from review point 6: RetryNow's "would not close" keeps the unkillable pid as last_pid, so the next start waits on it again.
  • Review point 4 (live_again wiping a person's closeAsked): not reachable in this PR, because the bound covers only the hub's own closes. Close-wait keeps the person's close reason.
  • Checks on 7716fc2:
    • hub cargo test --all-targets: 4062 passed, 0 failed (bin); every other target passed.
    • client tests: 885 passed.
    • windows-check.sh all: both finished clean.
    • i18n-check: ok.

Head 3a961b3: a start that waits on the project's previous KiCad is held as the session itself (the KiCad lead's shape, replacing Deferred). Rebased on main e3e2544.

  • The hold: when a fresh start finds the project's previous KiCad still there (previous_alive), the session is put in place at once as "starting" (HELD_REASON, a new generation, the attach's pane: held_session) and published. Everything after it takes the paths that already exist for a starting session:
  • The start: once the previous KiCad has ended (held_wait), the one real start runs from the held session's fields: its pane, holder, left and parked. Its waiters are finished when KiCad is ready.
  • It never kills the previous KiCad, which may be finishing a save or asking. After HELD_WAIT (15 s) the held session fails with "the KiCad before it is still closing (pid N, 15 s): it was not ended, as it may be saving or asking; try again once it has closed".
  • What the person sees: while held, the pane says "KiCad is closing…" (waits_previous). It ends one of two ways: KiCad starts and shows in the pane, or the pane says "KiCad could not start: the KiCad before it is still closing…" with Try again.
  • Tests:
    • a_start_held_for_the_previous_kicad_is_one_session_that_every_attach_joins
    • a_leave_or_a_detach_while_a_start_is_held_is_kept_by_its_session (includes the stale generation)
    • a_held_start_begins_once_the_previous_kicad_is_gone (a real process; nothing kills it)
    • the client's held text
  • Checks on 3a961b3:
    • hub cargo test --all-targets: 4067 passed, 0 failed (bin); every other target passed.
    • client tests: 885 passed.
    • i18n-check: ok.
    • windows-check.sh: the hub's test target fails to compile at settings/fab.rs:528 (E0034, custom_flags ambiguous). That line comes from main's e3e2544; this PR doesn't touch the file.

Head f7f9e00: the adversarial review's blocker, plus unanswered waiters.

  1. A leave or back is ordered by the pane's own number, not by the KiCad generation. A leave re-sent after a reattach carried the old session's generation and was answered stale, so the new KiCad counted as in the pane for good (the same across the held start's switch to the real one).
    • The holder check guards whose word it is. The client numbers every leave and back (seq, one count for the whole client), and the hub keeps the numbers per project and client across sessions (leave_in_order): a re-sent leave applies, and a leave older than a later back never wins.
    • Tests: a_leave_resent_after_a_reattach_under_a_new_generation_applies, a_late_leave_never_marks_a_pane_left_that_is_back_on_screen.
  2. An early return in the real start answers its waiters and publishes a final picture. This covers KiCad's program not found, the macOS refusal and Windows stock.
  • Left for the close-wait PR, as the lead allowed:
    • last_pid across a generation move (a reused pid's 15 s hold);
    • the held start's stale-lock sweep.
  • Known, minor:
    • an app-gone retire of a held session is a no-op (it starts, then idles);
    • the detach-then-attach of a held start runs with client 0 (attach_clients is not refreshed for it).
  • Checks on f7f9e00:
    • hub cargo test --all-targets: 4069 passed, 0 failed (bin); every other target passed.
    • client tests: 885 passed.
    • i18n-check: ok.
    • windows-check: still blocked by main's settings/fab.rs:528 (E0034, from e3e2544). This PR doesn't touch that file.

@i2cjak
i2cjak force-pushed the fix/1345-leave-idle branch from 17c112c to 9e3f5eb Compare November 20, 2026 20:02
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@i2cjak
i2cjak force-pushed the fix/1345-leave-idle branch from 9e3f5eb to 7e54879 Compare November 20, 2026 20:36
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
… says so and attaches again once it has ended (#1470 finding 1)

Carbon's Windows r1 (17c112c): after the idle close KiCad dropped its API but its process lived 2.5 min, and the next Edit attached to
it. The same on Linux under load (run 8 here). Narrow, as decided: `attach` on a session that is `closing` (the hub's Close: idle, the
cap, the person's, an agent's; or a runtime move) while it is ready or unresponsive answers `closing` and changes nothing
(closing_not_reused; a restart's placeholder is joined as before). The pane then says "KiCad is closing. The editor opens again once it
has closed." (gpui.c.kicad.closing, en/es/ja), maps nothing of the old KiCad, and attaches again once the hub's picture no longer has
that process live, which starts a fresh KiCad. `retire` publishes the session (its `closing` in the info), and a pane off screen when
its KiCad starts closing goes at once (closing_away), so coming back never shows a pane on a KiCad still ending. No kill, no bound, no
change to how a close is recorded: the close-wait PR does those.

Tests: an_attach_never_reuses_a_kicad_that_is_closing (hub), a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (client);
e2e test/kicad_embed/embed_closing_attach_e2e.sh (C1, C2; the slow exit made by SIGSTOP at the idle close). embed_leave_idle L1 waits
up to 30 s for the old process to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@i2cjak
i2cjak force-pushed the fix/1345-leave-idle branch from 7e54879 to d5582bb Compare November 20, 2026 20:49
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
… says so and attaches again once it has ended (#1470 finding 1)

Carbon's Windows r1 (17c112c): after the idle close KiCad dropped its API but its process lived 2.5 min, and the next Edit attached to
it. The same on Linux under load (run 8 here). Narrow, as decided: `attach` on a session that is `closing` (the hub's Close: idle, the
cap, the person's, an agent's; or a runtime move) while it is ready or unresponsive answers `closing` and changes nothing
(closing_not_reused; a restart's placeholder is joined as before). The pane then says "KiCad is closing. The editor opens again once it
has closed." (gpui.c.kicad.closing, en/es/ja), maps nothing of the old KiCad, and attaches again once the hub's picture no longer has
that process live, which starts a fresh KiCad. `retire` publishes the session (its `closing` in the info), and a pane off screen when
its KiCad starts closing goes at once (closing_away), so coming back never shows a pane on a KiCad still ending. No kill, no bound, no
change to how a close is recorded: the close-wait PR does those.

Tests: an_attach_never_reuses_a_kicad_that_is_closing (hub), a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (client);
e2e test/kicad_embed/embed_closing_attach_e2e.sh (C1, C2; the slow exit made by SIGSTOP at the idle close). embed_leave_idle L1 waits
up to 30 s for the old process to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…tarts a fresh one; an automatic pane goes (#1470, the KiCad lead's check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…viction Close, and still clean, is ended as a hang (#1470, the KiCad lead's bound)

On Windows (Carbon's main r2) a KiCad answered the hub's idle Close and never exited; with the closing guard an Edit then waited on it for
ever. The existing 800 ms kill is not broken: it is only in close() (editor.kicad.close, the person's or an agent's), after Close
answers; retire() (idle, evicted, appClosed) sends Close and nothing else. For the hub's idle and eviction closes only (a KiCad chosen
clean: nothing unsaved, no dialog, in no pane), IDLE_CLOSE_BOUND (15 s; BACKPLANE_KICAD_IDLE_CLOSE_BOUND_S for tests) after the Close the
same pid still running is checked again (bound_kill): still clean, it is killed and logged "a hang after its idle close: pid N still
running M ms after the hub's Close, killed", and its exit ends the session as a clean one does (stopped, the idle reason kept), so the
waiting Edit starts a fresh KiCad; unsaved or a dialog since, it is left and said. Every other close is unchanged (the close-wait PR's).

Tests: a_kicad_still_running_at_the_bound_after_an_idle_close_is_ended_only_while_still_clean; e2e embed_closing_attach C2 now never
lets the frozen KiCad go: ended at the bound (15000 ms, logged), a fresh KiCad on show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…; no answer starts the bound (#1470)

Found writing the close-wait PR: retire() did not read Close's answer, so a Close KiCad refused (it became modified after it was chosen,
or its task held it: CM_FAIL_IF_MODIFIED) left the session `closing` for good, and with closing_not_reused every later Edit would wait on
a close that never came. Refused (an answer with a status: close_refused) clears `closing` and the stop reason and publishes; the bound
counts from the answer. No answer at all (closed or timed out: a KiCad already going, or hung) is no refusal: the bound takes it.

Test: a_refused_idle_close_ends_the_closing_but_no_answer_does_not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@i2cjak
i2cjak force-pushed the fix/1345-leave-idle branch from f080345 to 6a053a3 Compare November 20, 2026 21:30
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
… says so and attaches again once it has ended (#1470 finding 1)

Carbon's Windows r1 (17c112c): after the idle close KiCad dropped its API but its process lived 2.5 min, and the next Edit attached to
it. The same on Linux under load (run 8 here). Narrow, as decided: `attach` on a session that is `closing` (the hub's Close: idle, the
cap, the person's, an agent's; or a runtime move) while it is ready or unresponsive answers `closing` and changes nothing
(closing_not_reused; a restart's placeholder is joined as before). The pane then says "KiCad is closing. The editor opens again once it
has closed." (gpui.c.kicad.closing, en/es/ja), maps nothing of the old KiCad, and attaches again once the hub's picture no longer has
that process live, which starts a fresh KiCad. `retire` publishes the session (its `closing` in the info), and a pane off screen when
its KiCad starts closing goes at once (closing_away), so coming back never shows a pane on a KiCad still ending. No kill, no bound, no
change to how a close is recorded: the close-wait PR does those.

Tests: an_attach_never_reuses_a_kicad_that_is_closing (hub), a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (client);
e2e test/kicad_embed/embed_closing_attach_e2e.sh (C1, C2; the slow exit made by SIGSTOP at the idle close). embed_leave_idle L1 waits
up to 30 s for the old process to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…tarts a fresh one; an automatic pane goes (#1470, the KiCad lead's check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…viction Close, and still clean, is ended as a hang (#1470, the KiCad lead's bound)

On Windows (Carbon's main r2) a KiCad answered the hub's idle Close and never exited; with the closing guard an Edit then waited on it for
ever. The existing 800 ms kill is not broken: it is only in close() (editor.kicad.close, the person's or an agent's), after Close
answers; retire() (idle, evicted, appClosed) sends Close and nothing else. For the hub's idle and eviction closes only (a KiCad chosen
clean: nothing unsaved, no dialog, in no pane), IDLE_CLOSE_BOUND (15 s; BACKPLANE_KICAD_IDLE_CLOSE_BOUND_S for tests) after the Close the
same pid still running is checked again (bound_kill): still clean, it is killed and logged "a hang after its idle close: pid N still
running M ms after the hub's Close, killed", and its exit ends the session as a clean one does (stopped, the idle reason kept), so the
waiting Edit starts a fresh KiCad; unsaved or a dialog since, it is left and said. Every other close is unchanged (the close-wait PR's).

Tests: a_kicad_still_running_at_the_bound_after_an_idle_close_is_ended_only_while_still_clean; e2e embed_closing_attach C2 now never
lets the frozen KiCad go: ended at the bound (15000 ms, logged), a fresh KiCad on show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…; no answer starts the bound (#1470)

Found writing the close-wait PR: retire() did not read Close's answer, so a Close KiCad refused (it became modified after it was chosen,
or its task held it: CM_FAIL_IF_MODIFIED) left the session `closing` for good, and with closing_not_reused every later Edit would wait on
a close that never came. Refused (an answer with a status: close_refused) clears `closing` and the stop reason and publishes; the bound
counts from the answer. No answer at all (closed or timed out: a KiCad already going, or hung) is no refusal: the bound takes it.

Test: a_refused_idle_close_ends_the_closing_but_no_answer_does_not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@i2cjak
i2cjak force-pushed the fix/1345-leave-idle branch from 6a053a3 to 7708a5d Compare November 20, 2026 21:55
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
… says so and attaches again once it has ended (#1470 finding 1)

Carbon's Windows r1 (17c112c): after the idle close KiCad dropped its API but its process lived 2.5 min, and the next Edit attached to
it. The same on Linux under load (run 8 here). Narrow, as decided: `attach` on a session that is `closing` (the hub's Close: idle, the
cap, the person's, an agent's; or a runtime move) while it is ready or unresponsive answers `closing` and changes nothing
(closing_not_reused; a restart's placeholder is joined as before). The pane then says "KiCad is closing. The editor opens again once it
has closed." (gpui.c.kicad.closing, en/es/ja), maps nothing of the old KiCad, and attaches again once the hub's picture no longer has
that process live, which starts a fresh KiCad. `retire` publishes the session (its `closing` in the info), and a pane off screen when
its KiCad starts closing goes at once (closing_away), so coming back never shows a pane on a KiCad still ending. No kill, no bound, no
change to how a close is recorded: the close-wait PR does those.

Tests: an_attach_never_reuses_a_kicad_that_is_closing (hub), a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (client);
e2e test/kicad_embed/embed_closing_attach_e2e.sh (C1, C2; the slow exit made by SIGSTOP at the idle close). embed_leave_idle L1 waits
up to 30 s for the old process to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…tarts a fresh one; an automatic pane goes (#1470, the KiCad lead's check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…viction Close, and still clean, is ended as a hang (#1470, the KiCad lead's bound)

On Windows (Carbon's main r2) a KiCad answered the hub's idle Close and never exited; with the closing guard an Edit then waited on it for
ever. The existing 800 ms kill is not broken: it is only in close() (editor.kicad.close, the person's or an agent's), after Close
answers; retire() (idle, evicted, appClosed) sends Close and nothing else. For the hub's idle and eviction closes only (a KiCad chosen
clean: nothing unsaved, no dialog, in no pane), IDLE_CLOSE_BOUND (15 s; BACKPLANE_KICAD_IDLE_CLOSE_BOUND_S for tests) after the Close the
same pid still running is checked again (bound_kill): still clean, it is killed and logged "a hang after its idle close: pid N still
running M ms after the hub's Close, killed", and its exit ends the session as a clean one does (stopped, the idle reason kept), so the
waiting Edit starts a fresh KiCad; unsaved or a dialog since, it is left and said. Every other close is unchanged (the close-wait PR's).

Tests: a_kicad_still_running_at_the_bound_after_an_idle_close_is_ended_only_while_still_clean; e2e embed_closing_attach C2 now never
lets the frozen KiCad go: ended at the bound (15000 ms, logged), a fresh KiCad on show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…; no answer starts the bound (#1470)

Found writing the close-wait PR: retire() did not read Close's answer, so a Close KiCad refused (it became modified after it was chosen,
or its task held it: CM_FAIL_IF_MODIFIED) left the session `closing` for good, and with closing_not_reused every later Edit would wait on
a close that never came. Refused (an answer with a status: close_refused) clears `closing` and the stop reason and publishes; the bound
counts from the answer. No answer at all (closed or timed out: a KiCad already going, or hung) is no refusal: the bound takes it.

Test: a_refused_idle_close_ends_the_closing_but_no_answer_does_not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 20, 2026
…KiCad to be gone; a close that did not happen leaves it live; a waiting pane learns a refusal; no kill or eviction while it is in use

From the cross-model review of 6a053a3, as the KiCad lead confirmed:
1. Two KiCads on one project: close() publishes the session stopped as Close answers and kills 800 ms later, and the fresh-start path
   started the next KiCad at once (the closing guard re-attaches the moment `stopped` is published). A session keeps its last pid when
   it stops (`last_pid`, cleared by the real exit); attach's start path waits for it to be gone (previous_alive, then gone_before_retry
   with restart's kill, Msg::AttachAfterGone), and never starts a second beside it.
2. The bound's "not killed" (not clean any more, a dialog, in use) cleared nothing: the session stayed ready+closing and every Edit was
   answered closing. It is live again now (Session::live_again, as a refused Close: also not chosen again at the next tick). The app-gone
   close has the bound too (its KiCads were chosen clean).
3. A waiting pane never saw a refusal: still_closing reads `closing` as well.
4. The bound could end a busy KiCad, and eviction could pick one mid-operation: `busy` (a named request in flight, in_flight; or a job,
   progress::has_jobs), read by note_use, keeps it from both.
Also: a re-attach while the pane is off screen (a reconnect) says the leave again (LeaveState::resend).

Tests: a_fresh_start_waits_for_the_projects_previous_kicad_to_be_gone (a real process as the previous KiCad),
a_close_that_did_not_happen_leaves_the_kicad_live_and_not_closing, a_kicad_in_use_is_never_evicted_nor_ended_at_the_bound;
client: a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (refusal), a_pane_off_screen_is_told_to_the_hub_once_settled_and_back_at_once (resend).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…tarts a fresh one; an automatic pane goes (#1470, the KiCad lead's check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…viction Close, and still clean, is ended as a hang (#1470, the KiCad lead's bound)

On Windows (Carbon's main r2) a KiCad answered the hub's idle Close and never exited; with the closing guard an Edit then waited on it for
ever. The existing 800 ms kill is not broken: it is only in close() (editor.kicad.close, the person's or an agent's), after Close
answers; retire() (idle, evicted, appClosed) sends Close and nothing else. For the hub's idle and eviction closes only (a KiCad chosen
clean: nothing unsaved, no dialog, in no pane), IDLE_CLOSE_BOUND (15 s; BACKPLANE_KICAD_IDLE_CLOSE_BOUND_S for tests) after the Close the
same pid still running is checked again (bound_kill): still clean, it is killed and logged "a hang after its idle close: pid N still
running M ms after the hub's Close, killed", and its exit ends the session as a clean one does (stopped, the idle reason kept), so the
waiting Edit starts a fresh KiCad; unsaved or a dialog since, it is left and said. Every other close is unchanged (the close-wait PR's).

Tests: a_kicad_still_running_at_the_bound_after_an_idle_close_is_ended_only_while_still_clean; e2e embed_closing_attach C2 now never
lets the frozen KiCad go: ended at the bound (15000 ms, logged), a fresh KiCad on show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…; no answer starts the bound (#1470)

Found writing the close-wait PR: retire() did not read Close's answer, so a Close KiCad refused (it became modified after it was chosen,
or its task held it: CM_FAIL_IF_MODIFIED) left the session `closing` for good, and with closing_not_reused every later Edit would wait on
a close that never came. Refused (an answer with a status: close_refused) clears `closing` and the stop reason and publishes; the bound
counts from the answer. No answer at all (closed or timed out: a KiCad already going, or hung) is no refusal: the bound takes it.

Test: a_refused_idle_close_ends_the_closing_but_no_answer_does_not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…KiCad to be gone; a close that did not happen leaves it live; a waiting pane learns a refusal; no kill or eviction while it is in use

From the cross-model review of 6a053a3, as the KiCad lead confirmed:
1. Two KiCads on one project: close() publishes the session stopped as Close answers and kills 800 ms later, and the fresh-start path
   started the next KiCad at once (the closing guard re-attaches the moment `stopped` is published). A session keeps its last pid when
   it stops (`last_pid`, cleared by the real exit); attach's start path waits for it to be gone (previous_alive, then gone_before_retry
   with restart's kill, Msg::AttachAfterGone), and never starts a second beside it.
2. The bound's "not killed" (not clean any more, a dialog, in use) cleared nothing: the session stayed ready+closing and every Edit was
   answered closing. It is live again now (Session::live_again, as a refused Close: also not chosen again at the next tick). The app-gone
   close has the bound too (its KiCads were chosen clean).
3. A waiting pane never saw a refusal: still_closing reads `closing` as well.
4. The bound could end a busy KiCad, and eviction could pick one mid-operation: `busy` (a named request in flight, in_flight; or a job,
   progress::has_jobs), read by note_use, keeps it from both.
Also: a re-attach while the pane is off screen (a reconnect) says the leave again (LeaveState::resend).

Tests: a_fresh_start_waits_for_the_projects_previous_kicad_to_be_gone (a real process as the previous KiCad),
a_close_that_did_not_happen_leaves_the_kicad_live_and_not_closing, a_kicad_in_use_is_never_evicted_nor_ended_at_the_bound;
client: a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (refusal), a_pane_off_screen_is_told_to_the_hub_once_settled_and_back_at_once (resend).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…n the previous KiCad is kept for it; busy has a quiet window; only the waited pid is forgotten

1. A leave behind a held attach (AttachAfterGone) reached a stopped session and was lost, so the new KiCad started with `left` empty
   while the pane had sent it (#1345 again on that path); a detach meanwhile had the same order. `Deferred` keeps them: a leave (or back)
   that comes for the project while its start is held is applied once the start has run; a detach cancels the held start.
2. `busy` was an instant: an agent's sequential calls have gaps. It is now others_busy(sock, BUSY_QUIET_MS = 10 s), for eviction and the
   bound.
3. AttachAfterGone forgets `last_pid` only when it is the pid waited on (Session::waited_gone).
Also (review 6): RetryNow's "would not close" keeps the unkillable pid as `last_pid`, so the next start waits on it again.
(Review 4, `live_again` wiping a person's closeAsked: not reachable here, the bound covers only the hub's own closes.)

Tests: a_leave_or_a_detach_while_a_start_waits_on_the_previous_kicad_is_kept_for_it, a_held_start_clears_only_the_pid_it_waited_on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…the session itself; every attach, leave and detach meanwhile takes the paths of a starting session (the KiCad lead's shape)

The delta review of 7716fc2 found that `Deferred` kept one slot per project while several attaches could be held at once (a warm-up and
the pane's Edit): a leave or a detach could be consumed by the wrong one, or a stale detach answer the live pane. Instead of slots: when
a fresh start finds the project's previous KiCad still there (previous_alive), the project's session is put in place at once as
"starting" (HELD_REASON, a new generation, the attach's pane: held_session) and published. A warm-up, the pane's Edit or a re-attach then
joins it through attach's starting branch, a leave or back is the ordinary leave() (holder check against its pane_cid), a detach the
ordinary detach(); a message of the old session's generation is stale (#1435). Once the previous KiCad has ended (held_wait, HELD_WAIT
15 s) the one real start runs from the held session's fields (its pane, holder, `left`, `parked`); its waiters are finished when KiCad is
ready. It never kills the previous KiCad (it may be finishing a save or asking): past HELD_WAIT the held session fails, "the KiCad
before it is still closing (pid N, 15 s)…", with Try again. While held the pane says "KiCad is closing…" (waits_previous), never a
start that looks hung. `Deferred`, AttachAfterGone and waited_gone are gone; the mode the start will run in is the held session's.

Tests: a_start_held_for_the_previous_kicad_is_one_session_that_every_attach_joins,
a_leave_or_a_detach_while_a_start_is_held_is_kept_by_its_session (with the stale generation),
a_held_start_begins_once_the_previous_kicad_is_gone (a real process; nothing kills it); client: the held start's text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…n number, not the KiCad generation; an early return in a start answers its waiters

1. A leave re-sent after a reattach carried the old session's generation, so the hub answered it stale and the new KiCad counted as in
   the pane for good (the same across a held start's switch to the real one). Leave/back no longer take the generation rule: the
   holder check guards whose word it is, and the client numbers them (`seq`, one count for the whole client), which the hub keeps per
   project and client across sessions (leave_in_order): a re-sent leave applies, and a leave older than a later back never wins.
2. An early return in the real start (KiCad's program not found, the macOS refusal, Windows stock) left a held start's waiters
   unanswered: now they are answered and a final picture published.

Tests: a_leave_resent_after_a_reattach_under_a_new_generation_applies, a_late_leave_never_marks_a_pane_left_that_is_back_on_screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@i2cjak
i2cjak force-pushed the fix/1345-leave-idle branch from c4fc48f to ab39617 Compare November 21, 2026 06:15
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
… says so and attaches again once it has ended (#1470 finding 1)

Carbon's Windows r1 (17c112c): after the idle close KiCad dropped its API but its process lived 2.5 min, and the next Edit attached to
it. The same on Linux under load (run 8 here). Narrow, as decided: `attach` on a session that is `closing` (the hub's Close: idle, the
cap, the person's, an agent's; or a runtime move) while it is ready or unresponsive answers `closing` and changes nothing
(closing_not_reused; a restart's placeholder is joined as before). The pane then says "KiCad is closing. The editor opens again once it
has closed." (gpui.c.kicad.closing, en/es/ja), maps nothing of the old KiCad, and attaches again once the hub's picture no longer has
that process live, which starts a fresh KiCad. `retire` publishes the session (its `closing` in the info), and a pane off screen when
its KiCad starts closing goes at once (closing_away), so coming back never shows a pane on a KiCad still ending. No kill, no bound, no
change to how a close is recorded: the close-wait PR does those.

Tests: an_attach_never_reuses_a_kicad_that_is_closing (hub), a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (client);
e2e test/kicad_embed/embed_closing_attach_e2e.sh (C1, C2; the slow exit made by SIGSTOP at the idle close). embed_leave_idle L1 waits
up to 30 s for the old process to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak pushed a commit that referenced this pull request Nov 21, 2026
…tarts a fresh one; an automatic pane goes (#1470, the KiCad lead's check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
i2cjak and others added 17 commits November 21, 2026 02:19
…for the idle close and the cap (#1345)

The client tells the hub when the pane leaves the screen because the person moved away (another thread or design, the viewer closed or
on another page: `in_page` false for 300 ms) and when it is back (editor.kicad.leave {left, why, generation}). A sheet over the pane is
not a leave. The leave is a plain send: no keyboard, no window, no call that waits on KiCad.

Hub: `Session.left` counts as out of the pane for idle_victims and evict_warm (out_of_pane) unless a dialog of KiCad's is up; unsaved
work stays exempt. Only the holder's leave counts (leave_counts), a stale generation changes nothing, a second leave never restarts
the clock. A holder whose connection is gone for 15 s counts as left (holderGone). The idle clock is the last use: an agent's or a
panel's request to that KiCad and a KiCad job running (ET_PROGRESS) are use (note_use), so a KiCad being used is not idle, left or
not. The idle close's log line says why. The close path is unchanged. Closed as idle while away, the pane gives the viewer back.

e2e: test/kicad_embed/embed_leave_idle_e2e.sh (L1-L5).

Fixes #1345

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ead; e2e L3 leaves by the Files page, pids of this run's copy only (#1345)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ain gives (#1345)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed 10 s ago kept, unused 301 s closed); e2e L6 (another thread of the same project showing the editor keeps it on screen, the leave comes when the last page showing it goes); the always-on leave log line says why

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lose, not the person's (Windows: KiCad closes its frames before it exits) (#1470 review)

Carbon's Windows rows (17c112c): after the idle close KiCad sent ET_FRAME_CLOSED for both frames before it exited, and the viewer
came back through PaneFrameClosed, which also put the project in kicad_closed (the person's close: no automatic attach after it).
`closed_idle_away` (the stop first) is Linux's order. A frame closed while the pane is off screen (nobody could close it there) now
gives the viewer back without the hold; both paths log kicad_idle_closed_away with "by" ("stopped" / "frames closed"), and the e2e
says which it saw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… says so and attaches again once it has ended (#1470 finding 1)

Carbon's Windows r1 (17c112c): after the idle close KiCad dropped its API but its process lived 2.5 min, and the next Edit attached to
it. The same on Linux under load (run 8 here). Narrow, as decided: `attach` on a session that is `closing` (the hub's Close: idle, the
cap, the person's, an agent's; or a runtime move) while it is ready or unresponsive answers `closing` and changes nothing
(closing_not_reused; a restart's placeholder is joined as before). The pane then says "KiCad is closing. The editor opens again once it
has closed." (gpui.c.kicad.closing, en/es/ja), maps nothing of the old KiCad, and attaches again once the hub's picture no longer has
that process live, which starts a fresh KiCad. `retire` publishes the session (its `closing` in the info), and a pane off screen when
its KiCad starts closing goes at once (closing_away), so coming back never shows a pane on a KiCad still ending. No kill, no bound, no
change to how a close is recorded: the close-wait PR does those.

Tests: an_attach_never_reuses_a_kicad_that_is_closing (hub), a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (client);
e2e test/kicad_embed/embed_closing_attach_e2e.sh (C1, C2; the slow exit made by SIGSTOP at the idle close). embed_leave_idle L1 waits
up to 30 s for the old process to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tarts a fresh one; an automatic pane goes (#1470, the KiCad lead's check)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…viction Close, and still clean, is ended as a hang (#1470, the KiCad lead's bound)

On Windows (Carbon's main r2) a KiCad answered the hub's idle Close and never exited; with the closing guard an Edit then waited on it for
ever. The existing 800 ms kill is not broken: it is only in close() (editor.kicad.close, the person's or an agent's), after Close
answers; retire() (idle, evicted, appClosed) sends Close and nothing else. For the hub's idle and eviction closes only (a KiCad chosen
clean: nothing unsaved, no dialog, in no pane), IDLE_CLOSE_BOUND (15 s; BACKPLANE_KICAD_IDLE_CLOSE_BOUND_S for tests) after the Close the
same pid still running is checked again (bound_kill): still clean, it is killed and logged "a hang after its idle close: pid N still
running M ms after the hub's Close, killed", and its exit ends the session as a clean one does (stopped, the idle reason kept), so the
waiting Edit starts a fresh KiCad; unsaved or a dialog since, it is left and said. Every other close is unchanged (the close-wait PR's).

Tests: a_kicad_still_running_at_the_bound_after_an_idle_close_is_ended_only_while_still_clean; e2e embed_closing_attach C2 now never
lets the frozen KiCad go: ended at the bound (15000 ms, logged), a fresh KiCad on show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…; no answer starts the bound (#1470)

Found writing the close-wait PR: retire() did not read Close's answer, so a Close KiCad refused (it became modified after it was chosen,
or its task held it: CM_FAIL_IF_MODIFIED) left the session `closing` for good, and with closing_not_reused every later Edit would wait on
a close that never came. Refused (an answer with a status: close_refused) clears `closing` and the stop reason and publishes; the bound
counts from the answer. No answer at all (closed or timed out: a KiCad already going, or hung) is no refusal: the bound takes it.

Test: a_refused_idle_close_ends_the_closing_but_no_answer_does_not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1. Two KiCads on one project: close() publishes the session stopped as Close answers and kills 800 ms later, and the fresh-start path
   started the next KiCad at once (the closing guard re-attaches the moment `stopped` is published). A session keeps its last pid when
   it stops (`last_pid`, cleared by the real exit); attach's start path waits for it to be gone (previous_alive, then gone_before_retry
   with restart's kill, Msg::AttachAfterGone), and never starts a second beside it.
2. The bound's "not killed" (not clean any more, a dialog, in use) cleared nothing: the session stayed ready+closing and every Edit was
   answered closing. It is live again now (Session::live_again, as a refused Close: also not chosen again at the next tick). The app-gone
   close has the bound too (its KiCads were chosen clean).
3. A waiting pane never saw a refusal: still_closing reads `closing` as well.
4. The bound could end a busy KiCad, and eviction could pick one mid-operation: `busy` (a named request in flight, in_flight; or a job,
   progress::has_jobs), read by note_use, keeps it from both.
Also: a re-attach while the pane is off screen (a reconnect) says the leave again (LeaveState::resend).

Tests: a_fresh_start_waits_for_the_projects_previous_kicad_to_be_gone (a real process as the previous KiCad),
a_close_that_did_not_happen_leaves_the_kicad_live_and_not_closing, a_kicad_in_use_is_never_evicted_nor_ended_at_the_bound;
client: a_pane_waits_on_a_closing_kicad_until_its_process_is_gone (refusal), a_pane_off_screen_is_told_to_the_hub_once_settled_and_back_at_once (resend).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n the previous KiCad is kept for it; busy has a quiet window; only the waited pid is forgotten

1. A leave behind a held attach (AttachAfterGone) reached a stopped session and was lost, so the new KiCad started with `left` empty
   while the pane had sent it (#1345 again on that path); a detach meanwhile had the same order. `Deferred` keeps them: a leave (or back)
   that comes for the project while its start is held is applied once the start has run; a detach cancels the held start.
2. `busy` was an instant: an agent's sequential calls have gaps. It is now others_busy(sock, BUSY_QUIET_MS = 10 s), for eviction and the
   bound.
3. AttachAfterGone forgets `last_pid` only when it is the pid waited on (Session::waited_gone).
Also (review 6): RetryNow's "would not close" keeps the unkillable pid as `last_pid`, so the next start waits on it again.
(Review 4, `live_again` wiping a person's closeAsked: not reachable here, the bound covers only the hub's own closes.)

Tests: a_leave_or_a_detach_while_a_start_waits_on_the_previous_kicad_is_kept_for_it, a_held_start_clears_only_the_pid_it_waited_on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the session itself; every attach, leave and detach meanwhile takes the paths of a starting session (the KiCad lead's shape)

The delta review of 7716fc2 found that `Deferred` kept one slot per project while several attaches could be held at once (a warm-up and
the pane's Edit): a leave or a detach could be consumed by the wrong one, or a stale detach answer the live pane. Instead of slots: when
a fresh start finds the project's previous KiCad still there (previous_alive), the project's session is put in place at once as
"starting" (HELD_REASON, a new generation, the attach's pane: held_session) and published. A warm-up, the pane's Edit or a re-attach then
joins it through attach's starting branch, a leave or back is the ordinary leave() (holder check against its pane_cid), a detach the
ordinary detach(); a message of the old session's generation is stale (#1435). Once the previous KiCad has ended (held_wait, HELD_WAIT
15 s) the one real start runs from the held session's fields (its pane, holder, `left`, `parked`); its waiters are finished when KiCad is
ready. It never kills the previous KiCad (it may be finishing a save or asking): past HELD_WAIT the held session fails, "the KiCad
before it is still closing (pid N, 15 s)…", with Try again. While held the pane says "KiCad is closing…" (waits_previous), never a
start that looks hung. `Deferred`, AttachAfterGone and waited_gone are gone; the mode the start will run in is the held session's.

Tests: a_start_held_for_the_previous_kicad_is_one_session_that_every_attach_joins,
a_leave_or_a_detach_while_a_start_is_held_is_kept_by_its_session (with the stale generation),
a_held_start_begins_once_the_previous_kicad_is_gone (a real process; nothing kills it); client: the held start's text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n number, not the KiCad generation; an early return in a start answers its waiters

1. A leave re-sent after a reattach carried the old session's generation, so the hub answered it stale and the new KiCad counted as in
   the pane for good (the same across a held start's switch to the real one). Leave/back no longer take the generation rule: the
   holder check guards whose word it is, and the client numbers them (`seq`, one count for the whole client), which the hub keeps per
   project and client across sessions (leave_in_order): a re-sent leave applies, and a leave older than a later back never wins.
2. An early return in the real start (KiCad's program not found, the macOS refusal, Windows stock) left a held start's waiters
   unanswered: now they are answered and a final picture published.

Tests: a_leave_resent_after_a_reattach_under_a_new_generation_applies, a_late_leave_never_marks_a_pane_left_that_is_back_on_screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he page takes no input and no focus

A hand-in pending after the person's Edit (want_keys) could complete off the page: an agent's viewer_show switching the page while
KiCad was still starting, or a switch inside EDIT_KEY_GRACE_MS, and the frame's arrival focused the editor off screen (nc::focus;
yield_to + ShowFrame{focus} on macOS), set `keys`, grabbed Escape and touched the left KiCad's idle clock. The hand-in is now gated on
the page and the pane's rect (hand_in_on_page), and set_in_page(false) drops a waiting hand-in (hand_in_after_leave).

Test: a_hand_in_pending_across_a_leave_never_focuses_an_editor_off_screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…' hand-in repost are gated on the page too (a pane off the page takes no focus)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

A KiCad I left by switching threads keeps running and is never closed as idle

1 participant