GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): linked workflow steps recover replies from older pages (… · patroza/t3code@d2a9b77

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/workflows
    • WorkflowAgentLinks.test.ts
    • WorkflowAgentLinks.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/workflows/WorkflowAgentLinks.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/workflows/WorkflowAgentLinks.test.ts
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,42 @@ const input = {
5959
const run = (status: string) => ({ recentRuns: [{ runId: "turn-1", status }], items: [] });
6060
const waited = { threadId: "thread-1", runId: "turn-1", status: "idle" };
6161

62+
const assistant = (position: number, runId: string, text: string) => ({
63+
type: "assistant_message",
64+
itemId: `item-${position}`,
65+
position,
66+
runId,
67+
text,
68+
textTruncated: false,
69+
});
70+
const page = (
71+
items: ReadonlyArray<ReturnType<typeof assistant>>,
72+
earlierPosition?: number | null,
73+
hasMore = false,
74+
) => ({
75+
recentRuns: [],
76+
items,
77+
earlierPosition,
78+
hasMore,
79+
nextPosition: items.at(-1)?.position ?? null,
80+
});
81+
const readReply = (...pages: ReadonlyArray<unknown>) => {
82+
const there = peer({
83+
t3_thread_wait: [{ ...waited, timedOut: false }],
84+
t3_thread_read: [run("completed"), ...pages],
85+
});
86+
return Effect.gen(function* () {
87+
const result = yield* Effect.provide(
88+
Effect.flatMap(WorkflowAgentLinks.make, (links) =>
89+
links.result({ threadId: "thread-1", turnId: "turn-1" }, "env-b"),
90+
),
91+
there.layer,
92+
);
93+
return { result, reads: there.calls.slice(2).map((call) => call.arguments) };
94+
});
95+
};
96+
const messageRead = { threadId: "thread-1", view: "messages", limit: 100 };
97+
6298
it.effect("starts a thread there by the project's folder, with the step's key as the request", () =>
6399
Effect.gen(function* () {
64100
const there = peer({
@@ -224,6 +260,79 @@ it.effect("waits in pieces, rides out a dropped route, and returns the output an
224260
}),
225261
);
226262

263+
it.effect("returns the whole last reply from an older page of a linked thread", () =>
264+
Effect.gen(function* () {
265+
const later = {
266+
...assistant(4, "turn-1", "Latest "),
267+
textTruncated: true,
268+
nextTextOffset: 7,
269+
};
270+
const { result, reads } = yield* readReply(
271+
page([assistant(9, "turn-3", "newest turn")], 9),
272+
page([assistant(6, "turn-2", "another turn")], 6, true),
273+
page([assistant(3, "turn-1", "earlier draft"), later], 3, true),
274+
page([{ ...later, text: "complete reply", textTruncated: false }]),
275+
);
276+
assert.deepStrictEqual(result, {
277+
ending: "completed",
278+
detail: "",
279+
reply: "Latest complete reply",
280+
});
281+
assert.deepStrictEqual(reads, [
282+
messageRead,
283+
{ ...messageRead, beforePosition: 9 },
284+
{ ...messageRead, beforePosition: 6 },
285+
{ threadId: "thread-1", itemId: "item-4", textOffset: 7, maxCharsPerItem: 50_000 },
286+
]);
287+
}),
288+
);
289+
290+
it.effect("keeps the latest matching reply when paging a legacy peer forward", () =>
291+
Effect.gen(function* () {
292+
for (const earlierPosition of [undefined, null]) {
293+
const { result, reads } = yield* readReply(
294+
page([assistant(2, "turn-1", "draft")], earlierPosition, true),
295+
page([assistant(4, "turn-1", "final")], earlierPosition, true),
296+
page([assistant(6, "turn-2", "other turn")], earlierPosition),
297+
);
298+
assert.strictEqual(result.reply, "final");
299+
assert.deepStrictEqual(reads, [
300+
messageRead,
301+
{ ...messageRead, afterPosition: 2 },
302+
{ ...messageRead, afterPosition: 4 },
303+
]);
304+
}
305+
}),
306+
);
307+
308+
it.effect("keeps the reply when a legacy peer's forward cursor stops advancing", () =>
309+
Effect.gen(function* () {
310+
for (const position of [2, 1]) {
311+
const { result, reads } = yield* readReply(
312+
page([assistant(2, "turn-1", "Done.")], undefined, true),
313+
page([assistant(position, "turn-2", "other turn")], undefined, true),
314+
);
315+
assert.strictEqual(result.reply, "Done.");
316+
assert.deepStrictEqual(reads, [messageRead, { ...messageRead, afterPosition: 2 }]);
317+
}
318+
}),
319+
);
320+
321+
it.effect(
322+
"returns an empty reply when older pages are exhausted or their cursor stops advancing",
323+
() =>
324+
Effect.gen(function* () {
325+
for (const earlierPosition of [null, 3, 4]) {
326+
const { result, reads } = yield* readReply(
327+
page([assistant(3, "turn-2", "other turn")], 3),
328+
page([assistant(1, "turn-0", "another turn")], earlierPosition, true),
329+
);
330+
assert.deepStrictEqual(result, { ending: "completed", detail: "", reply: "" });
331+
assert.deepStrictEqual(reads, [messageRead, { ...messageRead, beforePosition: 3 }]);
332+
}
333+
}),
334+
);
335+
227336
it.effect("a turn someone stopped there is stopped, and a refused link fails at once", () =>
228337
Effect.gen(function* () {
229338
const stopped = peer({
Collapse file

‎apps/server/src/workflows/WorkflowAgentLinks.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/workflows/WorkflowAgentLinks.ts
+17-4Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,33 @@ export const make = Effect.gen(function* () {
131131
environment: string,
132132
) {
133133
let last: OrchestratorMcpThreadReadResult["items"][number] | undefined;
134-
let afterPosition: number | undefined;
134+
let cursor: { beforePosition?: number; afterPosition?: number } = {};
135135
while (true) {
136136
const read = yield* call(environment, "t3_thread_read", OrchestratorMcpThreadReadResult, {
137137
threadId: turn.threadId,
138138
view: "messages",
139139
limit: 100,
140-
...(afterPosition === undefined ? {} : { afterPosition }),
140+
...cursor,
141141
});
142142
last =
143143
read.items.findLast(
144144
(item) => item.type === "assistant_message" && item.runId === turn.turnId,
145145
) ?? last;
146-
if (!read.hasMore || read.nextPosition === null) break;
147-
afterPosition = read.nextPosition;
146+
const { earlierPosition, nextPosition, hasMore } = read;
147+
// Backward pages are chronological too, and hasMore points toward newer items.
148+
if (cursor.afterPosition === undefined && earlierPosition != null) {
149+
if (last !== undefined || earlierPosition >= (cursor.beforePosition ?? Infinity)) break;
150+
cursor = { beforePosition: earlierPosition };
151+
continue;
152+
}
153+
if (
154+
cursor.beforePosition !== undefined ||
155+
!hasMore ||
156+
nextPosition === null ||
157+
nextPosition <= (cursor.afterPosition ?? -1)
158+
)
159+
break;
160+
cursor = { afterPosition: nextPosition };
148161
}
149162
if (last === undefined) return "";
150163
let text = last.text ?? "";

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.