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
15 changes: 5 additions & 10 deletions .github/fork-seams.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions FORK_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
| Model policy, part 1: the setting for which models (and efforts) agents may pick, per provider driver: off, advise or enforce, and the allowed rows. A bad hand edit reads as nothing allowed. Nothing reads the setting yet. | Agents should use the models the person chose for each kind of work. | `server.modelPolicy` | off | [#268](https://github.com/scuttletoby/t3code/pull/268) |

## Repository, CI and releases
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/fork/personOnlySettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const toolsDefinedElsewhere = (): ReadonlyArray<string> => {
const NOT_ADVERTISED: Readonly<Record<string, string>> = {
// Describes the linked environment's `orchestrator_capabilities` to call it there.
"peer/RemoteDelegation.ts": "a client of another environment's tool",
// Decodes the linked environment's `t3_thread_read` without the thread's details.
"fork/remoteReplyRead.ts": "a client of another environment's tool",
};

// A toolkit: an object whose `tools` are all `Tool`s (Toolkit exports no type guard).
Expand Down
280 changes: 280 additions & 0 deletions apps/server/src/fork/remoteReplyRead.test.ts
Original file line number Diff line number Diff line change
@@ -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<unknown>)(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");
}),
),
);
49 changes: 49 additions & 0 deletions apps/server/src/fork/remoteReplyRead.ts
Original file line number Diff line number Diff line change
@@ -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<Forwarding["readThread"]>
): Effect.Effect<ReplyPage, OrchestratorMcpFailure> =>
forwarding.readThread(scope, environmentId, input).pipe(
Effect.catchIf(
(error) => error.code === "orchestration_error",
(error) =>
forwarding
.call(scope, ReplyRead, environmentId, input)
.pipe(Effect.mapError(() => error)),
),
),
});
Loading
Loading