Skip to content

fix(agent-status): keep a hook question from a stale program working report - #32156

Merged
nwparker merged 4 commits into
stablyai:mainfrom
maxmilian:fix/pi-ask-user-waiting-stale-working
Oct 24, 2026
Merged

nwparker merged 4 commits into
stablyai:mainfrom
maxmilian:fix/pi-ask-user-waiting-stale-working

Conversation

@maxmilian

@maxmilian maxmilian commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Pi asks a question, its row could change from Waiting to Working while the question was still open. Orca was replaying the program's older working status on a lease renewal. The hook question now stays waiting until the user answers or a later program transition proves work resumed.

What Changed

A hook row in waiting or blocked now takes precedence over an older program working report without a silence deadline. A genuine transition into working after the hook event takes over immediately, using the existing ProgramStatusFacetStore.workingSince evidence. Other state pairs retain the two-minute silence fallback.

Fixes #32066

Verification

  • Reproduced on fresh main 92dfb4fda69e before production edits by copying only the original author's regression tests. Through the real AgentHookServer and /hook/pi, a clock-controlled 10-minute renewal plus two-minute silence overwrote the open question. The genuine resume case also failed. All three new regressions failed; 28 existing cases passed.
  • After adopting the author fix on committed head 15496722e411, all 136 tests across 12 relevant server, precedence, facet/timer, terminal-ingest, Pi prompt and OSC program-status suites pass.
  • Targeted typecheck passes over the production precedence file, its predicate test and their full 628-file import/type graph using the repository node options. Full server/project and platform validation remain with fresh CI.
  • Formatting, changed-code-quality (zero new findings across three files) and git diff --check pass.
  • Independent adversarial source and validation review at 15496722e411 found no blockers. All 136 tests in the same 12 suites passed again after review on the committed, clean head.

The maintainer replay exercises production HTTP ingestion, the real status projection, renewal provenance and timers with a controlled clock. It does not launch Pi or claim a new wall-clock 12-minute desktop run. The original author's rendered replay evidence is preserved below.

Visual Proof

Dev builds of main and this branch, each with its own profile. In a terminal pane, a script replays Pi's wire for an ask_user question using the pane's own hook env: OSC 7501 state=working:app=pi, then the Pi extension's agent_start and ui_prompt_start hooks, then nothing while the question waits. The app's real 10-minute lease renewal then re-sends the working report. Each build is captured right after the replay and again after the renewal.

Right after the question After the 10-minute lease renewal
Before (main) before, right after the question: row waiting before, after the renewal: row shows Working while the tab still says action required
After (this PR) after, right after the question: row waiting after, 12 minutes later: row still waiting

On main the row flipped to "Working - Pi" at the renewal (10:00 after the turn started), while the tab title still said "Pi - action required", as reported. With this branch the row was still waiting at 12 minutes, past the renewal.

Risk and Compatibility

Merge risk: low, following independent adversarial source/evidence review and post-review verification. Required fresh CI remains pending. If an agent misses the question-end hook and never transitions out of its old working state, its hook question can now stay waiting until another hook/lifecycle cleanup event. Current Pi prompt-end, session-change and PTY teardown paths remain unchanged. This is the conservative tradeoff that keeps an unanswered question visible.

The rule is shared by all agents with hook and OSC status. It changes only main-process precedence; no paths, shells, platform APIs, persistence, IPC/wire fields or mobile/remote contracts change. Local, SSH/WSL and folder workspaces use the same ingestion path. Older hosts keep their previous precedence until upgraded. Infinite yields cancel the existing silence recheck rather than scheduling repeated work.

Author and AI Disclosure

Original investigation, implementation, tests and attached desktop replay by Max Hsu (@maxmilian), preserved in commit b414cf277d3a. Original work used Claude Code as disclosed by the author. Maintainer current-main reproduction, verification and independent adversarial review used native Codex agents.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer source or resources are copied or translated.

Checklist

  • Current-main bug reproduced before adopting the production fix
  • Original author, history and screenshots retained
  • Meaningful real-server regression and neighboring behavior checked
  • Cross-platform, remote, mobile and folder-workspace effects considered
  • Independent adversarial review and post-review verification
  • Required fresh CI passes

…report

Pi reports no blocked status for ctx.ui.custom() dialogs such as ask_user, so
its OSC 7501 status stays working through the question. The 10-minute lease
renewal re-sent that working, and once the hooks had been silent for two
minutes it replaced the hook row's waiting.

A waiting or blocked hook row now yields to a program working report until
the program enters working after the hook event, mirroring the done/waiting
case.
@maxmilian
maxmilian marked this pull request as ready for review October 23, 2026 02:59
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5206ba2e-e058-4696-957b-f9a2d54ebfdc
Commits

Reviewing files that changed from the base of the PR and between b414cf2 and 22d3017.

Files selected for processing: 3
  • src/main/agent-hooks/server-program-status-hook-yield.test.ts
  • src/main/agent-hooks/server/program-status/hook-precedence.test.ts
  • src/main/agent-hooks/server/program-status/hook-precedence.ts
Walkthrough

The change updates programStatusHookYieldEndsAt for a program working report after a hook reports waiting or blocked. A newer program report ends the hook yield; otherwise, the yield has no end. Tests cover the waiting row during hook silence and lease renewal, its return to working after ui_prompt_end, and program status transitions.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to b414c

A reconnect can leave an agent incorrectly shown as waiting after it resumes work. Preserve the replay’s original evidence time and correct precedence before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "fix(agent-status): keep a hook question from a stale program working report" describes the main change: a stale OSC 7501 working report from the program no longer replaces a hook row that…
Linked Issues check Passed Issue #32066 is an active direct issue. The change updates programStatusHookYieldEndsAt so a hook row in waiting or blocked remains authoritative when OSC 7501 reports stale working. A newer p…
Out of Scope Changes check Passed The reviewed changes are limited to hook/program precedence and automated tests for that behavior. The tests directly support issue #32066 and preserve the existing two-minute rule for other state pai…
Description check Passed The description follows the repository template closely: it has ELI5, What Changed, Why (via Risk and Compatibility), Linked Issue (Fixes #32066), Visual Proof with before/after images, Testing/Verifi…
Full details: Title check

Explanation

The title "fix(agent-status): keep a hook question from a stale program working report" describes the main change: a stale OSC 7501 working report from the program no longer replaces a hook row that shows a question as waiting. It names the affected area (agent-status) and the fix. It is specific and in line with the changeset, which modifies hook/program status precedence in hook-precedence.ts and adds tests for it.

Full details: Linked Issues check

Explanation

Issue #32066 is an active direct issue. The change updates programStatusHookYieldEndsAt so a hook row in waiting or blocked remains authoritative when OSC 7501 reports stale working. A newer program entry into working still takes the row. Tests cover the Pi ask_user sequence, the 10-minute lease renewal, hook silence, ui_prompt_end, and later program work. The generic ingest path also avoids a Pi-only implementation.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to hook/program precedence and automated tests for that behavior. The tests directly support issue #32066 and preserve the existing two-minute rule for other state pairs. No unrelated product behavior or unrelated files are shown in the supplied change summary.

Full details: Description check

Explanation

The description follows the repository template closely: it has ELI5, What Changed, Why (via Risk and Compatibility), Linked Issue (Fixes #32066), Visual Proof with before/after images, Testing/Verification, AI Disclosure, the upstream boundary checkbox, and a checklist. The main gap is the Why section: it does not clearly state why this approach was chosen over alternatives, and the template's Testing checkboxes are not ticked in the expected form. The final CI checkbox is intentionally left open, and the author states CI is still pending.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73b793d6-9098-4d02-8944-e26b1a494f2c
📥 Commits

Reviewing files that changed from the base of the PR and between 3ef3ab9 and b414cf2.

📒 Files selected for processing: 3
  • src/main/agent-hooks/server-program-status-hook-yield.test.ts
  • src/main/agent-hooks/server/program-status/hook-precedence.test.ts
  • src/main/agent-hooks/server/program-status/hook-precedence.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +43 to +45
return programWorkingSince !== undefined && programWorkingSince > previous.receivedAt
? undefined
: Infinity

@coderabbitai coderabbitai Bot Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '105,150p' src/main/agent-hooks/server/server-ingest-normalization.ts
sed -n '35,85p' src/main/agent-hooks/server/server-status-update.ts
sed -n '245,305p' src/main/agent-hooks/server/server-status-update.ts
sed -n '155,195p' src/main/agent-hooks/server/server-status-application.ts
sed -n '195,275p' src/main/agent-hooks/server/server-ingest-terminal.ts

Repository: stablyai/orca

Length of output: 11603


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- precedence ---'
nl -ba src/main/agent-hooks/server/program-status/hook-precedence.ts | sed -n '1,90p'
printf '%s\n' '--- replay normalization and apply caller ---'
nl -ba src/main/agent-hooks/server/server-ingest-normalization.ts | sed -n '1,155p'
printf '%s\n' '--- replay/status disposition declarations and uses ---'
rg -n -F --glob '*.ts' -e 'getAgentStatusDisposition' -e 'applySpoolHook' -e 'attachStatusTiming' -e 'resolveEvidenceObservedAt' src/main/agent-hooks/server
printf '%s\n' '--- status application timing block ---'
nl -ba src/main/agent-hooks/server/server-status-application.ts | sed -n '150,215p'
printf '%s\n' '--- terminal ingest acceptance block ---'
nl -ba src/main/agent-hooks/server/server-ingest-terminal.ts | sed -n '175,275p'

Repository: stablyai/orca

Length of output: 20954


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- status application entry ---'
nl -ba src/main/agent-hooks/server/server-status-application.ts | sed -n '80,155p'
printf '%s\n' '--- status disposition ---'
nl -ba src/main/agent-hooks/server/server-status-disposition.ts | sed -n '1,115p'
printf '%s\n' '--- spool record/body contract ---'
rg -n -F --glob '*.ts' -e 'export type SpoolRecord' -e 'interface SpoolRecord' -e 'buildSpoolHookBody' -e 'receivedAt' src/shared src/main/agent-hooks/server | head -120
nl -ba src/shared/agent-hook-spool.ts | sed -n '1,180p'
printf '%s\n' '--- terminal ingest entry ---'
nl -ba src/main/agent-hooks/server/server-ingest-terminal.ts | sed -n '1,175p'

Repository: stablyai/orca

Length of output: 38823


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- complete hook application block ---'
nl -ba src/main/agent-hooks/server/server-status-application.ts | sed -n '120,225p'
printf '%s\n' '--- legacy admission implementation ---'
rg -n -F --glob '*.ts' -e 'function admitLegacyAgentStatus' -e 'admitLegacyAgentStatus' src/main src/shared

Repository: stablyai/orca

Length of output: 6379


🏁 Script executed:

nl -ba src/shared/agent-hook-listener/listener-state.ts | sed -n '120,205p'

Repository: stablyai/orca

Length of output: 3552


🏁 Script executed:

set -o pipefail
rg -n -F --glob '*.ts' -e 'class LegacyStatus' -e 'legacyStatusAdapter' -e 'admit(caller' -e 'canAdmit(caller' src/shared src/main

Repository: stablyai/orca

Length of output: 1395


🏁 Script executed:

nl -ba src/shared/agent-status-legacy-adapter.ts | sed -n '1,210p'

Repository: stablyai/orca

Length of output: 8472


🏁 Script executed:

set -o pipefail
rg -n -F --glob '*.ts' -e 'payload: ' -e 'receivedAt:' -e 'append.*spool' -e 'write.*spool' -e 'AGENT_HOOK_SPOOL' src/main src/shared | rg -C 3 'spool|receivedAt'

Repository: stablyai/orca

Length of output: 41202


Preserve the replay’s original evidence time.

A reconnect replay can be admitted and stored after a newer working transition. The replay gets a later receivedAt. A later repeated working report can then compare its retained workingSince with that later arrival and return Infinity, leaving the stale hook row authoritative.

The precedence-only change is insufficient. buildSpoolHookBody drops the spool record’s original timestamp, so replay timing derives evidenceObservedAt from the current row or remembered map. Preserve the replay’s original evidence time when constructing the replay, then compare evidenceObservedAt ?? receivedAt here. Add a reconnect test for this sequence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, verified locally. Spool replays get receivedAt = now: buildSpoolHookBody (src/shared/agent-hook-spool.ts:33-48) drops the record's time, and applySpoolHook calls applyNormalizedStatus without an observedAt (server-ingest-normalization.ts:140). So a superseded waiting/blocked hook replayed after the program entered working can hold the row until the agent's next hook event.

On a normal restart I couldn't reach it. The spool drains before the listener binds (server-status-hook-lifecycle.ts:46) and before terminals reconnect, so the facet store is empty. The program's first working after the replay then sets workingSince = now (facet-store.ts:59), which is newer than the replay, and the program takes the row. It is reachable when status hooks are switched on mid-session (main-process-ready-foundation.ts:258), because the first drain then runs against live OSC 7501 state. In a local repro of that sequence, the row stayed waiting across lease renewals; before this PR it recovered through the 2-minute rule.

Comparing evidenceObservedAt ?? receivedAt alone doesn't close it. For a spool replay, evidenceObservedAt comes from the previous row (server-status-application.ts:203), not the spooled time, and in the repro it equals workingSince. Passing the spool time as observedAt would also restamp stateStartedAt, turn timing and observation order for every replay (server-status-update.ts:283-284). Spool stamps are also whole seconds, which could reopen #32066 inside that window.

The same comparison already exists in the done → waiting branch from #32015 (hook-precedence.ts:32-36). I'd suggest fixing both together in a follow-up that carries the spool time into evidenceObservedAt only, with a little slack, rather than widening this PR. I'm happy to do it here instead if the maintainers prefer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxmilian Thanks for the detailed reproduction. My original reconnect description was too broad. Your results identify mid-session hook enablement against live OSC 7501 state as the reachable case, rather than normal restart.

I agree that changing the comparison alone is insufficient. The replay must first carry its own evidence time. Using that time as observedAt would also change timing fields outside this precedence decision.

A focused follow-up for both precedence branches is reasonable. It should:

  • Carry the spool timestamp into evidenceObservedAt without changing replay arrival or turn timing.
  • Define and test a tolerance for whole-second spool timestamps.
  • Cover mid-session hook enablement, lease renewals, and the timestamp boundary that could regress #32066.

The reported regression remains unresolved, so this finding stays open. Maintainers can decide whether to accept it as a follow-up rather than expand this PR.

Would you like me to open a follow-up GitHub issue with these acceptance criteria?

You are interacting with an AI system.

…dates it

Only a program working that began before the hook question is stale; a later working
transition, or one without facet ordering evidence, keeps the existing silence fallback.
@nwparker

Copy link
Copy Markdown
Contributor

Maintainer follow-up (22d3017, merged current main):

  • Narrowed the precedence change to the stale case only. A waiting/blocked hook row now ignores an OSC working only when the program's workingSince (ProgramStatusFacetStore) is at or before the hook question's receivedAt, which is what happens when the lease renewal re-sends an older working.
  • Everything else keeps current main's behavior. A working transition after the question, or a report with no facet ordering evidence, uses the existing two-minute silence fallback and is no longer an immediate override. Every other state pair is unchanged.
  • The rule stays agent-agnostic because the stale-ordering evidence is agent-independent. Agents whose OSC 7501 reports their own question state (e.g. Claude) never hit it, because their renewal re-sends blocked/waiting, not working.
  • Tests were updated to match. 119 tests across the hook-yield, precedence, facet and ingest suites pass.

@nwparker
nwparker merged commit fdb7e12 into stablyai:main Oct 24, 2026
55 of 57 checks passed
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.

[Bug]: A Pi ask_user question flips back to Working after a few minutes

2 participants