Skip to content

fix(app): clear stale waiting indicators when an aborted question never reports rejection - #4840

Merged
yomgui merged 1 commit into
devfrom
fix/stale-waiting-indicator
Sep 11, 2026
Merged

yomgui merged 1 commit into
devfrom
fix/stale-waiting-indicator

Conversation

@yomgui

@yomgui yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member

Symptom

A session that finished hours ago still shows the orange "needs you" dot in the sidebar, and session.archive is refused ("could not be confirmed" → Stop-and-archive confirmation → "A task, approval, or message acceptance is still unresolved"). Found by the workspace audit on an "E2E fix" session: 12:02 the assistant calls question; 12:05 a superseding prompt (another agent's STOP) arrives while the question is pending; the question tool part ends with state.status = "error"; the follow-up turn finishes with finish=stop; engine idle for hours; app still says waiting.

RCA (confirmed, with one correction)

Engine (confirmed, not patchable here). The engine is the upstream OpenCode binary (constants.json → v1.18.18, downloaded by apps/desktop/scripts/prepare-sidecar.mjs). In packages/opencode/src/question/index.ts (and identically permission/index.ts), ask() wraps Deferred.await in Effect.ensuring(pending.delete(id)); only an explicit reply()/reject() publishes question.replied/question.rejected. SessionProcessor.cleanup() waits 250 ms for open tool calls and then marks them error: "Tool execution aborted" without interrupting the tool fiber, so the question's deferred is never failed either. Read-only probe of the live engine while the affected session was idle:

  • GET /session/status → the session is absent (idle)
  • GET /question → still lists the session's request que_… with tool: { messageID, callID }
  • DB: that callID's tool part is state.status = "error"

So the RCA hypothesis 1 is confirmed and stronger than stated: not only is question.rejected never published, the abandoned request stays in the engine's pending list as a zombie. That rules out option (a) ("drop ids missing from the engine list") as a fix — the list is the source of the ghost.

App (corrected). Hypothesis 2 (a missed SSE idle plus the snapshot guards) is not what keeps the record waiting. setRunStatus(idle) does clear the ids, and connect-reconcile (seedSessionRun with snapshotStartedAt) heals a missed idle. The record.status !== "idle" guards in seedWorkspaceSessions/seedSessionRun are intentional: waiting + runActive=false is a legitimate state ("retains a pending question at the idle release deadline" test, v2 permissions), so they stay. What actually re-poisons the store is the zombie itself:

  • useSessionInteractions reads GET /question whenever the session (or its parent) is open and seedQuestionState re-adds the zombie → waiting again with runActive=false; nothing ever settles it.
  • useSessionArchive.readWorking reads the same list and counts the zombie as open work → archive refused forever.

Fix (option (c): the transcript is authoritative)

A question/permission can only be answered while the tool call that asked it is still running. When that call's part is completed/error, nobody can consume an answer, so the request is settled:

  • sync/orphaned-interactions.ts (new): isTerminalToolPart, terminalToolCallIds (raw parts), terminalTranscriptToolCallIds (UI transcript), isOrphanedInteraction(tool, terminal).
  • session-sync.ts: settleOrphanedInteractions() runs on live message.part.updated (before the tracked-session gate, so background sidebar rows heal too) and after each transcript snapshot; seedQuestionState/seedPermissionState treat orphaned requests as settled so a zombie list read cannot resurrect them. Settling goes through the existing settle*State path (settled set + waiting id removal), so the existing snapshot/live ordering guards are untouched.
  • use-session-archive.tsx: readWorking ignores a pending request whose tool call already ended in the fetched messages.

Requests without a tool link and requests whose tool part is still running are never touched (covered by tests).

Proof

  • apps/app: bun test --isolate tests/session-sync-orphaned-interactions.test.ts tests/session-sync-permissions.test.ts tests/session-sync-run-status.test.ts tests/session-sync-tool-parts.test.ts tests/session-sync-lifecycle.test.ts → 107 pass / 0 fail (the 6 new tests were red before the fix: 5 fail / 1 pass; the existing "does not let an older idle snapshot stop a live run" guard stays green).
  • apps/app: pnpm typecheck → clean.
  • E2E: evals/specs/abandoned-question-waiting-indicator.e2e.test.ts (new world abandonedQuestion in evals/worlds/chat.ts): real question via mock model → POST /session/:id/abort + prompt_async follow-up (what another agent's STOP does) → asserts the engine tool part ended and the session is idle, the question panel closes, the sidebar dot stops saying "Waiting" within 15 s, and Archive succeeds with no Stop-and-archive confirmation. Lane and result: see the evidence comment below.

Upstream engine item (not patchable in this repo)

Proposed issue for anomalyco/opencode:

Aborted/superseded question or permission is never rejected and stays in the pending list

When a session turn is aborted (POST /session/:id/abort) or superseded while a question (or permission) tool call is awaiting an answer, SessionProcessor.cleanup() marks the tool part error: "Tool execution aborted" but does not interrupt the tool fiber. Question.ask's Effect.ensuring(pending.delete(id)) therefore never runs: GET /question keeps listing the request after the session is idle, and no question.rejected event is published (only explicit reject() publishes one; the instance finalizer also fails deferreds silently). Clients cannot tell a live question from this leftover without cross-checking the tool part state. Same shape in Permission.ask. Suggested fix: on abort/supersede, interrupt or reject() the pending asks linked to the aborted tool calls so question.rejected / permission.replied(reject) is published and the pending map is cleaned. Observed on v1.18.18.

Coordination

Sibling branch fix/session-blocker-introspection exposes pending question/permission state to agents. This PR does not touch session-activity-store.ts; it adds one helper module and small hooks in session-sync.ts (settleOrphanedInteractions, seed filters, message.part.updated, seedSessionState) and use-session-archive.tsx. If that branch reads the engine's pending lists, it should apply the same isOrphanedInteraction filter so agents do not see the zombie either.

…er reports rejection

OpenCode 1.18 marks the tool call of a stopped or superseded turn as
errored but never publishes question.rejected / permission.replied, and an
abandoned (not interrupted) ask stays listed by GET /question. The app kept
re-seeding that zombie into the waiting set, so the sidebar showed "needs
you" for hours and Archive refused the idle session.

Treat the transcript as the authority: a pending question or permission
whose tool call part is already completed/errored is settled from live
part updates, transcript snapshots, and list seeds, and Archive no longer
counts such a request as open work.
@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 10, 2026 8:13pm UTC
openwork-den Ready Ready Preview Sep 10, 2026 8:13pm UTC
openwork-diagnostics Ready Ready Preview Sep 10, 2026 8:13pm UTC
openwork-landing Ready Ready Preview, v0 Sep 10, 2026 8:13pm UTC

@yomgui

yomgui commented Sep 10, 2026 •

Copy link
Copy Markdown
Member Author

Passed · 12/12 tests · 18/18 assertions · 8 images

Commit 5e7b16f491e7a25e26dd578bfa1dac424f76f95b · selected evidence

Open review report

@github-actions

Copy link
Copy Markdown
Contributor

Warden review summary — Clear

Native findings: 0. Blocking policy matches before consolidation: 0. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run

Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (70221 ms), confidentiality-review (78383 ms), spec-provenance-review (87263 ms), desktop-den-sync-review (105908 ms).

Blockers

  • None.

Advisories

  • None.

Needs recheck

  • None.

Observed review-thread metrics

  • Unique observed run attempts in retained window: 1
  • Distinct heads in retained window: 1
  • Current unresolved Warden threads: 0 of 0 observed
  • Observed resolved/unresolved transitions in retained snapshots: 0 / 0
  • First observed resolved/unresolved (state at first collection, not event time): 0 / 0
  • Precision: unavailable (no adjudications; no TP/FP values are inferred)
  • Observation window: 1/20 run attempts retained; truncated: false
  • Transition snapshot: 0/0 current attributed threads retained (limit 500); truncated: false

Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority.

@diff-warden diff-warden 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.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (5e7b16f491e7a25e26dd578bfa1dac424f76f95b). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@yomgui

yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Coordinated with #4843: session attention reads and both question-proposal load/confirmation now cross-check a fresh owner transcript with the same isOrphanedInteraction/terminalToolCallIds helper. The helper is included at the same sync/orphaned-interactions.ts path and is byte-identical to 5e7b16f (blob 60a55c648a697ca6155a9fc8f6e14fcb2ba3aa90). No changes to session-sync.ts, session-activity-store.ts, or use-session-archive.tsx, and no changes to this PR's branch. Running/unlinked requests stay eligible; transcript failures fail closed. 32 focused cases pass; a new real v1 abort/supersede zombie E2E is being verified on the pushed #4843 head. #4843 remains draft for its separate native-v2 host-tool exposure blocker.

@yomgui

yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Follow-up proof on #4843 head 3fe27d1: the real v1 zombie E2E passed on Daytona. It requires the unchanged request to remain in GET /question after abort/supersede, verifies fresh session.attention filters it, then confirms an already-staged answer and observes rejected/sent=false. Normal v1 reply E2E also passed. Shared helper remains byte-identical to your 5e7b16f; no seed/store guard changes from this feature. Current-head CI passed and Warden approved; #4843 stays draft for the separate native-v2 host-tool integration gap.

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — 5e7b16f4 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-diagnostics — 5e7b16f4 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-den — 5e7b16f4 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-app — 5e7b16f4 Deployed Sep 10, 2026 by vercel[bot]
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