Skip to content

pane ownership: carry a restart's set into the replacement pane (orca #44, stage 3 piece a) - #68

Merged
nachumi-a2zoperations merged 4 commits into
blowzer/fork-onlyfrom
nachumi-a2zoperations/issue-44-restart-carry
Nov 16, 2026
Merged

nachumi-a2zoperations merged 4 commits into
blowzer/fork-onlyfrom
nachumi-a2zoperations/issue-44-restart-carry

Conversation

@nachumi-a2zoperations

Copy link
Copy Markdown

Refs #44: stage 3 piece (a), restart carry-over, observe only. The design note was approved by the lane lead (~/nacho-run/orca-44-observe-ab.md, md5 a6013a07); piece (b) is PR 66 (merged).

What it does

  • The gap: a restart (account move, pane restart, resume into a new terminal) used to log the old pane's recorded set with reason=restart and then drop it. The processes the old agent left running (the Orchestration: rejected heartbeats from a stale terminal handle keep being delivered to the run (released dispatch) #5 shape) vanished from the log.
  • Order (read from the code): main stops the old PTY BEFORE it spawns the replacement (beginRuntimePaneReplacement).
  • The fix:
    1. At the restart's close, the daemon holds the old pane's still-present entries for CARRY_HOLD_MS (60 s).
    2. The replacement's spawn names the old PTY (carriesFrom).
    3. The new pane adopts the held entries, marked carried: { from, generation }.
    4. One pane-ownership-carry line is logged. The entries then appear, labelled, in the new pane's close lines.
  • Either order works: the claim may come before or after the hold.

Protocol change (named plainly)

  • ONE optional field, carriesFrom?: string, on the daemon's createOrAttach request payload (daemon-rpc-contract.ts). Its value is main's own replacesPtyId.
  • Path: PtySpawnOptions.carriesFrom → the daemon adapter's payload (non-attach creates only) → daemon-terminal-admission → TerminalHost (CreateOrAttachOptions.carriesFrom). The host calls the observer's optional noteCarry(sessionId, fromSessionId) hook when a session is really created, never on an attach.
  • Both spawn routes (runtime spawn-options.ts, window ipc/spawn-options.ts) map replacesPtyId through one helper, carryOverFor.
  • Older peers:
    • an older daemon ignores the field, and nothing is claimed;
    • an older app never sends it, so a held set expires after 60 s with one carry-unclaimed line, which is today's drop, now visible;
    • an observer without noteCarry is fine (the hook is optional, and its call is guarded).

Observe only (S1)

  • Nothing gains a way to signal. The new module pane-ownership-carry.ts only moves entries between sets and logs.
  • The stage-2 folder-wide import scan covers it.
  • Mode off drops everything held.

Bounds (the "leaked set across a restart" question)

  • First claim wins. A second claim logs pane-ownership-carry-already-claimed and gets nothing.
  • A claim that names a close (not a restart) carries nothing.
  • Unclaimed after 60 s: pane-ownership-carry-unclaimed, dropped.
  • Claimed but never sampled: pane-ownership-carry-unadopted.
  • At most CARRY_MAX_ENTRIES (256) per carry, the rest counted (droppedOverCap).
  • An entry carried CARRY_MAX_GENERATIONS (8) times is dropped and counted (droppedGenerations), so a pane that rotates all day cannot grow.
  • Memory only, like every set.

Tests (red first)

  • pane-ownership-carry.test.ts, 9 rows:
    • adopt + the new close logs carried;
    • claim before hold;
    • unclaimed expiry;
    • a close is never held;
    • double claim;
    • a dead process is not carried;
    • the generation cap over a chain of restarts;
    • the entry cap;
    • mode off.
    • It failed at import on base.
  • Host (terminal-host-pane-ownership.test.ts, 3 new):
    • a created agent pane with carriesFrom reports once;
    • a plain shell, or no field, reports nothing;
    • a throwing hook or an older hook set never changes the creation.
    • Red check: with the one onCreated call removed, 1 failed.
  • Adapter → daemon (daemon-pty-adapter-carries-from.test.ts): through the real adapter, wire and admission, the field reaches TerminalHost.createOrAttach, and is absent when not given. Red check: with the payload line removed, 1 failed.
  • Main (spawn-carry-over.test.ts): carryOverFor, and a pin that both routes and the assembly use it. The route pin was red before the routes used it.
  • Pane-ownership + terminal-host + the two new main/adapter files: 130/130.

Gates (MacBook, Node 24.22.1 first on PATH for the run, no override)

  • pnpm check:changed --base=origin/blowzer/fork-only: 24/24 at ea21ca1, including typecheck (node, web, cli), oxlint, the changed-code quality gate and the unit step.
  • Earlier rounds fixed:
    • 11 type assertions in the new tests;
    • two Reflect.get reads of private fields, replaced by a TerminalHost.prototype spy.
  • git merge-tree with fork-only 1a01c00 (PRs 64, 65, 66 merged): clean.

Notes

  • The branch carries a merge of PR 66's head (af41fdc, now merged). The conflicts were the two new OwnedEntry fields side by side; both were kept.
  • With both pieces the observer reached 311 lines (limit 300), so the sampler's failure counting moved into pane-ownership-health.ts (SamplerHealth), with the same behaviour.
  • terminal-host.ts was at 299 of its 300 code lines; the hook costs one line there, an onCreated dependency of the session create.
  • Docs: docs/decisions/issue-44-pane-process-ownership.md §4, "As built" for (a).
  • CPU: (a) adds no reads and no helper processes: map operations at restart and close, plus one per-tick adopt/expire pass over held sets.

…44, stage 3 piece a)

Observe only: no signal path (the stage-2 folder scan covers the new
module). A restart (account move, pane restart, resume) used to log the
old pane's set and drop it. Main stops the old PTY BEFORE it spawns the
replacement, so the daemon now HOLDS the still-present entries for
CARRY_HOLD_MS (60 s); the replacement's spawn names the old PTY and the
new pane adopts them, marked carried {from, generation}, so its later
close shows what the old agent left behind.

The link is ONE optional protocol field: carriesFrom (= main's own
replacesPtyId) on PtySpawnOptions -> the daemon adapter's createOrAttach
payload (non-attach creates only) -> admission -> TerminalHost, which
reports it to the observer's optional noteCarry when a session is really
created (never an attach). An older daemon ignores the field (the held
set expires as before); an older app never sends it. Both spawn routes
map it via carryOverFor.

Bounds: first claim wins (a second is logged); a claim naming a CLOSE
carries nothing; unclaimed after 60 s -> one carry-unclaimed line and
dropped; at most 256 entries per carry; an entry carried 8 times is
dropped and counted; mode off drops what is held; memory only.

Refs #44

Signed-off-by: Nachumi Eliyahu <[email protected]>
Refs #44. Conflicts were the two new OwnedEntry fields side by side
(carried, marker), the entry line and one import: both kept. With both
pieces the observer is 311 lines (limit 300), so the sampler's failure
counting moves into pane-ownership-health.ts (SamplerHealth), unchanged
behaviour; SAMPLER_FAILURES_BEFORE_LOG is re-exported from the observer.

Signed-off-by: Nachumi Eliyahu <[email protected]>
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