mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 10:15:46 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcac35d3b9 |
@@ -61,6 +61,11 @@ the chat and its replica cache would keep only the end of the reply. A recovery
|
||||
running catch-up starts after whatever that catch-up applied, because the app applies a forward page
|
||||
row by row and an older cursor repeats rows.
|
||||
|
||||
A live row whose epoch differs from the local cursor is a rewind or replacement this client never
|
||||
saw as an invalidation, not a stale row. The app recovers like a gap: it asks `after` its own
|
||||
cursor, and the daemon answers that stale epoch with a reset tail. Dropping the rows instead would
|
||||
leave the chat on pre-rewind history while the new epoch streams.
|
||||
|
||||
Initialization timeouts guard lack of catch-up progress, not the full multi-page sync. A successful page that queues the next `after` page refreshes the watchdog.
|
||||
|
||||
Opening or resuming an agent fetches the latest available turns with a soft target of 40
|
||||
|
||||
@@ -204,6 +204,112 @@ describe("viewed timeline persistence", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("replaces pre-rewind history when a live row arrives in a new epoch", async () => {
|
||||
useSessionStore.getState().initializeSession(SERVER_ID, null);
|
||||
applySynced(AGENT_ID, 5);
|
||||
const readTimelineState = () => {
|
||||
const timeline = selectAgentTimelineState(
|
||||
useSessionStore.getState().sessions[SERVER_ID],
|
||||
AGENT_ID,
|
||||
);
|
||||
return {
|
||||
status: timeline.status,
|
||||
texts:
|
||||
timeline.status === "cold"
|
||||
? []
|
||||
: timeline.items.flatMap((entry) =>
|
||||
entry.kind === "assistant_message" ? [entry.text] : [],
|
||||
),
|
||||
};
|
||||
};
|
||||
const fetches: Array<{
|
||||
direction: string;
|
||||
cursor?: { epoch: string; seq: number };
|
||||
}> = [];
|
||||
const replica = createTimelineReplica({
|
||||
serverId: SERVER_ID,
|
||||
storage: { readTimeline: async () => undefined, commitTimeline: () => undefined },
|
||||
prepareAgent: async () => undefined,
|
||||
});
|
||||
const owner = createViewedTimelineOwner({
|
||||
serverId: SERVER_ID,
|
||||
replica,
|
||||
replaceDemandedAgentIds: () => undefined,
|
||||
drainQueuedAgentMessage: () => undefined,
|
||||
applyTurnLiveness: () => undefined,
|
||||
ports: {
|
||||
canCheckFreshness: () => false,
|
||||
observe: () => ({ ready: Promise.resolve(), release: async () => undefined }),
|
||||
readCursor: () => undefined,
|
||||
fetchPage: async (_agentId, request) => {
|
||||
fetches.push(request);
|
||||
if (request.direction !== "after") return { hasNewer: false, endCursor: null };
|
||||
// A cursor from the pre-rewind epoch makes the daemon reset to its current tail.
|
||||
owner.applyTimelineResponse({
|
||||
requestId: "rewind-reset",
|
||||
agentId: AGENT_ID,
|
||||
agent: null,
|
||||
direction: "tail",
|
||||
projection: "projected",
|
||||
epoch: "epoch-2",
|
||||
reset: true,
|
||||
staleCursor: true,
|
||||
gap: false,
|
||||
window: { minSeq: 1, maxSeq: 2, nextSeq: 3 },
|
||||
startCursor: { epoch: "epoch-2", seq: 1 },
|
||||
endCursor: { epoch: "epoch-2", seq: 2 },
|
||||
entries: [
|
||||
{
|
||||
provider: "codex",
|
||||
item: { type: "assistant_message", text: "after rewind" },
|
||||
timestamp: "2026-08-26T10:05:00.000Z",
|
||||
seqStart: 1,
|
||||
seqEnd: 2,
|
||||
sourceSeqRanges: [{ startSeq: 1, endSeq: 2 }],
|
||||
collapsed: [],
|
||||
},
|
||||
],
|
||||
hasOlder: false,
|
||||
hasNewer: false,
|
||||
error: null,
|
||||
});
|
||||
return { hasNewer: false, endCursor: { epoch: "epoch-2", seq: 2 } };
|
||||
},
|
||||
fetchLatestTail: async () => ({ hasNewer: false, endCursor: null }),
|
||||
reportError: () => undefined,
|
||||
},
|
||||
});
|
||||
try {
|
||||
owner.setConnected(true);
|
||||
owner.replaceVisibleAgentIds("test", [AGENT_ID]);
|
||||
await expect.poll(() => fetches.length).toBe(1);
|
||||
|
||||
owner.applyStreamEvent(AGENT_ID, {
|
||||
event: {
|
||||
type: "timeline",
|
||||
provider: "codex",
|
||||
item: { type: "assistant_message", text: "new prompt reply" },
|
||||
} as AgentStreamEventPayload,
|
||||
seq: 6,
|
||||
epoch: "epoch-2",
|
||||
timestamp: new Date("2026-08-26T10:06:00.000Z"),
|
||||
});
|
||||
owner.flushStreamAgent(AGENT_ID);
|
||||
|
||||
await expect.poll(() => fetches.length).toBe(2);
|
||||
expect(fetches[1]).toMatchObject({
|
||||
direction: "after",
|
||||
cursor: { epoch: "epoch-1", seq: 5 },
|
||||
});
|
||||
await expect.poll(readTimelineState).toEqual({
|
||||
status: "synced",
|
||||
texts: ["after rewind"],
|
||||
});
|
||||
} finally {
|
||||
owner.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("shares an in-flight cache preparation with the viewed owner", async () => {
|
||||
useSessionStore.getState().initializeSession(SERVER_ID, null);
|
||||
let release!: (value: CachedTimeline) => void;
|
||||
|
||||
@@ -3834,7 +3834,7 @@ describe("processAgentStreamEvent", () => {
|
||||
expect(result.sideEffects).toEqual([]);
|
||||
});
|
||||
|
||||
it("drops timeline event with epoch mismatch", () => {
|
||||
it("requests authoritative recovery when a live row has a different epoch", () => {
|
||||
const existingCursor: TimelineCursor = {
|
||||
epoch: "epoch-1",
|
||||
startSeq: 1,
|
||||
@@ -3852,7 +3852,9 @@ describe("processAgentStreamEvent", () => {
|
||||
expect(result.cursorChanged).toBe(false);
|
||||
expect(result.changedTail).toBe(false);
|
||||
expect(result.changedHead).toBe(false);
|
||||
expect(result.sideEffects).toEqual([]);
|
||||
expect(result.sideEffects).toEqual([
|
||||
{ type: "catch_up", cursor: { epoch: "epoch-1", endSeq: 5 } },
|
||||
]);
|
||||
});
|
||||
|
||||
it("resets visible timeline when a new epoch starts at seq 1", () => {
|
||||
|
||||
@@ -1545,7 +1545,20 @@ function processTimelineSequencingGate(input: {
|
||||
cursorChanged: true,
|
||||
};
|
||||
}
|
||||
if (decision === "gap") {
|
||||
if (decision === "drop_epoch" && seq === 1) {
|
||||
return {
|
||||
...base,
|
||||
nextTimelineCursor: { epoch, startSeq: seq, endSeq: seq },
|
||||
cursorChanged: true,
|
||||
resetLiveTimeline: true,
|
||||
};
|
||||
}
|
||||
// A gap and an epoch change both mean the local cursor cannot certify the next row.
|
||||
// The epoch case is a rewind or replacement this client did not observe as an
|
||||
// invalidation; the daemon answers an `after` request carrying the stale epoch with a
|
||||
// reset tail, which installs current history. Dropping those rows would leave the chat
|
||||
// on pre-rewind history while the new epoch streams.
|
||||
if (decision === "gap" || decision === "drop_epoch") {
|
||||
return {
|
||||
...base,
|
||||
shouldApplyStreamEvent: false,
|
||||
@@ -1559,14 +1572,6 @@ function processTimelineSequencingGate(input: {
|
||||
],
|
||||
};
|
||||
}
|
||||
if (decision === "drop_epoch" && seq === 1) {
|
||||
return {
|
||||
...base,
|
||||
nextTimelineCursor: { epoch, startSeq: seq, endSeq: seq },
|
||||
cursorChanged: true,
|
||||
resetLiveTimeline: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
shouldApplyStreamEvent: false,
|
||||
|
||||
Reference in New Issue
Block a user