From a0821bc201fbf13d25dad1336e5df641ba526500 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:57:48 +0000 Subject: [PATCH 1/2] fork seams: announce the #386 reply-read lines in RemoteDelegation.ts List only. Announces the three lines the follow-up pull request adds to RemoteDelegation.ts: an import of fork/remoteReplyRead.ts, the wrapped forwarding, and lastReply reading through it. A task delegated to a linked environment on another version then still delivers its reply. Part of #386. Co-Authored-By: Claude Opus 5.5 --- .github/fork-seams.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/fork-seams.json b/.github/fork-seams.json index 16d5f67eb2fc2..7227c25c8231b 100644 --- a/.github/fork-seams.json +++ b/.github/fork-seams.json @@ -111,7 +111,7 @@ ] }, "apps/server/src/peer/RemoteDelegation.ts": { - "why": "#386: a remote delegate_task interrupted after its launch there (the parent's turn moved on) still records and follows its task: the launch, record and follow run as one uninterruptible step. A launch recorded with no task here is stopped there with a warning, as a failed record is. Tested in apps/server/src/fork/remoteDelegationAbortSafe.test.ts. Upstream PR pingdotgg/t3code#30249 (record before launch) rewrites this block, and its intent differs: after an interrupted, uncertain launch it stops the child there, while this seam keeps the child and follows it. Whoever brings #30249 in through fork-follow must choose on purpose between stopping and keeping (and expect a merge conflict on this block), then drop this seam or keep it.", + "why": "#386: a remote delegate_task interrupted after its launch there (the parent's turn moved on) still records and follows its task: the launch, record and follow run as one uninterruptible step. A launch recorded with no task here is stopped there with a warning, as a failed record is. Tested in apps/server/src/fork/remoteDelegationAbortSafe.test.ts. Upstream PR pingdotgg/t3code#30249 (record before launch) rewrites this block, and its intent differs: after an interrupted, uncertain launch it stops the child there, while this seam keeps the child and follows it. Whoever brings #30249 in through fork-follow must choose on purpose between stopping and keeping (and expect a merge conflict on this block), then drop this seam or keep it. Also #386: lastReply reads a task's reply through fork/remoteReplyRead.ts, which decodes the answer again without the thread's details when the full read does not decode, so a linked environment on another version (thread details missing a field this version requires) still delivers the reply. Tested in apps/server/src/fork/remoteReplyRead.test.ts.", "added": [ "// Fork: from the launch on, the task is recorded and followed even if this call is", "// interrupted (the parent's turn moved on), else the thread there runs with nothing here", @@ -123,7 +123,15 @@ "yield* Effect.logWarning(\"remote-delegation.record-found-no-task\", remoteChild);", "const unfollowed = stopThere(followScope(scope.thread, remoteChild), remoteChild, \"stop\");", "yield* unfollowed.pipe(Effect.ignoreCause({ log: true }));" - ] + ], + "announced": { + "since": "2026-11-19", + "added": [ + "import * as RemoteReplyRead from \"../fork/remoteReplyRead.ts\"; // Fork: replies across versions", + "const replyForwarding = RemoteReplyRead.replyReads(forwarding); // Fork: lastReply reads with it", + "const forwarding = replyForwarding; // Fork: a reply there on another version is still read." + ] + } }, "apps/web/src/components/ChatView.browser.test.tsx": { "why": "#474: upstream's test \"an interrupted image-only first send of a new thread says it may not have been sent\" presses Enter once the pasted image's tile shows. The tile shows while the image still compresses, and the composer refuses a send then (\"Still compressing a pasted image\"), so on a loaded runner the launch never came and the test went red. The fork line waits until the tile's preview button is enabled, which is when the image is ready. Drop this seam when upstream's test waits for the ready image itself.", From 35869d0d08eea92459a0a0f7c48a657a06e3ee7f Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:58:28 +0000 Subject: [PATCH 2/2] fix(remote-delegation): a reply from a linked environment on another version still completes its task A task delegated to a linked environment that runs an older T3 build never completed here. Its thread read decodes the whole thread, and a field this version requires in the thread's details (a linked pull request's watch state) is missing there, so every read failed as "did not match this version" and the follower retried forever: the parent was never told. lastReply now reads through fork/remoteReplyRead.ts. When the full read fails as an answer this version cannot decode, it reads the same page again without the thread's details, which a reply never needs. Runs and items keep their own schemas, so a reply is never guessed; if that read fails too, the first error stands as before. Moves the three announced RemoteDelegation.ts lines to the seam's added list. Part of #386. Co-Authored-By: Claude Opus 5.5 --- .github/fork-seams.json | 15 +- FORK_CHANGES.md | 1 + apps/server/src/fork/remoteReplyRead.test.ts | 280 +++++++++++++++++++ apps/server/src/fork/remoteReplyRead.ts | 49 ++++ apps/server/src/peer/RemoteDelegation.ts | 4 + 5 files changed, 339 insertions(+), 10 deletions(-) create mode 100644 apps/server/src/fork/remoteReplyRead.test.ts create mode 100644 apps/server/src/fork/remoteReplyRead.ts diff --git a/.github/fork-seams.json b/.github/fork-seams.json index 7227c25c8231b..a11d38a13d0b0 100644 --- a/.github/fork-seams.json +++ b/.github/fork-seams.json @@ -122,16 +122,11 @@ "// Fork: nothing here follows it, so stop it there, as a failed record does.", "yield* Effect.logWarning(\"remote-delegation.record-found-no-task\", remoteChild);", "const unfollowed = stopThere(followScope(scope.thread, remoteChild), remoteChild, \"stop\");", - "yield* unfollowed.pipe(Effect.ignoreCause({ log: true }));" - ], - "announced": { - "since": "2026-11-19", - "added": [ - "import * as RemoteReplyRead from \"../fork/remoteReplyRead.ts\"; // Fork: replies across versions", - "const replyForwarding = RemoteReplyRead.replyReads(forwarding); // Fork: lastReply reads with it", - "const forwarding = replyForwarding; // Fork: a reply there on another version is still read." - ] - } + "yield* unfollowed.pipe(Effect.ignoreCause({ log: true }));", + "import * as RemoteReplyRead from \"../fork/remoteReplyRead.ts\"; // Fork: replies across versions", + "const replyForwarding = RemoteReplyRead.replyReads(forwarding); // Fork: lastReply reads with it", + "const forwarding = replyForwarding; // Fork: a reply there on another version is still read." + ] }, "apps/web/src/components/ChatView.browser.test.tsx": { "why": "#474: upstream's test \"an interrupted image-only first send of a new thread says it may not have been sent\" presses Enter once the pasted image's tile shows. The tile shows while the image still compresses, and the composer refuses a send then (\"Still compressing a pasted image\"), so on a loaded runner the launch never came and the test went red. The fork line waits until the tile's preview button is enabled, which is when the image is ready. Drop this seam when upstream's test waits for the ready image itself.", diff --git a/FORK_CHANGES.md b/FORK_CHANGES.md index 714069cfef286..f79c40da78d6a 100644 --- a/FORK_CHANGES.md +++ b/FORK_CHANGES.md @@ -39,6 +39,7 @@ setting is missing here or a setting named here does not exist. | Review rules, part 1: the setting for how this machine runs a review lens (runner, state question), off by default; `{"preset": "recommended"}` turns the fork's defaults on. A bad hand edit reads as off and is kept. Nothing reads it yet. | The repo says what a pull request needs and CI enforces it; the machine says how reviews run. | `server.reviewRules`, `projectOverride.reviewRules` | off | [#291](https://github.com/scuttletoby/t3code/pull/291) | | An interval setting the settings file cannot hold (negative, not finite, too large) is refused when saved; one already in the file reads as its default instead of resetting every setting. A test finds every interval setting from the schema. | A `1e400` saved as `null` made the next start reject the whole settings file. | none | always | [#323](https://github.com/scuttletoby/t3code/pull/323) | | Handoff instead of compaction, part 2: the handoff service hands a big or idle thread to a fresh session in the same thread, with T3's state and the recent conversation, only while the thread is quiet and still at the run that triggered it. | Long threads keep their children, PRs and waits instead of compacting. | `server.handoff`, `projectOverride.handoff` | off | [#320](https://github.com/scuttletoby/t3code/pull/320) | +| A task delegated to a linked environment is still followed if the delegating call is cut off, and still delivers its reply when that environment runs another T3 version. | Its parent was never told: the task stayed running here and its result never arrived. | none | always | [#412](https://github.com/scuttletoby/t3code/pull/412), [#540](https://github.com/scuttletoby/t3code/pull/540) | ## Repository, CI and releases diff --git a/apps/server/src/fork/remoteReplyRead.test.ts b/apps/server/src/fork/remoteReplyRead.test.ts new file mode 100644 index 0000000000000..9e4bb5d05616b --- /dev/null +++ b/apps/server/src/fork/remoteReplyRead.test.ts @@ -0,0 +1,280 @@ +/** + * Fork: a task delegated to a linked environment on another version still completes with + * its reply when that environment's thread details no longer decode here. Upstream's + * `RemoteDelegation.test.ts` covers following itself. + */ +import { assert, it } from "@effect/vitest"; +import { + type EnvironmentId, + NodeId, + OrchestratorMcpFailure, + OrchestratorMcpThreadReadResult, + ProviderInstanceId, + RunId, + ThreadId, +} from "@t3tools/contracts"; +import * as Context from "effect/Context"; +import * as Deferred from "effect/Deferred"; +import * as SecureRandom from "effect/crypto/SecureRandom"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import * as Schedule from "effect/Schedule"; +import * as Schema from "effect/Schema"; +import * as Stream from "effect/Stream"; + +import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; +import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts"; +import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts"; +import * as PeerForwarding from "../peer/PeerForwarding.ts"; +import * as PeerLinks from "../peer/PeerLinks.ts"; +import * as RemoteDelegation from "../peer/RemoteDelegation.ts"; +import * as ProjectService from "../project/ProjectService.ts"; +import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts"; + +const box = "environment-box" as EnvironmentId; +const parentThreadId = ThreadId.make("thread:parent"); +const childThreadId = ThreadId.make("thread:box-child"); +const taskId = NodeId.make("node:task"); +const runId = RunId.make("run:box"); +const instanceId = ProviderInstanceId.make("codex"); +const at = "2026-11-19T10:00:00.000Z"; +const reply = "The review found two bugs; both are fixed on the branch."; + +/** A thread read as this version answers it, with one linked pull request. */ +const currentAnswer = { + thread: { + threadId: childThreadId, + projectId: "project:box", + title: "Review", + createdBy: "agent", + creationSource: "mcp", + status: "completed", + latestRunId: runId, + activeRunId: null, + providerInstanceId: instanceId, + model: "gpt-5.4", + runtimeMode: "full-access", + interactionMode: "default", + linkedPullRequest: null, + pullRequests: [ + { + host: "github.com", + repository: "acme/app", + number: 7, + url: "https://github.com/acme/app/pull/7", + source: "agent", + state: "open", + watching: false, + watchStartedAt: null, + }, + ], + titleRegeneration: null, + branch: null, + worktreePath: null, + parentThreadId: null, + relationshipToParent: null, + runCount: 1, + itemCount: 1, + pendingRequestCount: 0, + archived: false, + settled: false, + settledAt: null, + snoozed: false, + snoozedUntil: null, + createdAt: at, + updatedAt: at, + }, + recentRuns: [ + { + runId, + ordinal: 1, + status: "completed", + providerInstanceId: instanceId, + model: "gpt-5.4", + requestedAt: at, + startedAt: at, + completedAt: at, + }, + ], + items: [ + { + position: 0, + visibility: "local", + sourceThreadId: childThreadId, + itemId: "item:reply", + runId, + messageId: null, + createdBy: "agent", + creationSource: "provider", + type: "assistant_message", + status: "completed", + title: null, + text: reply, + textTruncated: false, + updatedAt: at, + }, + ], + nextPosition: null, + hasMore: false, +}; + +/** The same read from a build before linked pull requests carried their watch. */ +const olderAnswer = { + ...currentAnswer, + thread: { + ...currentAnswer.thread, + pullRequests: currentAnswer.thread.pullRequests.map( + ({ watching: _watching, watchStartedAt: _since, ...pullRequest }) => pullRequest, + ), + }, +}; + +/** An older answer whose reply item itself lacks a field this version requires. */ +const unreadableAnswer = { + ...olderAnswer, + items: olderAnswer.items.map(({ textTruncated: _truncated, ...item }) => item), +}; + +/** What the peer client does with an answer: decode it here or fail as it does. */ +const decodeAnswer = (success: Schema.Top, answer: unknown) => + Schema.decodeUnknownEffect(success as Schema.Decoder)(answer).pipe( + Effect.mapError( + () => + new OrchestratorMcpFailure({ + code: "orchestration_error", + message: + "The linked environment's answer did not match this version. Update both environments.", + }), + ), + ); + +/** + * The delegation service following one open task on the box, whose run there has ended and + * whose thread answers `answer`. `betaOff`: this machine's linked environments are off, so a + * call (not a follower's read) is refused. + */ +const followTask = (answer: unknown, options: { readonly betaOff?: boolean } = {}) => + Effect.gen(function* () { + const reads: Array<"read" | "reply-read"> = []; + const completed = yield* Deferred.make<{ readonly status: string; readonly result: string }>(); + const task = { + id: taskId, + status: "running", + result: null as string | null, + startedAt: null, + completedAt: null, + remoteChild: { + environmentId: box, + threadId: childThreadId, + label: "Box", + runId, + stoppedThere: undefined as boolean | undefined, + }, + }; + + const forwarding = Layer.mock(PeerForwarding.PeerForwarding)({ + waitForThread: () => + Effect.succeed({ threadId: childThreadId, runId, status: "completed", timedOut: false }), + readThread: () => + Effect.sync(() => reads.push("read")).pipe( + Effect.andThen(decodeAnswer(OrchestratorMcpThreadReadResult, answer)), + ) as never, + call: ((_scope: unknown, tool: { readonly name: string; readonly successSchema: never }) => { + if (tool.name !== "t3_thread_read") return Effect.die(`unexpected call ${tool.name}`); + if (options.betaOff) return Effect.fail(PeerForwarding.linkedEnvironmentsOff); + return Effect.sync(() => reads.push("reply-read")).pipe( + Effect.andThen(decodeAnswer(tool.successSchema, answer)), + ); + }) as never, + }); + + const threads = Layer.mock(ThreadManagement.ThreadManagementService)({ + getThreadEventSequence: () => Effect.succeed(0) as never, + getThreadRecords: (() => + Effect.sync(() => ({ + thread: { id: parentThreadId, providerInstanceId: instanceId }, + subagents: [structuredClone(task)], + }))) as never, + streamStoredEventsFrom: () => Stream.never, + streamDomainEvents: Stream.never, + dispatch: ((command: { + readonly type: string; + readonly status: string; + readonly result: string; + }) => + Effect.gen(function* () { + if (command.type !== "delegated_task.remote.complete") { + return yield* Effect.die(`unexpected command ${command.type}`); + } + task.status = command.status; + task.result = command.result; + task.remoteChild.stoppedThere = true; + yield* Deferred.succeed(completed, { status: command.status, result: command.result }); + return { storedEvents: [] }; + })) as never, + }); + + const remote = yield* Layer.build( + RemoteDelegation.layer.pipe( + Layer.provide( + Layer.mergeAll( + forwarding, + threads, + Layer.mock(PeerLinks.PeerLinks)({ get: () => Effect.succeedNone }), + Layer.mock(ProjectionStore.ProjectionStoreV2)({ + getOpenRemoteDelegatedTasks: Effect.succeed([{ parentThreadId, taskId }]), + }), + Layer.mock(ProjectService.ProjectService)({}), + Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({}), + Layer.mock(ServerEnvironment.ServerEnvironment)({ + getEnvironmentId: Effect.succeed("environment-here" as EnvironmentId), + }), + Layer.succeed(SecureRandom.SecureRandom, { + uuidV4: () => Effect.succeed("00000000-0000-4000-8000-000000000000"), + } as never), + ), + ), + ), + ).pipe( + // Two retries, at once, before the follower gives up on the task. + Effect.provideService(RemoteDelegation.FollowRetrySchedule, Schedule.recurs(2)), + Effect.map(Context.get(RemoteDelegation.RemoteDelegation)), + ); + yield* remote.start(); + return { completion: yield* Deferred.await(completed), reads }; + }); + +it.effect("this version's own answer is read once, as before", () => + Effect.scoped( + Effect.gen(function* () { + const { completion, reads } = yield* followTask(currentAnswer); + assert.deepStrictEqual(completion, { status: "completed", result: reply }); + assert.deepStrictEqual(reads, ["read"]); + }), + ), +); + +it.effect("an older version's answer still completes the task with its reply", () => + Effect.scoped( + Effect.gen(function* () { + const { completion, reads } = yield* followTask(olderAnswer); + assert.deepStrictEqual(completion, { status: "completed", result: reply }); + assert.deepStrictEqual(reads, ["read", "reply-read"]); + }), + ), +); + +it.effect.each([ + ["whose reply does not decode either", unreadableAnswer, {}], + ["while linked environments are off here", olderAnswer, { betaOff: true }], +] as const)("an older version's answer %s fails the task as before", ([, answer, options]) => + Effect.scoped( + Effect.gen(function* () { + const { completion } = yield* followTask(answer, options); + assert.strictEqual(completion.status, "failed"); + assert.include(completion.result, "failed repeatedly"); + // Never the second read's own refusal. + assert.notInclude(completion.result, "Linked environments is off"); + }), + ), +); diff --git a/apps/server/src/fork/remoteReplyRead.ts b/apps/server/src/fork/remoteReplyRead.ts new file mode 100644 index 0000000000000..c70af993a0670 --- /dev/null +++ b/apps/server/src/fork/remoteReplyRead.ts @@ -0,0 +1,49 @@ +/** + * Fork: a task's reply from a linked environment on another version. Its thread details may lack a + * field this version requires, which fails the whole read and kept the task running forever; the + * reply needs none of them. Runs and items keep their schemas, so a reply is never guessed. + */ +import { + OrchestratorMcpFailure, + OrchestratorMcpThreadReadInput, + OrchestratorMcpThreadReadResult, +} from "@t3tools/contracts"; +import * as Effect from "effect/Effect"; +import * as Struct from "effect/Struct"; +import * as Tool from "effect/ai/Tool"; + +import type * as PeerForwarding from "../peer/PeerForwarding.ts"; + +/** A thread read without the thread's details: all a task's reply is read from. */ +export const ReplyPage = OrchestratorMcpThreadReadResult.mapFields(Struct.omit(["thread"])); +export type ReplyPage = typeof ReplyPage.Type; + +/** `t3_thread_read` there, decoding its answer as a ReplyPage. */ +const ReplyRead = Tool.make("t3_thread_read", { + parameters: OrchestratorMcpThreadReadInput, + success: ReplyPage, + failure: OrchestratorMcpFailure, + failureMode: "return", +}); + +type Forwarding = PeerForwarding.PeerForwarding["Service"]; + +/** + * Reads a task's reply there: the full read, then, if that fails as an answer this version cannot + * decode does (`orchestration_error`), the same read as a ReplyPage. If that fails too, or `call` + * refuses it because linked environments are off here, the first error stands, as before. + */ +export const replyReads = (forwarding: Forwarding) => ({ + readThread: ( + ...[scope, environmentId, input]: Parameters + ): Effect.Effect => + forwarding.readThread(scope, environmentId, input).pipe( + Effect.catchIf( + (error) => error.code === "orchestration_error", + (error) => + forwarding + .call(scope, ReplyRead, environmentId, input) + .pipe(Effect.mapError(() => error)), + ), + ), +}); diff --git a/apps/server/src/peer/RemoteDelegation.ts b/apps/server/src/peer/RemoteDelegation.ts index 766020b255e4d..5f9c49e767643 100644 --- a/apps/server/src/peer/RemoteDelegation.ts +++ b/apps/server/src/peer/RemoteDelegation.ts @@ -44,6 +44,7 @@ import { followUpOwnerRun } from "../orchestration-v2/CommandPolicy.ts"; import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts"; import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; +import * as RemoteReplyRead from "../fork/remoteReplyRead.ts"; // Fork: replies across versions import * as ProjectService from "../project/ProjectService.ts"; import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts"; import { forkParked } from "../serverActivation.ts"; @@ -614,6 +615,8 @@ const make = Effect.gen(function* () { }) .pipe(Effect.asVoid); + const replyForwarding = RemoteReplyRead.replyReads(forwarding); // Fork: lastReply reads with it + /** * The last reply `runId` gave on the task's thread there, which is its * result, read whole however long it is. A failed run prefers its error @@ -626,6 +629,7 @@ const make = Effect.gen(function* () { runId: RunId | null, failed = false, ) { + const forwarding = replyForwarding; // Fork: a reply there on another version is still read. let reply: OrchestratorMcpThreadTimelineItem | undefined; let error: OrchestratorMcpThreadTimelineItem | undefined; let afterPosition: number | undefined;