qingnian108's follow-up to #747 and #758, on top of 1.3.2.
- A permission request still open when its turn ends is cancelled by the
daemon (manager and ACP session both), and an ACP request the Agent
withdraws ($/cancel_request, through the handler's AbortSignal) closes
as cancelled. The page waits only on cards that still show buttons, so
a finished turn no longer leaves 等待授权 with nothing to click. The
等待授权 pill scrolls to the waiting card.
- 添加到对话 uses a speech-bubble icon.
- Sidebar dot: blinks while running, green after a completed turn, red
on failure, amber while waiting.
- Wrapper: every disconnect / invalid-link end state offers Reconnect;
the last safe back URL is kept in sessionStorage (safeBack re-checked
on read). Coming back to the page (visible / focus) probes the child
for 4 s instead of waiting out timers pushed back while hidden.
Review (head 0c8ee32b): every changed source line read. 1.3.2's Codex
model_catalog_json change is kept (codex/provider.ts untouched, rebuilt
dist still carries it). No new network in tests, page text set through
textContent/React, no new timers in the page or daemon; the wrapper's
sessionStorage back passes the same loopback check (tested with an evil
stored value).
Run (mote, macOS), standalone copy of packages/agent-console:
- npm ci; npm run check OK.
- vitest: 65 files, 489 passed / 17 skipped.
- npm run build, then verify:build: committed app/ and daemon/dist
identical to the rebuild.
On the PR merged onto main 5026f636: root `bun test
packages/agent-console` 6/6, `bun scripts/check.mjs` exit 0.
Not tried: scripts/e2e-v1.mjs (Playwright, scenario 28), the page with a
live Cursor/Claude/Codex, Windows/Linux.
89 lines
5.0 KiB
TypeScript
89 lines
5.0 KiB
TypeScript
// Nolan, Cursor on 1.2.0: the top bar said 等待授权 and the composer was locked ("等待你确认上面的授权请求"), but no card
|
|
// in the timeline had buttons. His timeline had one permission_request (seq 501) with no permission_resolved: Cursor's
|
|
// stream died ("[canceled] http/2 stream closed … CANCEL") right after asking and the turn ended "completed"; the daemon
|
|
// kept the request in its pending list, threads.get handed it to the page, and the card (thread idle) showed 已取消.
|
|
import { describe, it, expect } from "vitest";
|
|
import { applyEvent, newTimelineState, pendingRequests, reduceTimeline, type DisplayItem } from "../../web/src/timeline/reducer.js";
|
|
import { foldTimeline, TOOL_COLLAPSE_AT } from "../../web/src/timeline/fold.js";
|
|
|
|
type Ev = Record<string, unknown>;
|
|
let seq = 0;
|
|
const tl = (evs: Ev[]) => evs.map((e) => ({ seq: ++seq, ts: seq, threadId: "t", ...e })) as never[];
|
|
const tool = (itemId: string, extra: Ev = {}): Ev => ({ type: "tool_call", itemId, kind: "search", title: `search ${itemId}`, status: "ok", ...extra });
|
|
const perm = (requestId: string): Ev => ({
|
|
type: "permission_request", requestId, title: "`git status -sb; git diff --stat`", kind: "execute",
|
|
options: [{ id: "allow-once", label: "Allow", kind: "allow_once" }, { id: "allow-always", label: "Always", kind: "allow_always" }, { id: "reject-once", label: "Reject", kind: "reject_once" }],
|
|
});
|
|
const permItem = (items: DisplayItem[], id: string) =>
|
|
items.find((i) => i.kind === "permission" && i.requestId === id) as Extract<DisplayItem, { kind: "permission" }> | undefined;
|
|
|
|
// The shape of Nolan's thread t_mw1ubvax40e6cd around seq 501, then later turns that ran normally
|
|
const nolan = () => tl([
|
|
{ type: "user_message", text: "看下状态" },
|
|
{ type: "turn_started", turnId: "u_1" },
|
|
tool("a"),
|
|
perm("pmp09ibgx"),
|
|
{ type: "assistant_message", itemId: "m1", text: "Error: RetriableError: [canceled] http/2 stream closed with error code CANCEL (0x8)" },
|
|
{ type: "turn_ended", turnId: "u_1", status: "completed" },
|
|
{ type: "user_message", text: "继续" },
|
|
{ type: "turn_started", turnId: "u_2" },
|
|
perm("pjhfg5zac"),
|
|
{ type: "permission_resolved", requestId: "pjhfg5zac", optionId: "allow-always" },
|
|
tool("b"),
|
|
{ type: "turn_ended", turnId: "u_2", status: "completed" },
|
|
]);
|
|
|
|
describe("a permission request left open by an ended turn (等待授权 with no card)", () => {
|
|
it("replaying 1.2 history: the orphan closes at its turn end, so nothing waits — even while a later turn runs", () => {
|
|
for (const runtimeStatus of ["idle", "running"]) {
|
|
const { items } = reduceTimeline(nolan(), { runtimeStatus });
|
|
expect(permItem(items, "pmp09ibgx")?.status).toBe("cancelled");
|
|
expect(permItem(items, "pjhfg5zac")?.status).toBe("resolved");
|
|
expect(pendingRequests(items)).toEqual([]);
|
|
}
|
|
});
|
|
|
|
it("live: the turn_ended event alone closes it (before the idle status arrives)", () => {
|
|
const st = newTimelineState();
|
|
const evs = nolan();
|
|
for (const e of evs.slice(0, 4)) applyEvent(st, e);
|
|
expect(pendingRequests(st.items).map((p) => p.requestId)).toEqual(["pmp09ibgx"]);
|
|
for (const e of evs.slice(4, 6)) applyEvent(st, e);
|
|
expect(pendingRequests(st.items)).toEqual([]);
|
|
});
|
|
|
|
it("a request of the running turn still waits, and its card has the key the top bar scrolls to", () => {
|
|
const { items } = reduceTimeline(tl([
|
|
{ type: "user_message", text: "x" }, { type: "turn_started", turnId: "u_3" }, tool("c"), perm("live1"),
|
|
]), { runtimeStatus: "running" });
|
|
expect(pendingRequests(items)).toEqual([{ requestId: "live1", kind: "permission", key: "perm:live1" }]);
|
|
expect(items.some((i) => i.key === "perm:live1")).toBe(true);
|
|
});
|
|
|
|
it("a cancelled question closes too (the daemon cancels questions with permission_resolved{cancelled})", () => {
|
|
const { items } = reduceTimeline(tl([
|
|
{ type: "turn_started", turnId: "u_4" },
|
|
{ type: "question", requestId: "q1", questions: [{ id: "a", question: "?" }] },
|
|
{ type: "permission_resolved", requestId: "q1", cancelled: true },
|
|
]), { runtimeStatus: "running" });
|
|
expect(pendingRequests(items)).toEqual([]);
|
|
});
|
|
|
|
it("a pending card is never folded into a tool run, however long the run", () => {
|
|
const run = (p: string, n: number) => Array.from({ length: n }, (_, i) => tool(`${p}${i}`));
|
|
const { items } = reduceTimeline(tl([
|
|
{ type: "turn_started", turnId: "u_5" },
|
|
...run("x", TOOL_COLLAPSE_AT + 3),
|
|
{ type: "reasoning", itemId: "r", text: "短" },
|
|
perm("mid"),
|
|
{ type: "reasoning", itemId: "r2", text: "短" },
|
|
...run("y", TOOL_COLLAPSE_AT + 3),
|
|
]), { runtimeStatus: "running" });
|
|
const folded = foldTimeline(items);
|
|
const top = folded.filter((i) => i.kind === "permission");
|
|
expect(top.map((i) => (i as { requestId: string }).requestId)).toEqual(["mid"]);
|
|
expect(folded.filter((i) => i.kind === "toolgroup")).toHaveLength(2);
|
|
expect(pendingRequests(folded).map((p) => p.requestId)).toEqual(["mid"]);
|
|
});
|
|
});
|