From 470a68f65868229285fb13daa22bafbfc83d8e55 Mon Sep 17 00:00:00 2001 From: OrwellVII <56531592+OrwellVII@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:26:18 +0800 Subject: [PATCH] fix(rpc): clear the awaiting-input mark when a reload drops pending dialogs #461 marks a running session as awaitingInput while its wrapper holds a pending dialog and broadcasts from forgetPendingUiRequest. The other removal path, clearPendingUiRequests (reload, destroy), dropped every pending dialog without broadcasting. destroy and a successful reload broadcast afterwards, but a reload whose replacement spawn fails threw past its final notifyRunningChange, so the sidebar kept the session running and waiting on a dialog that no longer exists until some unrelated change. clearPendingUiRequests now broadcasts when it drops anything, like forgetPendingUiRequest. Also covers the two settlement paths raised in review of #319: a host resync that clears dialogs before a get_state reconcile that then fails, and a dialog found expired when replayed to a new tab. Both already clear through forgetPendingUiRequest; the tests fail if that broadcast is removed, which the existing answer-path test does not catch. Supersedes #319, whose sidebar marking predates the host/daemon architecture and was replaced by #461. --- AGENTS.md | 1 + CHANGELOG.md | 2 +- lib/rpc-manager.test.mjs | 71 ++++++++++++++++++++++++++++++++++++++++ lib/rpc-manager.ts | 3 ++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 7593b18c1..57c942b8e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1438,6 +1438,7 @@ during the wait. ### Running state + reconciliation - The sidebar subscribes to the `running` channel, backed by `subscribeRunningSessions()` in `lib/rpc-manager.ts`, so running badges update without polling. +- `runningSessions` entries carry `awaitingInput` while the wrapper's `pendingUiRequests` is non-empty. Every removal broadcasts a running change (`forgetPendingUiRequest` per dialog, `clearPendingUiRequests` for reload/destroy), so a new path that drops dialogs must go through one of them or the sidebar keeps the mark. - An open chat subscribes to `running` too: when its session shows up there while the chat has no `session` stream (the run started after the chat loaded: another tab or device, or a send from a chat instance the user switched away from), it reads `GET /api/agent/[id]` and attaches exactly as on load (`attachLiveRun`). Without it the chat stayed idle beside a running badge until a reload. - The lookup waits for the chat's own work: its mount load while in flight (a stream attached before that load lands would make its `agent_start` drop the load), a stream of its own still connecting (its readiness wait can still fail and close it), and a local send, `!` command, Edit or manual compaction until it settles. The frame is kept meanwhile, and the operation's release rechecks it (`runningRecheckRef`). A local operation that starts during the lookup makes its answer stale (one generation per operation kind). A failed lookup is retried after 1, 2 and 4 s. - Compaction state has one owner at a time. A manual compaction this tab sends holds it until its command settles (`localCompactionsRef`): omp may not have the command yet, so an idle snapshot cannot release it; when it settles during an auto-compaction (`autoCompactingRef`), the control stays with the auto-compaction. Native snapshots (state polls, catch-up, attach, mount) apply only if no compaction started or ended since they were requested (`compactionGenRef`); `setCompacting` keeps `isCompactingRef` and the rendered state together. diff --git a/CHANGELOG.md b/CHANGELOG.md index 62801f331..8f7cb7043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **Traditional Chinese (`zh-TW`) interface language.** Select Traditional Chinese (繁體中文) in the top-bar language menu. On compact layouts, open **More controls** first. Alternatively, let omp-web pick it automatically when the browser language is `zh-TW`, `zh-HK`, `zh-MO`, or `zh-Hant`. Localized Web Push notifications and a Traditional Chinese README (`README.zh-TW.md`) are included. - **Several web apps can share one host daemon and the same live sessions.** Link additional servers with `ompweb host login --add --url ` (token from stdin). Prompts, tool progress, results and dialogs stay synchronized, and restarting one web app leaves the other connected to the same omp process. Link protocol v7 moves session startup, idle cleanup and interrupted-run recovery into the host; older links remain supported without sharing their processes. Schedule the first daemon upgrade while its host is quiescent. - **Sidebar marks sessions with an unsent draft.** A session whose composer still holds text or attachments shows a small pencil beside its title, so a half-written message is easy to find again. The mark follows this browser tab's drafts. -- **Sidebar marks sessions waiting for your input.** A session with an open question, confirmation or other blocking dialog shows a small question-bubble icon beside its title, next to the unsent-draft pencil. The mark clears as soon as the dialog is answered, cancelled or expires, in every open browser. +- **Sidebar marks sessions waiting for your input.** A session with an open question, confirmation or other blocking dialog shows a small question-bubble icon beside its title, next to the unsent-draft pencil. The mark clears as soon as the dialog is answered, cancelled or expires, or a reload drops it (even one that then fails to restart omp), in every open browser. - **Identify untagged builds from the logo.** Clicking or tapping the ompweb logo still reveals the version; builds made from an untagged Git commit also show its full hash and commit date (`YYYY-MM-DD`). Builds made on a tag keep the version-only display. The metadata is embedded in the browser bundle, so installed packages and binaries do not need Git. - **Workspace file APIs run on the owning host.** Directory listings, file metadata and previews, downloads, file search and referenced shell output go through that machine's daemon, including This machine. File downloads stream in bounded chunks rather than being limited by the host link's per-result size. A stopped or older daemon reports unavailable or unsupported instead of reading a path on the web server. - **File tabs keep their owning workspace.** Files with the same path on different hosts open in separate tabs. Switching chats does not redirect a tab's reads, Markdown links, images or downloads to the new host. Explorer and composer file suggestions follow the selected host, and confirming an agent's file-open request keeps that request's source host. Mention and reveal actions are disabled while the active chat belongs to another host. diff --git a/lib/rpc-manager.test.mjs b/lib/rpc-manager.test.mjs index 7f8b28a23..f68e419ff 100644 --- a/lib/rpc-manager.test.mjs +++ b/lib/rpc-manager.test.mjs @@ -3038,6 +3038,77 @@ test("a session with an open dialog is listed as awaiting input until the dialog assert.equal(pushed.at(-1), false, "answering clears the mark without waiting for another omp frame"); }); +/** The `running` broadcasts' latest entry for `id` (undefined once it is no longer running). */ +function runningBroadcasts(t, subscribeRunningSessions, id) { + const pushed = []; + t.after(subscribeRunningSessions((update) => pushed.push(update.runningSessions.find((running) => running.id === id)))); + return { pushed, awaiting: () => pushed.at(-1)?.awaitingInput === true }; +} + +test("a host resync whose get_state read fails still clears the awaiting-input mark", async (t) => { + const { adoptRpcSession, getRunningRpcSessions, subscribeRunningSessions } = await import("./rpc-manager.ts"); + const { until } = await import("./hosts/link-driver.test-helper.mjs"); + const id = "11111111-2222-4333-8444-adadadadad40"; + const transport = adoptedTransport(id, { state: { isStreaming: true } }); + // A shared daemon channel: omp-web only leaves it, and a resync clears its replayed dialogs. + transport.hostOwnedLifecycle = true; + transport.close = () => queueMicrotask(() => transport.exit?.(null, null)); + let resync; + transport.onResync = (listener) => { resync = listener; }; + const session = await adoptRpcSession({ host: adoptionHost("resync-await-box", transport), transport, sessionId: id, cwd: "/w", replay: [], advisorSpawned: false }); + t.after(() => session.destroyAndWait()); + const { pushed, awaiting } = runningBroadcasts(t, subscribeRunningSessions, id); + transport.emit(JSON.stringify({ type: "extension_ui_request", id: "q", method: "confirm", title: "Continue?", message: "" })); + assert.equal(awaiting(), true); + // After the gap omp's state cannot be read: only the resync's own clearing tells the sidebar. + const answer = transport.answer; + let stateRead = false; + transport.answer = (command, reply) => { + if (command.type !== "get_state") return answer(command, reply); + stateRead = true; + return answer(command, { success: false, error: "link lost" }); + }; + const before = pushed.length; + resync(); + await until(() => stateRead, "the reconcile's get_state"); + await flushWrites(); + assert.notEqual(getRunningRpcSessions().find((running) => running.id === id)?.awaitingInput, true); + assert.ok(pushed.length > before, "the resync broadcast a running change"); + assert.equal(awaiting(), false, "the cleared dialog does not leave the sidebar waiting"); +}); + +test("a dialog that expired before a tab attached clears the awaiting-input mark on replay", async (t) => { + const { adoptRpcSession, subscribeRunningSessions } = await import("./rpc-manager.ts"); + const id = "11111111-2222-4333-8444-adadadadad41"; + const transport = adoptedTransport(id, { state: { isStreaming: true } }); + const session = await adoptRpcSession({ host: adoptionHost("replay-expiry-box", transport), transport, sessionId: id, cwd: "/w", replay: [] }); + t.after(() => session.destroyAndWait()); + const { awaiting } = runningBroadcasts(t, subscribeRunningSessions, id); + // Only the clock moves: the expiry timer has not fired, so the replay is what finds the dialog expired. + t.mock.timers.enable({ apis: ["Date"], now: Date.now() }); + transport.emit(JSON.stringify({ type: "extension_ui_request", id: "q", method: "input", title: "Value", timeout: 60_000 })); + assert.equal(awaiting(), true); + t.mock.timers.tick(60_001); + const replayed = []; + session.onEvent((event) => replayed.push(event)); + assert.deepEqual(replayed.filter((event) => event.type === "extension_ui_request"), []); + assert.equal(awaiting(), false); +}); + +test("a reload that fails to spawn clears the awaiting-input mark of the dialog it dropped", async (t) => { + const { getRunningRpcSessions, subscribeRunningSessions } = await import("./rpc-manager.ts"); + const transport = scriptedTransport("s-reload-await"); + const host = scriptedHost("reload-await-box", transport); + const { session } = await runningRemoteSession(t, "s-reload-await", transport, host); + const { awaiting } = runningBroadcasts(t, subscribeRunningSessions, "s-reload-await"); + transport.emit(JSON.stringify({ type: "extension_ui_request", id: "q", method: "confirm", title: "Continue?", message: "" })); + assert.equal(awaiting(), true); + host.spawnRpc = async () => { throw new Error("spawn failed"); }; + await assert.rejects(session.send({ type: "reload" }), /spawn failed/); + assert.notEqual(getRunningRpcSessions().find((running) => running.id === "s-reload-await")?.awaitingInput, true, "the dialog went with the old child"); + assert.equal(awaiting(), false, "the sidebar is told, not left waiting on a dialog nobody can answer"); +}); + test("a reload whose host drops while the old child exits fails host_offline and spawns nothing beside it", async () => { const { getRpcSession, startRpcSession } = await import("./rpc-manager.ts"); let emitLine; diff --git a/lib/rpc-manager.ts b/lib/rpc-manager.ts index 311ebf67e..fa933eddc 100644 --- a/lib/rpc-manager.ts +++ b/lib/rpc-manager.ts @@ -1487,7 +1487,10 @@ export class AgentSessionWrapper { this.dropServerUiRequests(); for (const timer of this.uiExpiryTimers.values()) clearTimeout(timer); this.uiExpiryTimers.clear(); + // Like forgetPendingUiRequest: a reload whose spawn then fails broadcasts nothing else. + if (this.pendingUiRequests.size === 0) return; this.pendingUiRequests.clear(); + notifyRunningChange(); } /** Settle every server dialog as declined and close it in attached tabs. */