diff --git a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts index 3a389a5063645..a1294de3648f9 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts @@ -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); @@ -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); }); diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 68d8cc02b49f1..36f8c72b7f3aa 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -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)); const timeline = yield* threadManagement .getTimelinePage(input.threadId, { ...(input.afterPosition === undefined ? {} : { afterPosition: input.afterPosition }), diff --git a/apps/server/src/peer/RemoteDelegation.test.ts b/apps/server/src/peer/RemoteDelegation.test.ts index d4af55cae0313..3c14fb427fc2e 100644 --- a/apps/server/src/peer/RemoteDelegation.test.ts +++ b/apps/server/src/peer/RemoteDelegation.test.ts @@ -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) => diff --git a/apps/server/src/peer/RemoteDelegation.ts b/apps/server/src/peer/RemoteDelegation.ts index 6e48aa5fa61fe..5ed03b795b686 100644 --- a/apps/server/src/peer/RemoteDelegation.ts +++ b/apps/server/src/peer/RemoteDelegation.ts @@ -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; @@ -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 =