mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-10 02:15:02 +00:00
Stop showing Updating messages for a chat that has not changed (#9175)
* fix(app): stop showing Updating messages for a chat that has not changed Every return to a chat fetched from the daemon just to learn nothing had changed, and the toast covered that fetch. The subscribe request that attaches a chat now carries its cursor, and the daemon answers current or behind in the same round trip, so an unchanged chat needs no fetch and shows nothing. The daemon attaches before it compares, so a commit landing in between is either delivered live or counted as behind. It never loads an agent to answer: an agent it has not loaded answers behind and resumes in the fetch, as before. The delay before an unanswered check shows the toast starts when the request is sent. A cold start's cache read alone can outlast the delay, which would flash the toast for a chat the daemon then reports current. * fix(app): keep agent details and stay quiet after a current timeline answer The timeline fetch that a current answer skips also delivered the full agent row, and the replica cache stores only part of it. After a cold reload with an empty incremental directory page, usage, modes, permissions and runtime info stayed empty. The subscribe answer now carries the row for each current chat, gated with the rest of the freshness check. The panel also reported ready before the timeline owner was published, so a connected render with cached content showed Updating messages. No owner now reads as a check that has not begun. * test(app): pin the held running turn across a freshness check A chat that left mid-turn holds its running footer until its messages are current. With the freshness check, "current" is that commit with no rows, so the tests and the timeline-sync doc now cover the check in flight, a current answer, and a behind answer that holds until the fetched rows land. * fix(app): keep hidden chats live while a subscription is replaced The old timeline subscription was released in the same tick the new one was requested. The client deletes a route on release and adds the new route only when the daemon responds, so events sent in between were dropped. Visible chats recover through the cursor check; hidden chats skip it and stayed behind until something else fetched them. Release the old subscription when the new one settles. Accepting the new route and releasing the old one happen without a socket frame in between, so each event reaches the client once. * test(app): make the plugin chat reload spec independent of the freshness answer The spec reloaded and waited for a held timeline fetch. A chat with a cached cursor now answers current and never fetches, so the wait hung until the test timed out, depending on whether the cursor had been saved before the reload. Hold the subscribe request instead: the catalog still has to arrive while the timeline is outstanding, for either answer.
This commit is contained in:
@@ -1399,6 +1399,11 @@ export class AgentManager {
|
||||
return this.timelineStore.getRows(id);
|
||||
}
|
||||
|
||||
/** The timeline head of a loaded agent, or null when this agent is not loaded. Never loads. */
|
||||
getLoadedTimelineHead(id: string): { epoch: string; seq: number } | null {
|
||||
return this.getAgent(id) ? this.timelineStore.getHead(id) : null;
|
||||
}
|
||||
|
||||
fetchTimeline(id: string, options?: AgentTimelineFetchOptions): AgentTimelineFetchResult {
|
||||
this.requireAgent(id);
|
||||
return this.timelineStore.fetch(id, options);
|
||||
|
||||
@@ -89,6 +89,11 @@ export class InMemoryAgentTimelineStore {
|
||||
return this.requireState(agentId).epoch;
|
||||
}
|
||||
|
||||
getHead(agentId: string): { epoch: string; seq: number } {
|
||||
const state = this.requireState(agentId);
|
||||
return { epoch: state.epoch, seq: state.nextSeq - 1 };
|
||||
}
|
||||
|
||||
fetch(agentId: string, options?: AgentTimelineFetchOptions): AgentTimelineFetchResult {
|
||||
const state = this.requireState(agentId);
|
||||
const direction = options?.direction ?? "tail";
|
||||
|
||||
@@ -184,6 +184,7 @@ async function connect(input: {
|
||||
timelineNotifications?: boolean;
|
||||
pluginTimelineItems?: boolean;
|
||||
workspaceSetupBlocked?: boolean;
|
||||
ownedSubscriptions?: boolean;
|
||||
}): Promise<ConnectedClient> {
|
||||
let socket!: WebSocket;
|
||||
const client = new DaemonClient({
|
||||
@@ -194,7 +195,7 @@ async function connect(input: {
|
||||
return socket as unknown as WebSocketLike;
|
||||
},
|
||||
capabilities: {
|
||||
[CLIENT_CAPS.ownedSubscriptions]: false,
|
||||
[CLIENT_CAPS.ownedSubscriptions]: input.ownedSubscriptions ?? false,
|
||||
[CLIENT_CAPS.selectiveAgentTimeline]: input.selective,
|
||||
[CLIENT_CAPS.pluginTimelineItems]: input.pluginTimelineItems ?? false,
|
||||
[CLIENT_CAPS.workspaceSetupBlocked]: input.workspaceSetupBlocked ?? false,
|
||||
@@ -211,6 +212,97 @@ async function connect(input: {
|
||||
return connected;
|
||||
}
|
||||
|
||||
async function startDaemonWithMockAgents(
|
||||
home: { paseoHomeRoot: string; cleanup: boolean } | Record<string, never> = {},
|
||||
): Promise<void> {
|
||||
await daemon.close();
|
||||
daemon = await createTestPaseoDaemon({
|
||||
isDev: true,
|
||||
agentClients: { mock: new MockLoadTestAgentClient() },
|
||||
...home,
|
||||
});
|
||||
}
|
||||
|
||||
async function connectForFreshness(clientId: string): Promise<ConnectedClient> {
|
||||
return connect({ clientId, selective: true, ownedSubscriptions: true });
|
||||
}
|
||||
|
||||
async function createChatAtHead(connected: ConnectedClient, title: string) {
|
||||
const agent = await connected.client.createAgent({
|
||||
provider: "mock",
|
||||
cwd: "/tmp",
|
||||
title,
|
||||
model: "ten-second-stream",
|
||||
});
|
||||
await daemon.daemon.agentManager.appendTimelineItem(agent.id, {
|
||||
type: "assistant_message",
|
||||
text: "Already on screen",
|
||||
});
|
||||
const page = await connected.client.fetchAgentTimeline(agent.id, { direction: "tail" });
|
||||
if (!page.endCursor) throw new Error("Expected a timeline cursor");
|
||||
return { agentId: agent.id, head: { epoch: page.endCursor.epoch, seq: page.endCursor.seq } };
|
||||
}
|
||||
|
||||
test("subscribing with a cursor answers whether each chat is at its head", async () => {
|
||||
await startDaemonWithMockAgents();
|
||||
const connected = await connectForFreshness("freshness-loaded");
|
||||
const atHead = await createChatAtHead(connected, "At head");
|
||||
const staleSeq = await createChatAtHead(connected, "Stale seq");
|
||||
const otherEpoch = await createChatAtHead(connected, "Other epoch");
|
||||
const noCursor = await createChatAtHead(connected, "No cursor");
|
||||
|
||||
const observation = connected.client.observeTimeline(
|
||||
[atHead.agentId, staleSeq.agentId, otherEpoch.agentId, noCursor.agentId],
|
||||
{
|
||||
cursors: {
|
||||
[atHead.agentId]: atHead.head,
|
||||
[staleSeq.agentId]: { ...staleSeq.head, seq: staleSeq.head.seq - 1 },
|
||||
[otherEpoch.agentId]: { ...otherEpoch.head, epoch: "another-epoch" },
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const answer = await observation.ready;
|
||||
expect(answer.timelines).toEqual({
|
||||
[atHead.agentId]: "current",
|
||||
[staleSeq.agentId]: "behind",
|
||||
[otherEpoch.agentId]: "behind",
|
||||
});
|
||||
// Only a current chat skips the fetch that would have delivered its agent row.
|
||||
expect(Object.keys(answer.agents ?? {})).toEqual([atHead.agentId]);
|
||||
expect(answer.agents?.[atHead.agentId]).toMatchObject({ id: atHead.agentId, title: "At head" });
|
||||
|
||||
connected.clear();
|
||||
await daemon.daemon.agentManager.appendTimelineItem(atHead.agentId, {
|
||||
type: "assistant_message",
|
||||
text: "Arrives after the answer",
|
||||
});
|
||||
await connected.next(isAgentStream(atHead.agentId), "live row after a current answer");
|
||||
await observation.release();
|
||||
});
|
||||
|
||||
test("subscribing with a cursor answers behind for a stored agent and leaves it unloaded", async () => {
|
||||
const paseoHomeRoot = await mkdtemp(path.join(os.tmpdir(), "paseo-freshness-"));
|
||||
await startDaemonWithMockAgents({ paseoHomeRoot, cleanup: false });
|
||||
const before = await connectForFreshness("freshness-before-restart");
|
||||
const stored = await createChatAtHead(before, "Stored");
|
||||
before.close();
|
||||
await before.client.close();
|
||||
await startDaemonWithMockAgents({ paseoHomeRoot, cleanup: true });
|
||||
expect(daemon.daemon.agentManager.getAgent(stored.agentId)).toBeNull();
|
||||
|
||||
const connected = await connectForFreshness("freshness-after-restart");
|
||||
const observation = connected.client.observeTimeline([stored.agentId], {
|
||||
cursors: { [stored.agentId]: stored.head },
|
||||
});
|
||||
|
||||
const answer = await observation.ready;
|
||||
expect(answer.timelines).toEqual({ [stored.agentId]: "behind" });
|
||||
expect(answer.agents).toEqual({});
|
||||
expect(daemon.daemon.agentManager.getAgent(stored.agentId)).toBeNull();
|
||||
await observation.release();
|
||||
});
|
||||
|
||||
test("notification timeline items are sent only to clients that advertise support", async () => {
|
||||
await daemon.close();
|
||||
daemon = await createTestPaseoDaemon({
|
||||
|
||||
@@ -1408,6 +1408,65 @@ export class Session {
|
||||
this.refreshObservationProducers();
|
||||
}
|
||||
|
||||
private compareTimelineCursors(
|
||||
agentIds: string[],
|
||||
cursors: Record<string, AgentTimelineCursor>,
|
||||
): Record<string, "current" | "behind"> {
|
||||
const timelines: Record<string, "current" | "behind"> = {};
|
||||
for (const agentId of agentIds) {
|
||||
const cursor = cursors[agentId];
|
||||
if (!cursor) continue;
|
||||
const head = this.agentManager.getLoadedTimelineHead(agentId);
|
||||
timelines[agentId] =
|
||||
head?.epoch === cursor.epoch && head.seq === cursor.seq ? "current" : "behind";
|
||||
}
|
||||
return timelines;
|
||||
}
|
||||
|
||||
private async answerTimelineFreshness(
|
||||
agentIds: string[],
|
||||
cursors: Record<string, AgentTimelineCursor>,
|
||||
): Promise<{
|
||||
timelines: Record<string, "current" | "behind">;
|
||||
agents: Record<string, AgentSnapshotPayload>;
|
||||
}> {
|
||||
const snapshots = await Promise.all(
|
||||
agentIds.flatMap((agentId) => {
|
||||
const agent = cursors[agentId] ? this.agentManager.getAgent(agentId) : null;
|
||||
return agent ? [this.buildAgentPayload(agent)] : [];
|
||||
}),
|
||||
);
|
||||
// Compared after the await, so a row appended while reading the snapshots answers behind.
|
||||
const timelines = this.compareTimelineCursors(agentIds, cursors);
|
||||
const agents: Record<string, AgentSnapshotPayload> = {};
|
||||
for (const snapshot of snapshots) {
|
||||
if (timelines[snapshot.id] === "current") agents[snapshot.id] = snapshot;
|
||||
}
|
||||
return { timelines, agents };
|
||||
}
|
||||
|
||||
private async handleAgentTimelineSubscription(
|
||||
msg: Extract<SessionInboundMessage, { type: "agent.timeline.set_subscription.request" }>,
|
||||
source?: object,
|
||||
): Promise<void> {
|
||||
const agentIds = [...new Set(msg.agentIds)].sort();
|
||||
// Attach before comparing: a row appended after the comparison reaches this owner live.
|
||||
const owner = this.subscribeAgentTimelines(agentIds);
|
||||
const freshness = msg.cursors ? await this.answerTimelineFreshness(agentIds, msg.cursors) : {};
|
||||
this.emitForSource(
|
||||
{
|
||||
type: "agent.timeline.set_subscription.response",
|
||||
payload: {
|
||||
agentIds,
|
||||
requestId: msg.requestId,
|
||||
subscriptionId: owner.responseId,
|
||||
...freshness,
|
||||
},
|
||||
},
|
||||
source,
|
||||
);
|
||||
}
|
||||
|
||||
private subscribeAgentTimelines(agentIds: string[]): OwnedSubscription {
|
||||
const owner = this.delivery.begin("timelines", undefined, (id) => {
|
||||
this.timelineSubscriptions.delete(id);
|
||||
@@ -3043,18 +3102,8 @@ export class Session {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
case "agent.timeline.set_subscription.request": {
|
||||
const agentIds = [...new Set(msg.agentIds)].sort();
|
||||
const owner = this.subscribeAgentTimelines(agentIds);
|
||||
this.emitForSource(
|
||||
{
|
||||
type: "agent.timeline.set_subscription.response",
|
||||
payload: { agentIds, requestId: msg.requestId, subscriptionId: owner.responseId },
|
||||
},
|
||||
source,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
case "agent.timeline.set_subscription.request":
|
||||
return this.handleAgentTimelineSubscription(msg, source);
|
||||
case "agent.fork_context.request":
|
||||
return this.handleAgentForkContextRequest(msg);
|
||||
default:
|
||||
|
||||
@@ -2196,6 +2196,8 @@ export class VoiceAssistantWebSocketServer {
|
||||
forgeProviders: true,
|
||||
// COMPAT(selectiveAgentTimeline): added in v0.1.106, remove after 2027-01-12.
|
||||
selectiveAgentTimeline: true,
|
||||
// COMPAT(timelineFreshnessCheck): added after v0.15.3, remove after 2027-05-09.
|
||||
timelineFreshnessCheck: true,
|
||||
explicitEventSubscriptions: true,
|
||||
// COMPAT(canonicalSubmittedPrompts): added in v0.2.6, remove gate after 2027-01-30.
|
||||
canonicalSubmittedPrompts: true,
|
||||
|
||||
Reference in New Issue
Block a user