Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,28 @@ it("readThread returns the newest items that fit the response budget", async ()
maxCharsPerItem: 1_500,
};
const result = yield* service.readThread(makeScope(), read);
// Linked environments and the CLI read as clients without a cursor and follow only hasMore.
// The CLI reads as a client without a cursor and follows only hasMore.
const first = yield* service.readThread({ ...makeScope(), thread: undefined }, read);
const fromStart = yield* service.readThread(makeScope(), { ...read, afterPosition: -1 });
const linked = yield* service.readThread(
{
...makeScope(),
thread: undefined,
client: {
sessionId: "laptop",
label: "T3 Code · laptop",
access: "auto",
linked: true,
},
},
read,
);

expect(pageOptions).toEqual([
{ beforePosition: Number.POSITIVE_INFINITY, limit: 100, view: "activity" },
{ limit: 100, view: "activity" },
{ afterPosition: -1, limit: 100, view: "activity" },
{ beforePosition: Number.POSITIVE_INFINITY, limit: 100, view: "activity" },
]);
// Claude Code saves results over ~50k chars of this JSON to a file instead of showing them.
expect(JSON.stringify(result).length).toBeLessThan(31_000);
Expand All @@ -524,6 +538,9 @@ it("readThread returns the newest items that fit the response budget", async ()
expect(first.hasMore).toBe(true);
expect(first.nextPosition).toBe(first.items.at(-1)?.position);
expect(fromStart.items[0]?.position).toBe(0);
expect(linked.items.at(-1)?.position).toBe(99);
expect(linked.earlierPosition).toBe(linked.items[0]?.position);
expect(linked.hasMore).toBe(false);
}).pipe(Effect.provide(layer), Effect.runPromise);
});

Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3510,10 +3510,11 @@ const make = Effect.gen(function* () {
const view = input.view ?? "messages";
const limit = input.limit ?? DEFAULT_THREAD_READ_LIMIT;
const maxChars = input.maxCharsPerItem ?? DEFAULT_THREAD_ITEM_MAX_CHARS;
// Client callers (the CLI, older linked environments) page forward from a cursorless read.
// Client callers (the CLI) page forward from a cursorless read.
const newestFirst =
input.beforePosition !== undefined ||
(input.afterPosition === undefined && scope.thread !== undefined);
(input.afterPosition === undefined &&
(scope.thread !== undefined || scope.client?.linked === true));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const timeline = yield* threadManagement
.getTimelinePage(input.threadId, {
...(input.afterPosition === undefined ? {} : { afterPosition: input.afterPosition }),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/peer/RemoteDelegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ it.effect.each([
const pages = reads.filter((read) => read.itemId === undefined && read.limit === 100);
// The thread's final page starts at its canonical 100-item boundary.
const tailPosition = Math.floor((timeline.length - 1) / 100) * 100 - 1;
expect(pages.at(0)?.afterPosition).toBeUndefined();
expect(pages.at(0)?.afterPosition).toBe(-1);
expect(
pages.every(
(read) =>
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/peer/RemoteDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ const make = Effect.gen(function* () {
) {
let reply: OrchestratorMcpThreadTimelineItem | undefined;
let error: OrchestratorMcpThreadTimelineItem | undefined;
let afterPosition: number | undefined;
// Linked peers read newest first without a cursor; this scan runs forward.
let afterPosition = -1;
let run: OrchestratorMcpThreadRun | undefined;
let remainingItems = 0;
let tailProbed = false;
Expand All @@ -632,7 +633,7 @@ const make = Effect.gen(function* () {
// Keep the first and expected final activity pages whole. A result on a
// middle page then needs an extra text read after the scan.
maxCharsPerItem: failed && remainingItems > 100 ? 1 : 20_000,
...(afterPosition === undefined ? {} : { afterPosition }),
afterPosition,
});
run ??= read.recentRuns.find((candidate) => candidate.runId === runId);
reply =
Expand Down
Loading