Repository navigation
fix(agent-status): keep a hook question from a stale program working report - #32156
Conversation
…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.
|
Warning Review limit reachedYou'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. View limit details
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
There was a problem hiding this comment.
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
📒 Files selected for processing: 3
src/main/agent-hooks/server-program-status-hook-yield.test.tssrc/main/agent-hooks/server/program-status/hook-precedence.test.tssrc/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.
| return programWorkingSince !== undefined && programWorkingSince > previous.receivedAt | ||
| ? undefined | ||
| : Infinity |
There was a problem hiding this comment.
🎯 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.tsRepository: 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/sharedRepository: 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/mainRepository: 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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
evidenceObservedAtwithout 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.
|
Maintainer follow-up (22d3017, merged current main):
|
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
waitingorblockednow takes precedence over an older programworkingreport without a silence deadline. A genuine transition intoworkingafter the hook event takes over immediately, using the existingProgramStatusFacetStore.workingSinceevidence. Other state pairs retain the two-minute silence fallback.Fixes #32066
Verification
92dfb4fda69ebefore production edits by copying only the original author's regression tests. Through the realAgentHookServerand/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.15496722e411, all 136 tests across 12 relevant server, precedence, facet/timer, terminal-ingest, Pi prompt and OSC program-status suites pass.git diff --checkpass.15496722e411found 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
mainand this branch, each with its own profile. In a terminal pane, a script replays Pi's wire for anask_userquestion using the pane's own hook env: OSC 7501state=working:app=pi, then the Pi extension'sagent_startandui_prompt_starthooks, then nothing while the question waits. The app's real 10-minute lease renewal then re-sends theworkingreport. Each build is captured right after the replay and again after the renewal.On
mainthe 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
workingstate, 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
Checklist