Keep timeline history duplicate-free across daemon upgrades (#2789)

* fix(app): keep timeline pagination duplicate-free

Older daemons page projected history by canonical sequence ranges, so one projected block can appear in adjacent responses. Accept each block on the page containing its projection anchor while still advancing across empty projected pages.\n\nProjected siblings can share a provider message ID, so render identity also includes the timeline cursor instead of collapsing distinct blocks onto one layout row.

* fix(e2e): preserve isolated daemon launch contract

Keep the source-daemon spawn path recognizable to the repository launch-contract check while selecting the built supervisor only for published package fixtures.

* fix(app): preserve stable timeline item identity
This commit is contained in:
Mohamed Boudra
2026-08-02 12:21:47 +02:00
committed by GitHub
parent 0a106dd35f
commit 26bdb1d171
9 changed files with 407 additions and 44 deletions
@@ -74,6 +74,7 @@ export interface ProcessTimelineResponseInput {
payload: {
agentId: string;
direction: TimelineDirection;
projection: "projected" | "canonical";
reset: boolean;
epoch: string;
window: { minSeq: number; maxSeq: number; nextSeq: number };
@@ -786,6 +787,27 @@ function deriveCanonicalAcknowledgements(params: {
return [...acknowledged];
}
function selectEntriesOwnedByTimelinePage(
payload: ProcessTimelineResponseInput["payload"],
): TimelineResponseEntry[] {
// COMPAT(projectedBeforePageOwnership): added in v0.2.6, remove after 2027-02-02
// once the supported daemon floor paginates projected before pages.
if (
payload.direction !== "before" ||
payload.projection !== "projected" ||
!payload.startCursor ||
!payload.endCursor
) {
return payload.entries;
}
const pageStartSeq = payload.startCursor.seq;
const pageEndSeq = payload.endCursor.seq;
return payload.entries.filter(
(entry) => entry.seqStart >= pageStartSeq && entry.seqStart <= pageEndSeq,
);
}
function applyTimelineIncrementalPath(args: {
timelineUnits: TimelineUnit[];
payload: ProcessTimelineResponseInput["payload"];
@@ -802,7 +824,7 @@ function applyTimelineIncrementalPath(args: {
const sideEffects: TimelineReducerSideEffect[] = [];
let acknowledgedClientMessageIds: string[] = [];
if (timelineUnits.length === 0) {
if (timelineUnits.length === 0 && payload.direction !== "before") {
return {
tail: nextTail,
head: nextHead,
@@ -827,16 +849,33 @@ function applyTimelineIncrementalPath(args: {
currentCursor,
});
if (
payload.direction === "before" &&
cursor &&
currentCursor &&
cursor.startSeq !== currentCursor.startSeq
) {
older = payload.hasOlder ? "available" : "none";
}
if (acceptedUnits.length > 0) {
if (payload.direction === "before") {
older = payload.hasOlder ? "available" : "none";
const olderTail = hydrateStreamState(
acceptedUnits.map(({ event, timestamp, seqEnd }) => ({
event,
timestamp,
timelineCursor: { epoch: payload.epoch, seq: seqEnd },
})),
{ source: "canonical" },
{
source: "canonical",
reservedItemIds: new Set(
currentTail.flatMap((item) =>
item.kind === "assistant_message" && item.blockGroupId
? [item.id, item.blockGroupId]
: [item.id],
),
),
},
);
nextTail = mergePrependedCanonicalTail(olderTail, currentTail);
} else {
@@ -915,7 +954,7 @@ export function processTimelineResponse(
// ------------------------------------------------------------------
// Convert entries to timeline units
// ------------------------------------------------------------------
const timelineUnits = payload.entries.map((entry) => ({
const timelineUnits = selectEntriesOwnedByTimelinePage(payload).map((entry) => ({
seq: entry.seqStart,
seqEnd: entry.seqEnd,
sourceSeqRanges: