Skip to content

fix(pi): complete a run whose settle never comes, and re-open a late busy post - #63

Merged
nplez1 merged 1 commit into
nplez1/mainfrom
nplez1/pi-status-child-session
Oct 9, 2026
Merged

nplez1 merged 1 commit into
nplez1/mainfrom
nplez1/pi-status-child-session

Conversation

@nplez1

@nplez1 nplez1 commented Oct 9, 2026

Copy link
Copy Markdown
Owner

ELI5

The Agents list shows a word next to each agent: Working, Waiting, Idle. A Pi agent's row could get stuck on "Working — bash" for hours after that agent had finished its turn and gone quiet. Nothing the agent did afterwards could clear it, and only restarting the app would. Two separate gaps in the Pi status lane let a finished turn go unpublished; both are fixed here.

What Changed

Before: a Pi pane that finished its turn stayed on Working indefinitely. Confirmed live, not theorised: orca worktree ps reported state: working with stateStartedAt pointing at a dangling agent_start (21:07:34 on one pane, 23:03:51 on another) whose agent_stop never followed — while both sessions' own transcripts ended on an assistant message with stopReason: stop. The last hook Orca ever received was a working one, so the row had nothing left to answer it.

After: a run publishes its own completion whether or not the runtime happens to send its settle event, and a later stray working event re-asserts the completion it displaced instead of re-opening the row for good.

Two failures in the turn-end path, each fixed at its own point:

1. One settle silenced every later run

agent_settled set a session-lifetime boolean (agentSettledSupported) that made the agent_end fallback return early forever after. That boolean conflates "this runtime knows how to send a settle" with "this run already settled". So a run whose settle never arrived — or whose settle had been reported for a different run — could not publish its own completion either: its generation differed from the latch, and the fallback that exists to cover exactly that case had been switched off.

It is now the generation of the run that settled (settledGeneration = lifecycleState.runGeneration), and agent_end re-arms the idle recheck for the run that just ended. It is skipped only when that run already settled.

2. A working post after the completion re-opened the row for good

A working post that lands once the run is over — a re-finalized assistant message_end, a late tool_execution_end — re-opens the row, but the completion latch for that generation had already been consumed by the first completion. No later event could answer it, so the stale re-open was permanent. republishLateBusyPostCompletion() now runs after those two posts: when no turn is in flight and a run has actually ended, it re-asserts the completion the working post displaced.

The ordinary path is untouched: the latch still dedupes a settle against its own agent_end, and a busy post that arrives while a turn is in flight still leaves the run in flight.

Scope

Every change is either gated on kind === 'pi' at source-generation time or (for the settle tracking) a strictly narrower replacement of the boolean it replaces. OMP's willContinue / approval contract is not touched.

Why

Why track the settling run's generation rather than a "does this runtime settle?" flag. The existing flag was answering the wrong question. Its only purpose was to stop the fallback from double-posting a completion for a run that had already completed — and that is a question about a run, not about a runtime. Answering it per run fixes the under-reporting without weakening the dedupe, and a runtime that stops emitting settles simply falls back to the agent_end recheck, which is the behaviour that already existed for runtimes that never emitted them.

Why republish rather than suppress the late busy post. The late post is not spurious — it is newer truth than the completion and the host is right to apply it. Suppressing it would trade one wrong row for another (a finished turn that still shows a tool running). Re-asserting the completion keeps the host's last-write-wins rule intact and makes the pair of posts self-correcting.

Why both in one commit. They are the two halves of one symptom: a completion the pane never gets, and a completion the pane loses again after getting it. Either alone leaves a way to wedge the row, so a reviewer cannot judge the fix from one of them.

Linked Issue

N/A — a fork PR against nplez1/main, reported directly by the fork owner from a live stuck pane rather than filed as an issue first.

Visual Proof

The change is to what the status row reads (Working → Idle on a finished turn), but the defect only appears when a runtime stops emitting its settle event at the right moment, which is not reproducible on demand — that is exactly why it went unnoticed. The proof is the hook-event stream rather than a screenshot, and it is pinned by tests:

Scenario Before After
Run 1 settles, run 2 ends with no settle agent_start, agent_end, agent_start (run 2 never completes; pane stays working) agent_start, agent_end, agent_start, agent_end
message_end lands after the run completed agent_start, agent_end, message_end (row re-opened, permanently working) agent_start, agent_end, message_end, agent_end
tool_execution_end lands after the run completed agent_start, agent_end, tool_execution_end — same wedge agent_start, agent_end, tool_execution_end, agent_end
message_end during a run in flight agent_start, message_end agent_start, message_end — unchanged

The pre-fix failures were observed directly, not inferred: the second run posted nothing (expected ['agent_start','agent_end'] to equal ['agent_start','agent_end', ...]) and both late-busy cases delivered 3 posts where 4 are required. Say the word if a screen recording of the before/after is wanted anyway and I will drive a live pane for it.

Testing

  • pnpm tc — clean
  • pnpm lint — clean (full chain, including repo-wide oxlint and the max-lines ratchet)
  • pnpm test — full suite from this worktree; see the failure classification below
  • Targeted, before the full run: pnpm test src/main/pi (362 passed) and pnpm test src/shared/agent-hook-listener src/main/agent-hooks (1754 passed)
  • pnpm run check:code-quality:changed — clean

pnpm test result: 112,889 passed, 57 failed, 14 files failed, 113,878 total. Every one of the 57 is in a class this machine's LOCAL-PATCHES.md already records as red on the fork's base, and none of them is reachable from this change:

Class Files Why it is red here
Upstream-red logic — agent-session-*, agent-launch-*, structured-agent-session-* 9 Recorded as proved not ours: they reproduce on pre-merge 807aa6062c
Relay region correction 1 cloud/ is not installed on this host, so the suite dies importing pg
PTY / subprocess integration, bun project only 4 No child output under the bun runtime; passes under the node project

The baseline this is measured against is on record as 113,874 tests with 57 failing across 14 files on this machine before this branch existed; this run is 113,878 (the four new tests) with the same 57 failures in the same 14 files — the failing set is unchanged.

Three further checks back "not ours" rather than assuming it:

  • No failing file can see the change. Nothing in src/main/runtime, src/main/native-chat, src/main/daemon, src/relay or tests/e2e imports src/main/pi, so the changed module is not on any of the 14 files' import graph.
  • src/main/pi is green: 362 passed, including the four tests added here.
  • The one name not previously recorded, src/relay/subprocess.test.ts, passes on its own — pnpm test src/relay/subprocess.test.ts → 28 passed / 28. It timed out at the default 10s inside the full bun-project run, which is the shared-resource shape the recorded bun-project class has. It is noted in the LOCAL-PATCHES.md ledger rather than fixed here.

Platform: verified on macOS (this host). No platform-specific code path is touched — the change is in generated hook-handler source, which is platform-independent.

AI Disclosure

Written by Claude (Opus) in an agent session, reviewed by the fork owner. The live diagnosis was done against this machine's own stuck panes.

Review

Agent skill upstream boundary

  • Not applicable — no skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation is copied or translated.

Notes

  • Cross-platform: no platform-dependent behaviour; the changed code is generated hook-handler source.
  • SSH / remote: unchanged. Status posts travel the existing hook channel; no new wire field, param or opcode, so a mixed client/host version pair is unaffected.
  • Folder workspaces: unaffected — this is agent status, not workspace discovery.
  • Mobile / dashboard: unaffected; like the sidebar they read the same status store, which now simply receives a completion that was previously missing.
  • Performance: one extra boolean comparison per agent_end and message_end; no new timers, and the new code paths run at most once per turn.
  • Backwards compatibility: no API, config, schema or storage change.
  • Known, deliberately left alone: a Pi in-process task child runs this same generated extension, and its session_start writes the module-global sessionMetadata. So the pane's own posts can carry the child's session id — both wedged panes' posts currently name a child session that finished hours ago while their leads run. That attribution is deliberate for the child lane (agent-status-async-subagent.test.ts: "its child is reported, and reported for the session its own context named"), so changing it is its own decision and is not smuggled into this fix.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after evidence attached above as the event streams each test pins, with the reason a screenshot is not the right proof for this defect
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm tc, pnpm lint and pnpm test run from this worktree; results and failure classification above

…busy post

A pi pane could sit on "Working - <tool>" for hours after its turn was over: the
last hook Orca ever received was a working `message_end`, and nothing later could
take the row out of working. Confirmed live on two panes (`orca worktree ps`
reported `state: working` with `stateStartedAt` = the dangling `agent_start` at
21:07:34 and 23:03:51 whose `agent_stop` never followed, while both sessions'
transcripts ended on an assistant `stopReason: stop`).

Two ways the completion went missing, both in the turn-end path:

- `agent_settled` set a permanent `agentSettledSupported` flag, and `agent_end`
  returned early on it forever after. A run whose settle never arrived (or whose
  settle was reported for another run) could therefore not publish its own
  completion — the generation differed from the latch, so there was no fallback
  left. `agent_end` now arms the idle recheck for the run that just ended and is
  only skipped when THAT run already settled.
- A working post published after the run's completion (a re-finalized
  `message_end`, a late `tool_execution_end`) re-opened the row with the latch
  already consumed at that generation, so no later event could answer it. A busy
  post that lands while no turn is in flight now republishes the completion.

The pane's completion is otherwise unchanged: the latch still dedupes a settle
against its own `agent_end`, and OMP's `willContinue`/approval contract is
untouched (every change is `kind === 'pi'` or already runtime-gated).

Pre-fix evidence, from the new tests: the second run posted nothing
(`expected ['agent_start','agent_end'] to equal [... 'agent_start','agent_end']`),
and both late-busy cases delivered 3 posts instead of 4, leaving the row working.

Known and left alone (reported separately): a pi in-process task child runs this
same extension, and its `session_start` writes the module-global `sessionMetadata`,
so the pane's own posts carry the CHILD's session id — both wedged panes' posts
currently name a child session that finished hours ago while their leads run.
That is deliberate for the child lane's run attribution
(`agent-status-async-subagent.test.ts`: "its child is reported, and reported for
the session its own context named"), so it needs its own decision.

`pnpm test src/main/pi` (362 passed), `pnpm test src/shared/agent-hook-listener
src/main/agent-hooks` (1754 passed), `pnpm tc`, changed-code quality gate: clean.
@nplez1
nplez1 merged commit 21c3fb7 into nplez1/main Oct 9, 2026
nplez1 added a commit that referenced this pull request Oct 9, 2026
…it options

Merging a review-gated pull request with the admin bypass failed on every attempt
from the right sidebar, and from every other surface that offers it: the
confirmation appeared, the user accepted it, and the merge was refused with "This
pull request requires review approval before it can be merged." The same merge
succeeded on github.com. Confirmed on #63 and #64, both merged by hand in the end.

`getGitHubLocalGitOptionArgs` returns `[]` when a repo has no local git options —
the ordinary case for a local checkout with no WSL routing and no gh account bound
to the repo. Both host entry points spread that array immediately before a
trailing options object:

    ...getGitHubLocalGitOptionArgs(store, repo),
    { bypassBranchProtection: args.bypassBranchProtection === true }

An empty array spreads to nothing, so the options object became the sixth argument
(`localGitOptions`) and `mergePR`'s seventh parameter (`options`) took its default
`{}`. `options.bypassBranchProtection === true` was therefore false, so the
preflight refused to authorise the bypass it had just been asked for and returned
the review-approval error. A WSL repo, whose options array is non-empty, was
unaffected — which is why that suite passed while the SSH/local one asserted the
shifted call as if it were the contract.

Both call sites now materialise the argument with the `[0] ?? {}` idiom the
neighbouring runtime commands already use (`runtime-github-repository-query-commands`,
`runtime-github-review-query-commands`), so the trailing options object cannot be
displaced. Nothing else moves.

The running build carries the same shape (`out/main/index.js` in Orca NP
1.4.214-np.22), and the real preflight called against #63 while it was still open
returned `{"error":null,"adminBypass":true}` — the permission was never the
problem, only the lost flag.

Verified: the new and corrected suites fail 4 of 7 with the production change
stashed and pass with it; `github-wsl-runtime-routing`, `rpc/methods/github`,
`client-pr-admin-merge-bypass` and `pr-mutation-review-invalidation` pass (68
tests); `pnpm tc` and `pnpm lint` clean; full `pnpm test` 112,892 passed / 56
failed, every failure in a class already recorded as red on this machine's base
and none of them importing the changed modules.
nplez1 added a commit that referenced this pull request Oct 9, 2026
…it options (#67)

Merging a review-gated pull request with the admin bypass failed on every attempt
from the right sidebar, and from every other surface that offers it: the
confirmation appeared, the user accepted it, and the merge was refused with "This
pull request requires review approval before it can be merged." The same merge
succeeded on github.com. Confirmed on #63 and #64, both merged by hand in the end.

`getGitHubLocalGitOptionArgs` returns `[]` when a repo has no local git options —
the ordinary case for a local checkout with no WSL routing and no gh account bound
to the repo. Both host entry points spread that array immediately before a
trailing options object:

    ...getGitHubLocalGitOptionArgs(store, repo),
    { bypassBranchProtection: args.bypassBranchProtection === true }

An empty array spreads to nothing, so the options object became the sixth argument
(`localGitOptions`) and `mergePR`'s seventh parameter (`options`) took its default
`{}`. `options.bypassBranchProtection === true` was therefore false, so the
preflight refused to authorise the bypass it had just been asked for and returned
the review-approval error. A WSL repo, whose options array is non-empty, was
unaffected — which is why that suite passed while the SSH/local one asserted the
shifted call as if it were the contract.

Both call sites now materialise the argument with the `[0] ?? {}` idiom the
neighbouring runtime commands already use (`runtime-github-repository-query-commands`,
`runtime-github-review-query-commands`), so the trailing options object cannot be
displaced. Nothing else moves.

The running build carries the same shape (`out/main/index.js` in Orca NP
1.4.214-np.22), and the real preflight called against #63 while it was still open
returned `{"error":null,"adminBypass":true}` — the permission was never the
problem, only the lost flag.

Verified: the new and corrected suites fail 4 of 7 with the production change
stashed and pass with it; `github-wsl-runtime-routing`, `rpc/methods/github`,
`client-pr-admin-merge-bypass` and `pr-mutation-review-invalidation` pass (68
tests); `pnpm tc` and `pnpm lint` clean; full `pnpm test` 112,892 passed / 56
failed, every failure in a class already recorded as red on this machine's base
and none of them importing the changed modules.
@nplez1
nplez1 deleted the nplez1/pi-status-child-session branch October 24, 2026 03:23
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