@devries-cameron20 / t3code Mirror · read-only / commits / 9359081c24
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 21:00 UTC

fix(server): a pull request watch started after a pending self-settle survives the turn end (#34884)

Julius Marminge committed Nov 11, 2026 at 23:51 UTC 9359081c2471045ca4af90dfac1b01d1d43aa860
2 files changed +86
apps/server/src/orchestration-v2/ThreadManagementService.ts
+11
@@ -62,6 +62,7 @@ import * as CommandReceiptStore from "./CommandReceiptStore.ts";
62 import * as Orchestrator from "./Orchestrator.ts";
63 import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
64 import { projectedRowEncodedBytes } from "./threadHistoryPaging.ts";
65 +import { threadPullRequestsOf } from "../sourceControl/threadPullRequests.ts";
66 import * as ProviderSessionManager from "./ProviderSessionManager.ts";
67 import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts";
68 import { DispatchModeLimit, exceededDispatchModeLimit } from "./DispatchModeLimit.ts";
@@ -1066,12 +1067,22 @@ const make = Effect.gen(function* () {
1067 const settleAfterRun: ThreadManagementServiceShape["settleAfterRun"] = Effect.fn(
1068 "orchestrationV2.threadManagement.settleAfterRun",
1069 )(function* (input) {
1070 + const requestedAt = yield* DateTime.now;
1071 const { run } = yield* waitForThread({ ...input, timeoutMs: SETTLE_AFTER_RUN_WAIT_MS });
1072 if (run?.status !== "completed") return;
1073 const afterSequence = yield* orchestrator.getThreadEventSequence(input.threadId);
1074 const trySettle = Effect.gen(function* () {
1075 const sequence = yield* orchestrator.getThreadEventSequence(input.threadId);
1076 const records = yield* getProjectThreadRecords(input, ["runs"]);
1077 + // Settling ends every watch; one the agent started after asking to settle must outlive it.
1078 + if (
1079 + threadPullRequestsOf(records.thread).some(
1080 + (link) =>
1081 + link.watch !== undefined &&
1082 + !DateTime.isLessThan(DateTime.makeUnsafe(link.watch.startedAt), requestedAt),
1083 + )
1084 + )
1085 + return true;
1086 const following = records.runs.filter((candidate) => candidate.ordinal > run.ordinal);
1087 if (following.length > 0) {
1088 const { messages } = yield* getProjectThreadRecords(input, ["messages"], {
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+75
@@ -5761,6 +5761,81 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
5761 }),
5762 );
5763
5764 + it.effect("keeps a pull request watch its agent started after asking to settle", () =>
5765 + Effect.gen(function* () {
5766 + const orchestrator = yield* Orchestrator.OrchestratorV2;
5767 + const eventSink = yield* EventSink.EventSinkV2;
5768 + const threadManagement = yield* ThreadManagementService.ThreadManagementService;
5769 + const projectId = ProjectId.make("runtime-layer-settle-then-watch-project");
5770 + const threadId = ThreadId.make("runtime-layer-settle-then-watch-thread");
5771 +
5772 + yield* orchestrator.dispatch({
5773 + type: "thread.create",
5774 + createdBy: "user",
5775 + creationSource: "web",
5776 + commandId: CommandId.make("runtime-layer-settle-then-watch-create"),
5777 + threadId,
5778 + projectId,
5779 + title: "Settle then watch",
5780 + modelSelection,
5781 + runtimeMode: "full-access",
5782 + interactionMode: "default",
5783 + branch: null,
5784 + worktreePath: "/tmp/runtime-layer-settle-then-watch",
5785 + });
5786 + yield* orchestrator.dispatch({
5787 + type: "message.dispatch",
5788 + createdBy: "user",
5789 + creationSource: "web",
5790 + commandId: CommandId.make("runtime-layer-settle-then-watch-message"),
5791 + threadId,
5792 + messageId: MessageId.make("runtime-layer-settle-then-watch-message"),
5793 + text: "Settle this thread, then watch the pull request.",
5794 + attachments: [],
5795 + modelSelection,
5796 + dispatchMode: { type: "start_immediately" },
5797 + });
5798 + const run = (yield* orchestrator.getThreadProjection(threadId)).runs[0];
5799 + if (run === undefined) return yield* Effect.die(new Error("Run missing."));
5800 +
5801 + // The deferred settle `settleThread` forks for its own agent's active run.
5802 + const settleRequest = yield* threadManagement
5803 + .settleAfterRun({ projectId, threadId, runId: run.id })
5804 + .pipe(Effect.forkChild);
5805 + yield* orchestrator.dispatch({
5806 + type: "thread.pull-request.watch",
5807 + commandId: CommandId.make("runtime-layer-settle-then-watch-watch"),
5808 + threadId,
5809 + host: "github.com",
5810 + repository: "pingdotgg/t3code",
5811 + number: 7,
5812 + watching: true,
5813 + link: { url: "https://github.com/pingdotgg/t3code/pull/7", source: "agent" },
5814 + });
5815 + assert.isDefined((yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch);
5816 +
5817 + const now = yield* DateTime.now;
5818 + yield* eventSink.write({
5819 + commandId: CommandId.make("runtime-layer-settle-then-watch-completed"),
5820 + events: [
5821 + {
5822 + id: EventId.make("runtime-layer-settle-then-watch-completed"),
5823 + type: "run.updated",
5824 + threadId,
5825 + runId: run.id,
5826 + occurredAt: now,
5827 + payload: { ...run, status: "completed", startedAt: now, completedAt: now },
5828 + },
5829 + ],
5830 + });
5831 + yield* Fiber.join(settleRequest);
5832 +
5833 + const shell = yield* orchestrator.getThreadShell(threadId);
5834 + assert.isDefined(shell?.pullRequests?.[0]?.watch);
5835 + assert.isNull(shell?.settledOverride ?? null);
5836 + }),
5837 + );
5838 +
5839 it.effect("settles past held automatic runs but not held user messages", () =>
5840 Effect.gen(function* () {
5841 const orchestrator = yield* Orchestrator.OrchestratorV2;