Skip to content

Commit 5f82942

Browse files
fix(client): reveal earlier agent turns in one load (pingdotgg#24417)
1 parent d9c0920 commit 5f82942

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

‎packages/client-runtime/src/state/threads-sync.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,66 @@ describe("EnvironmentThreads", () => {
10511051
expect((yield* SubscriptionRef.get(harness.threadState)).history.loading).toBe(false);
10521052
}),
10531053
);
1054+
const boundary = (fields: object, id = "boundary", ordinal = 2) => ({
1055+
...command(id, "completed", 0, ordinal),
1056+
...fields,
1057+
});
1058+
const message = (
1059+
inputIntent: "turn_start" | "steer",
1060+
createdBy: "agent" | "user",
1061+
id = "boundary",
1062+
ordinal = 2,
1063+
) =>
1064+
boundary(
1065+
{
1066+
type: "user_message",
1067+
messageId: MessageId.make(id),
1068+
inputIntent,
1069+
createdBy,
1070+
creationSource: "mcp",
1071+
text: "Run every check",
1072+
attachments: [],
1073+
},
1074+
id,
1075+
ordinal,
1076+
);
1077+
it.effect.each([
1078+
["an agent-started turn", message("turn_start", "agent"), ["3"]],
1079+
[
1080+
"a notification",
1081+
boundary({
1082+
type: "notification",
1083+
source: { kind: "delegated_task", taskIds: [] },
1084+
outcome: "completed",
1085+
summary: "Checks finished",
1086+
}),
1087+
["3"],
1088+
],
1089+
["a steer, paging on to its turn", message("steer", "user"), ["3", "2", "1"]],
1090+
] as const)("stops paging earlier history at %s", ([, item, expected]) =>
1091+
Effect.gen(function* () {
1092+
const pages: Record<string, ReadonlyArray<unknown>> = {
1093+
"3": [item],
1094+
"2": [command("work-1", "completed", 0, 1)],
1095+
"1": [message("turn_start", "user", "opener", 0)],
1096+
};
1097+
const requests: string[] = [];
1098+
const harness = yield* makeHarness({
1099+
cached: cachedItem(command("tail", "completed", 0, 3)),
1100+
cachedHistory: { historyCursor: "3", hasMoreHistory: true },
1101+
historyHttpClient: HttpClient.make((request, url) => {
1102+
const cursor = url.searchParams.get("cursor")!;
1103+
requests.push(cursor);
1104+
const items = (pages[cursor] ?? []) as ReadonlyArray<OrchestrationV2TurnItem>;
1105+
return Effect.succeed(
1106+
historyPage(request, items.map(localRow), String(Number(cursor) - 1)),
1107+
);
1108+
}),
1109+
});
1110+
expect(yield* harness.loadEarlier()).toEqual({ _tag: "loaded" });
1111+
expect(requests).toEqual(expected);
1112+
}),
1113+
);
10541114
it.effect("loads deferred work on demand and resumes a failed page", () =>
10551115
Effect.gen(function* () {
10561116
const anchor = {

‎packages/client-runtime/src/state/threads.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ function formatHistoryError(error: unknown): string {
7575
return "Could not load earlier activity.";
7676
}
7777

78+
// Steers join a running turn; every other user message opens one. The timeline shows every
79+
// notification as a response boundary, whether it opened its run or arrived mid-run.
80+
function startsTurn(item: OrchestrationV2TurnItem): boolean {
81+
return (
82+
item.type === "notification" ||
83+
(item.type === "user_message" &&
84+
item.inputIntent !== "steer" &&
85+
item.inputIntent !== "promoted_queued_to_steer")
86+
);
87+
}
88+
7889
function historyMetaFromCachedSnapshot(
7990
snapshot: OrchestrationV2ThreadDetailSnapshot,
8091
): ThreadHistoryMeta {
@@ -777,9 +788,7 @@ export const makeEnvironmentThreadState = Effect.fn("EnvironmentThreadState.make
777788
? page.nextCursor !== null
778789
: throughEntryId === undefined &&
779790
page.hasMoreHistory &&
780-
!page.items.some(
781-
({ item }) => item.type === "user_message" && item.createdBy === "user",
782-
));
791+
!page.items.some(({ item }) => startsTurn(item)));
783792
if (keepPaging && (page.nextCursor === null || page.nextCursor === requestCursor))
784793
return yield* failLoad(
785794
workAnchorId === undefined

0 commit comments

Comments
 (0)