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, 07:15 UTC
fix(server): a PR watch the agent owns keeps its thread working until the PR merges (#38926)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 18, 2026 at 21:49 UTC
28d96a2a49bc8d2e215da32958082aeb36985892
14 files changed
+187
-54
apps/server/src/mcp/toolkits/pullRequests/handlers.ts
+10
-7
@@ -2,6 +2,7 @@ import {
2
CommandId,
3
type OrchestrationProjectShell,
4
type PullRequestState,
5
+ type PullRequestWatchUntil,
6
type OrchestrationV2ThreadShell,
7
type ThreadId,
8
type ThreadPullRequestLink,
@@ -199,18 +200,20 @@ const make = Effect.gen(function* () {
200
201
// The domain service owns the registration span.
202
const setWatching = Effect.fnUntraced(function* (
202
- input: PullRequestTargetInput,
203
+ input: PullRequestTargetInput & { readonly until?: PullRequestWatchUntil | undefined },
204
watching: boolean,
205
) {
206
const scope = yield* McpInvocationContext.requireMcpCapability("pull-requests");
207
const threadId = input.threadId ?? scope.thread?.threadId;
208
if (threadId === undefined) return yield* new PullRequestThreadRequiredError();
208
- return yield* watches.setWatching({ threadId, target: input, watching }).pipe(
209
- Effect.catchTags({
210
- PullRequestWatchThreadNotFoundError: (error) =>
211
- threadNotFound(engine, scope, error.threadId, error.message),
212
- }),
213
- );
209
+ return yield* watches
210
+ .setWatching({ threadId, target: input, watching, until: input.until })
211
+ .pipe(
212
+ Effect.catchTags({
213
+ PullRequestWatchThreadNotFoundError: (error) =>
214
+ threadNotFound(engine, scope, error.threadId, error.message),
215
+ }),
216
+ );
217
});
218
219
const locateAll = Effect.fn("PullRequestsToolkit.locateAll")(function* (
apps/server/src/mcp/toolkits/pullRequests/tools.ts
+12
-1
@@ -7,6 +7,7 @@ import {
7
PullRequestReviewGuideRun,
8
PullRequestState,
9
PullRequestUnavailableError,
10
+ PullRequestWatchUntil,
11
ThreadPullRequestLinkSource,
12
TrimmedNonEmptyString,
13
ThreadId,
@@ -324,10 +325,20 @@ const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
325
.annotate(Tool.Idempotent, true)
326
.annotate(Tool.OpenWorld, false);
327
328
+const WatchPullRequestInput = Schema.Struct({
329
+ ...PullRequestTargetInput.fields,
330
+ until: Schema.optional(
331
+ PullRequestWatchUntil.annotate({
332
+ description:
333
+ 'How long this thread stays working. Omit it to keep the current value; a new watch starts at "checks". "checks": until checks finish, for a PR you hand to the user. "merged": until it merges or closes or you unwatch it, when you will act on it yourself, such as merging after someone else approves.',
334
+ }),
335
+ ),
336
+});
337
+
338
const WatchPullRequestTool = Tool.make("watch_pull_request", {
339
description:
340
"Watch an open PR for this thread, linking it first if needed. T3 wakes you on failed checks, passed required checks, new comments or reviews, or conflicts. Handle old comments first. Only later ones wake you. After this call, end your turn. The watch stays on after each wake, so do not call this again on a wake. A wake is not a merge decision. Check readiness yourself.",
330
- parameters: PullRequestTargetInput,
341
+ parameters: WatchPullRequestInput,
342
success: WatchPullRequestResult,
343
failure: PullRequestToolError,
344
dependencies: watchDependencies,
apps/server/src/orchestration-v2/Orchestrator.ts
+55
-39
@@ -40,6 +40,7 @@ import {
40
type OrchestrationV2ServerCommand,
41
type ThreadPullRequestLink,
42
type ThreadPullRequestWatch,
43
+ type PullRequestWatchUntil,
44
type OrchestrationV2AppThread,
45
type OrchestrationV2ContextHandoff,
46
type OrchestrationV2ContextSourcePoint,
@@ -892,11 +893,23 @@ function syncedPullRequestWatch(
893
},
894
): ThreadPullRequestWatch | undefined {
895
if (command.watch === null) return undefined;
896
+ // Only the agent sets `until`, so a read in flight keeps what the watch has now.
897
+ const watch = withUntil(command.watch, existing?.until ?? "checks");
898
// A push cleared the answer while this read was in flight, so its answer is the old head's.
899
if (command.checksPendingBefore === undefined || existing?.checksPending !== undefined) {
897
- return command.watch;
900
+ return watch;
901
}
899
- return withoutChecksAnswer(command.watch);
902
+ return withoutChecksAnswer(watch);
903
+}
904
+
905
+function withUntil(
906
+ watch: ThreadPullRequestWatch,
907
+ until: PullRequestWatchUntil | undefined,
908
+): ThreadPullRequestWatch {
909
+ if (until === undefined || until === (watch.until ?? "checks")) return watch;
910
+ if (until === "merged") return { ...watch, until };
911
+ const { until: _checks, ...rest } = watch;
912
+ return rest;
913
}
914
915
const withoutChecksAnswer = ({
@@ -5077,43 +5090,46 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5090
: existing.watch
5091
: !command.watching
5092
? undefined
5080
- : (existing.watch ?? {
5081
- startedAt,
5082
- headSha: null,
5083
- failedChecks: [],
5084
- passed: false,
5085
- passedChecks: [],
5086
- conflicting: false,
5087
- // Watching again must not repeat check or conflict news the last watch told.
5088
- ...(existing.endedWatch && {
5089
- headSha: existing.endedWatch.headSha,
5090
- failedChecks: existing.endedWatch.failedChecks,
5091
- passed: existing.endedWatch.passed,
5092
- passedChecks: existing.endedWatch.passedChecks,
5093
- conflicting: existing.endedWatch.conflicting,
5094
- rebaseRequired: existing.endedWatch.rebaseRequired,
5095
- }),
5096
- awaitingBaseline: existing.endedWatch
5097
- ? existing.endedWatch.awaitingBaseline
5098
- : "all",
5099
- ...(existing.endedWatch?.owedChecks !== undefined && {
5100
- owedChecks: existing.endedWatch.owedChecks,
5101
- }),
5102
- ...(existing.endedWatch?.awaitingApproval !== undefined && {
5103
- awaitingApproval: existing.endedWatch.awaitingApproval,
5104
- }),
5105
- ...(existing.endedWatch?.approvalAnnounced !== undefined && {
5106
- approvalAnnounced: existing.endedWatch.approvalAnnounced,
5107
- }),
5108
- // A finished-checks answer may be an older head's; a fresh read decides.
5109
- ...(existing.endedWatch?.checksPending === true && { checksPending: true }),
5110
- ...(existing.endedWatch?.checksAwaitedSince !== undefined && {
5111
- checksAwaitedSince: existing.endedWatch.checksAwaitedSince,
5112
- }),
5113
- remarksThrough: startedAt,
5114
- remarkIds: [],
5115
- wakes: 0,
5116
- });
5093
+ : withUntil(
5094
+ existing.watch ?? {
5095
+ startedAt,
5096
+ headSha: null,
5097
+ failedChecks: [],
5098
+ passed: false,
5099
+ passedChecks: [],
5100
+ conflicting: false,
5101
+ // Watching again must not repeat check or conflict news the last watch told.
5102
+ ...(existing.endedWatch && {
5103
+ headSha: existing.endedWatch.headSha,
5104
+ failedChecks: existing.endedWatch.failedChecks,
5105
+ passed: existing.endedWatch.passed,
5106
+ passedChecks: existing.endedWatch.passedChecks,
5107
+ conflicting: existing.endedWatch.conflicting,
5108
+ rebaseRequired: existing.endedWatch.rebaseRequired,
5109
+ }),
5110
+ awaitingBaseline: existing.endedWatch
5111
+ ? existing.endedWatch.awaitingBaseline
5112
+ : "all",
5113
+ ...(existing.endedWatch?.owedChecks !== undefined && {
5114
+ owedChecks: existing.endedWatch.owedChecks,
5115
+ }),
5116
+ ...(existing.endedWatch?.awaitingApproval !== undefined && {
5117
+ awaitingApproval: existing.endedWatch.awaitingApproval,
5118
+ }),
5119
+ ...(existing.endedWatch?.approvalAnnounced !== undefined && {
5120
+ approvalAnnounced: existing.endedWatch.approvalAnnounced,
5121
+ }),
5122
+ // A finished-checks answer may be an older head's; a fresh read decides.
5123
+ ...(existing.endedWatch?.checksPending === true && { checksPending: true }),
5124
+ ...(existing.endedWatch?.checksAwaitedSince !== undefined && {
5125
+ checksAwaitedSince: existing.endedWatch.checksAwaitedSince,
5126
+ }),
5127
+ remarksThrough: startedAt,
5128
+ remarkIds: [],
5129
+ wakes: 0,
5130
+ },
5131
+ command.until,
5132
+ );
5133
if (watch === existing.watch && links === linked) return thread;
5134
const final =
5135
command.type === "thread.pull-request-watch.sync" && watch === undefined
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+2
-1
@@ -229,7 +229,8 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
229
left.wakes === right.wakes &&
230
left.awaitingBaseline === right.awaitingBaseline &&
231
left.checksAwaitedSince === right.checksAwaitedSince &&
232
- left.checksPending === right.checksPending
232
+ left.checksPending === right.checksPending &&
233
+ left.until === right.until
234
);
235
}
236
apps/server/src/orchestration-v2/pullRequestWatch.ts
+1
@@ -256,6 +256,7 @@ export function evaluatePullRequestWatch(
256
}),
257
checksAwaitedSince,
258
checksPending,
259
+ ...(watch.until !== undefined && { until: watch.until }),
260
},
261
exhausted: commentsOnly && wakes >= PULL_REQUEST_WATCH_WAKE_LIMIT,
262
};
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+68
@@ -31,6 +31,7 @@ import {
31
type PullRequestDetail,
32
type PullRequestComment,
33
PullRequestOperationError,
34
+ type PullRequestWatchUntil,
35
ProviderDriverKind,
36
ProviderInstanceId,
37
ProviderSessionId,
@@ -4280,6 +4281,73 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
4281
}),
4282
);
4283
4284
+ it.effect("keeps how long a watch holds across reads until the agent changes it", () =>
4285
+ Effect.gen(function* () {
4286
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
4287
+ const maintenance = yield* ProjectionReplay.ProjectionReplay;
4288
+ const threadId = ThreadId.make("runtime-pull-request-watch-until-merged");
4289
+ yield* orchestrator.dispatch({
4290
+ type: "thread.create",
4291
+ createdBy: "user",
4292
+ creationSource: "web",
4293
+ commandId: CommandId.make("pr-watch-until-create"),
4294
+ threadId,
4295
+ projectId: ProjectId.make("pr-watch-project"),
4296
+ title: "Watch until merged",
4297
+ modelSelection,
4298
+ runtimeMode: "full-access",
4299
+ interactionMode: "default",
4300
+ branch: null,
4301
+ worktreePath: null,
4302
+ });
4303
+ const key = { host: "github.com", repository: "pingdotgg/t3code", number: 7 };
4304
+ const watchOf = Effect.map(
4305
+ orchestrator.getThreadShell(threadId),
4306
+ (thread) => thread?.pullRequests?.[0]?.watch,
4307
+ );
4308
+ const watch = (id: string, until?: PullRequestWatchUntil) =>
4309
+ orchestrator.dispatch({
4310
+ type: "thread.pull-request.watch",
4311
+ commandId: CommandId.make(id),
4312
+ threadId,
4313
+ ...key,
4314
+ watching: true,
4315
+ link: { url: "https://github.com/pingdotgg/t3code/pull/7", source: "agent" },
4316
+ ...(until !== undefined && { until }),
4317
+ });
4318
+
4319
+ yield* watch("pr-watch-until-start");
4320
+ assert.isUndefined((yield* watchOf)?.until);
4321
+
4322
+ yield* watch("pr-watch-until-on", "merged");
4323
+ const started = yield* watchOf;
4324
+ assert.equal(started?.until, "merged");
4325
+ if (started === undefined) return;
4326
+
4327
+ // A read that began before the agent set it must not drop it.
4328
+ const { until: _read, ...readBefore } = started;
4329
+ yield* orchestrator.dispatch({
4330
+ type: "thread.pull-request-watch.sync",
4331
+ commandId: CommandId.make("pr-watch-until-record"),
4332
+ threadId,
4333
+ ...key,
4334
+ startedAt: started.startedAt,
4335
+ watch: { ...readBefore, headSha: "abc123", checksPending: false },
4336
+ });
4337
+ assert.equal((yield* watchOf)?.until, "merged");
4338
+ assert.equal((yield* watchOf)?.headSha, "abc123");
4339
+
4340
+ yield* watch("pr-watch-until-again");
4341
+ assert.equal((yield* watchOf)?.until, "merged");
4342
+ assert.isTrue((yield* maintenance.rebuild).valid);
4343
+ assert.equal((yield* watchOf)?.until, "merged");
4344
+
4345
+ yield* watch("pr-watch-until-off", "checks");
4346
+ assert.isUndefined((yield* watchOf)?.until);
4347
+ assert.equal((yield* watchOf)?.headSha, "abc123");
4348
+ }),
4349
+ );
4350
+
4351
it.effect.each(["manual", "automatic"])("settling ends every pull request watch: %s", (mode) =>
4352
Effect.gen(function* () {
4353
const orchestrator = yield* Orchestrator.OrchestratorV2;
apps/server/src/provider/agentContextBudget.json
+1
-1
@@ -1,5 +1,5 @@
1
{
2
"claudeSystemAppendBytes": 6037,
3
"codexAdditionalContextBytes": 7431,
4
- "mcpToolListJsonBytes": 52145
4
+ "mcpToolListJsonBytes": 52519
5
}
apps/server/src/pullRequest/PullRequestWatchService.ts
+4
@@ -3,6 +3,7 @@ import {
3
ThreadId,
4
type OrchestrationV2ThreadShell,
5
type PullRequestUnavailableError,
6
+ type PullRequestWatchUntil,
7
} from "@t3tools/contracts";
8
import * as Cause from "effect/Cause";
9
import * as Context from "effect/Context";
@@ -69,6 +70,7 @@ export class PullRequestWatchService extends Context.Service<
70
readonly threadId: ThreadId;
71
readonly target: PullRequestTarget;
72
readonly watching: boolean;
73
+ readonly until?: PullRequestWatchUntil | undefined;
74
}) => Effect.Effect<
75
ResolvedTarget & { readonly watching: boolean; readonly wasWatching: boolean },
76
| PullRequestWatchFailedError
@@ -104,6 +106,7 @@ const make = Effect.gen(function* () {
106
readonly threadId: ThreadId;
107
readonly target: PullRequestTarget;
108
readonly watching: boolean;
109
+ readonly until?: PullRequestWatchUntil | undefined;
110
}) {
111
const { watching } = input;
112
const thread = yield* requireThread(input.threadId);
@@ -158,6 +161,7 @@ const make = Effect.gen(function* () {
161
number: target.number,
162
watching,
163
...(watching ? { link: { url: target.url, source: "agent" as const } } : {}),
164
+ ...(watching && input.until !== undefined && { until: input.until }),
165
})
166
.pipe(
167
Effect.catchCause((cause) =>
docs/user/source-control.md
+4
-2
@@ -351,8 +351,10 @@ A watched thread counts as working while the pull request still has checks runni
351
the **Working** section, including after the agent pushes a fix. Once every check has finished,
352
including review bots that report as checks, the thread returns to your inbox: what happens next is
353
up to a person. That includes a workflow waiting for a maintainer to approve it, which runs only
354
-once someone does. The watch stays on and still wakes the agent on new comments, failed checks or
355
-conflicts, and a watched thread never auto-settles.
354
+once someone does. If you ask the agent to act on the pull request itself, such as merging it once
355
+a teammate approves, the thread stays in **Working** until the pull request merges or closes. The
356
+watch stays on and still wakes the agent on new comments, failed checks or conflicts, and a watched
357
+thread never auto-settles.
358
359
Cross-repository links use a project on the same host. Azure DevOps reviews require a project checked
360
out from the matching organization and repository.
evals/mcp-tool-use/cases/pull-requests.ndjson
+2
@@ -37,3 +37,5 @@
37
{"id": "link-one-pr", "area": "pull-requests", "privacy": "commit-safe", "kind": "control", "pattern": "single link stays single", "experience": "Linking one named PR is ordinary work.", "setup": {"role": "top", "context": "No pull requests are linked to this thread.", "world": {"repo": "acme/app", "branch": "main"}}, "prompt": "link https://github.com/acme/app/pull/130 here", "expect": {"calls": [{"tool": "link_pull_request", "args": {"url": "~/pull/130"}}], "notCalls": ["link_pull_requests"]}, "maxSteps": 6, "source": {"thread": "Synthetic control for batch link"}}
38
{"id": "schedule-one-time-date", "area": "pull-requests", "kind": "bad", "pattern": "one-off date scheduled as a daily task", "experience": "Theo asked whether a scheduled task can run at a specific date and time. schedule_task only had daily times, intervals, and webhooks, so a one-off request became a daily task.", "source": {"report": "maintainer request, 2026-10-31: scheduled tasks could not run at one date and time"}, "rule": "schedule: {type:'once',runAt} for one date and time", "privacy": "commit-safe", "setup": {"role": "top", "mocks": {"schedule_task": {"scheduledTaskId": "scheduled-task-4", "title": "Cut 2.0 release branch", "schedule": {"type": "once", "runAt": "2026-11-03T09:00:00.000Z"}, "enabled": true, "nextRunAt": "2026-11-03T09:00:00.000Z"}}}, "prompt": "On November 3rd at 9am UTC, start a new thread that cuts the 2.0 release branch from main in acme/app. Only that one time.", "expect": {"calls": [{"tool": "schedule_task", "args": {"schedule.type": "once", "schedule.runAt": "~11-03T09:00"}}], "notCalls": ["delegate_task", "run_scheduled_task_now"]}, "notes": "Mock result shape is an approximation."}
39
{"id": "schedule-fresh-session-per-run", "area": "pull-requests", "kind": "guard", "pattern": "recurring task that should not accumulate context", "experience": "A recurring triage task kept one thread so the user could read its history, but each run carried every earlier run's context into the next.", "rule": "schedule_task `freshSession: true` keeps runs in one thread while each run starts a fresh session.", "privacy": "commit-safe", "setup": {"role": "top", "context": "Today is Monday 2026-11-02, 10:00 local time.", "mocks": {"schedule_task": {"scheduledTaskId": "scheduled-task-7", "title": "Triage new issues", "enabled": true, "projectId": "project-1", "boundThreadId": null, "freshSession": true, "schedule": {"type": "fixed_time", "timeOfDay": "09:00"}, "nextRunAt": "2026-11-03T09:00:00-08:00", "lastRunStatus": "never"}}}, "prompt": "Every morning at 9, triage new issues in acme/app. Keep all the runs in one thread so I can scroll back, but each run should start clean without remembering the previous days.", "expect": {"calls": [{"tool": "schedule_task", "args": {"schedule.type": "fixed_time", "freshSession": true}}], "notCalls": ["delegate_task", "run_scheduled_task_now"]}, "source": {"request": "juliusmarminge (maintainer) request, 2026-11-03: automations in one thread with separate provider sessions"}, "notes": "schedule-one-off-tomorrow is the control: an ordinary schedule must not set freshSession."}
40
+{"id": "babysit-merge-after-approval-until-merged", "area": "pull-requests", "kind": "bad", "pattern": "babysit until a teammate approves, then merge, watching only until checks finish", "experience": "Asked to babysit a PR and merge it once a teammate approved, the agent watched it only until checks finished, so the thread left Working as soon as checks passed while the agent still owned the merge.", "rule": "until: merged when you will act on the PR yourself, such as merging it after someone else approves", "privacy": "commit-safe", "setup": {"role": "top", "priorTurns": [{"role": "user", "text": "The HTML preview frame has no accessible name. Fix it and open a PR."}, {"role": "assistant", "text": "Opened [PR #124](https://github.com/acme/app/pull/124). The preview frame now has the title \"HTML preview\".", "toolCalls": [{"tool": "Bash", "input": {"command": "git push -u origin fix/html-preview-title && gh pr create --fill"}, "result": "https://github.com/acme/app/pull/124"}, {"tool": "link_pull_request", "input": {"url": "https://github.com/acme/app/pull/124"}, "result": {"host": "github.com", "repository": "acme/app", "number": 124, "url": "https://github.com/acme/app/pull/124", "alreadyLinked": false}}]}], "mocks": {"watch_pull_request": "default", "link_pull_request": "default"}, "world": {"branch": "fix/html-preview-title", "commits": [{"sha": "abc1234", "subject": "fix(web): HTML preview frame gets an accessible title"}], "diff": "diff --git a/apps/web/src/HtmlPreview.tsx b/apps/web/src/HtmlPreview.tsx\n--- a/apps/web/src/HtmlPreview.tsx\n+++ b/apps/web/src/HtmlPreview.tsx\n@@ -1,3 +1,3 @@\n export function HtmlPreview({ html }: { html: string }) {\n- return <iframe sandbox=\"allow-scripts\" srcDoc={html} height={400} />;\n+ return <iframe title=\"HTML preview\" sandbox=\"allow-scripts\" srcDoc={html} height={400} />;\n }\n", "prs": [{"number": 124, "title": "fix(web): HTML preview frame gets an accessible title", "headRefName": "fix/html-preview-title", "reviewDecision": "REVIEW_REQUIRED", "reviewRequests": ["sam-acme"], "checks": [{"name": "Lint", "state": "pass"}, {"name": "Typecheck", "state": "pass"}, {"name": "Test Web", "state": "pass"}]}], "files": {"apps/web/src/HtmlPreview.tsx": "export function HtmlPreview({ html }: { html: string }) {\n return <iframe title=\"HTML preview\" sandbox=\"allow-scripts\" srcDoc={html} height={400} />;\n}\n"}}}, "prompt": "Every PR here needs a teammate's approval. Babysit PR #124 and merge it once Sam approves it.", "expect": {"calls": [{"tool": "watch_pull_request", "args": {"url": "~/pull/124", "until": "merged"}}], "notCalls": ["Monitor", "ScheduleWakeup", "CronCreate"], "shellMustNot": ["\\bsleep \\d", "gh pr checks[^\\n]*--watch", "gh run watch", "\\buntil\\b[^\\n]*\\bgh (pr|run|api)\\b", "gh pr merge(?![^\\n]*--auto)"], "endsTurnAfter": "watch_pull_request"}, "notes": "pingdotgg/t3code#36230: since #33214 a watch stops holding its thread once checks finish. gh pr merge --auto plus the watch is fine; a plain merge before approval is not."}
41
+{"id": "control-handoff-pr-not-until-merged", "area": "pull-requests", "kind": "control", "pattern": "PR handed to the user for review", "experience": "A PR the agent hands to the user for review must not keep the thread working until it merges.", "rule": "until: checks (the default) for a PR handed to the user", "privacy": "commit-safe", "setup": {"role": "top", "priorTurns": [{"role": "user", "text": "The HTML preview frame has no accessible name. Fix it."}, {"role": "assistant", "text": "Fixed on branch fix/html-preview-title (commit abc1234). The preview frame now has the title \"HTML preview\". Want a PR?", "toolCalls": [{"tool": "Bash", "input": {"command": "git checkout -b fix/html-preview-title"}, "result": "Switched to a new branch 'fix/html-preview-title'"}, {"tool": "Bash", "input": {"command": "git add -A && git commit -m \"fix(web): HTML preview frame gets an accessible title\""}, "result": "[fix/html-preview-title abc1234] fix(web): HTML preview frame gets an accessible title\n 1 file changed"}]}], "mocks": {"watch_pull_request": "default", "link_pull_request": "default"}, "world": {"branch": "fix/html-preview-title", "commits": [{"sha": "abc1234", "subject": "fix(web): HTML preview frame gets an accessible title"}], "diff": "diff --git a/apps/web/src/HtmlPreview.tsx b/apps/web/src/HtmlPreview.tsx\n--- a/apps/web/src/HtmlPreview.tsx\n+++ b/apps/web/src/HtmlPreview.tsx\n@@ -1,3 +1,3 @@\n export function HtmlPreview({ html }: { html: string }) {\n- return <iframe sandbox=\"allow-scripts\" srcDoc={html} height={400} />;\n+ return <iframe title=\"HTML preview\" sandbox=\"allow-scripts\" srcDoc={html} height={400} />;\n }\n", "files": {"apps/web/src/HtmlPreview.tsx": "export function HtmlPreview({ html }: { html: string }) {\n return <iframe title=\"HTML preview\" sandbox=\"allow-scripts\" srcDoc={html} height={400} />;\n}\n"}}, "shellMocks": [{"match": "gh pr create", "output": "https://github.com/acme/app/pull/124"}]}, "prompt": "Yes, open the PR and hand it over. I'll review and merge it myself.", "expect": {"callsMustNot": [{"tool": "watch_pull_request", "args": {"until": "merged"}}], "linked": ["~/pull/124"]}, "notes": "pingdotgg/t3code#36230 / #34770: a hand-off for the user's own review returns the thread to the inbox once checks finish."}
packages/contracts/src/orchestrationV2.ts
+3
@@ -66,6 +66,7 @@ import {
66
ThreadPullRequestSnapshot,
67
ThreadPullRequestStack,
68
ThreadPullRequestWatch,
69
+ PullRequestWatchUntil,
70
} from "./threadPullRequest.ts";
71
import {
72
ProviderApprovalDecision,
@@ -3320,6 +3321,8 @@ export const OrchestrationV2Command = Schema.Union([
3321
threadId: ThreadId,
3322
...ThreadPullRequestKey.fields,
3323
watching: Schema.Boolean,
3324
+ /** With `watching`, sets how long the watch holds its thread; absent keeps the current one. */
3325
+ until: Schema.optional(PullRequestWatchUntil),
3326
link: Schema.optional(
3327
Schema.Struct({
3328
url: TrimmedNonEmptyString,
packages/contracts/src/threadPullRequest.ts
+6
@@ -118,9 +118,15 @@ export const ThreadPullRequestWatch = Schema.Struct({
118
* watch keep its thread waiting; absent on watches not read since it existed.
119
*/
120
checksPending: Schema.optional(Schema.Boolean),
121
+ /** How long the watch holds its thread. Absent means until every check finished. */
122
+ until: Schema.optional(Schema.Literal("merged")),
123
});
124
export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
125
126
+/** `merged` also ends when the PR closes or the agent unwatches it. */
127
+export const PullRequestWatchUntil = Schema.Literals(["checks", "merged"]);
128
+export type PullRequestWatchUntil = typeof PullRequestWatchUntil.Type;
129
+
130
export const ThreadPullRequestLink = Schema.Struct({
131
...ThreadPullRequestKey.fields,
132
url: TrimmedNonEmptyString,
packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
+13
@@ -492,6 +492,19 @@ describe("derivePendingBackgroundWork kinds", () => {
492
],
493
});
494
expect(backgroundWorkHoldsCompletion(merged)).toBe(true);
495
+
496
+ const untilMerged = derivePendingBackgroundWork({
497
+ latestRun: { id: "run-1" as never, ordinal: 1, status: "completed" },
498
+ providerThreads: [],
499
+ turnItems: [],
500
+ pullRequests: [
501
+ {
502
+ ...link(1, { state: "open" }),
503
+ watch: { ...watch, passed: true, checksPending: false, until: "merged" as const },
504
+ },
505
+ ],
506
+ });
507
+ expect(backgroundWorkHoldsCompletion(untilMerged)).toBe(true);
508
});
509
510
it("lists no watch while a run is active", () => {
packages/shared/src/orchestrationV2PendingBackgroundWork.ts
+6
-3
@@ -323,9 +323,12 @@ function pullRequestWatchTasks(
323
taskId: `${PULL_REQUEST_WATCH_TASK_ID}${link.host.toLowerCase()}/${link.repository.toLowerCase()}#${link.number}`,
324
description: `Watching pull request #${link.number}`,
325
kind: "monitor" as const,
326
- // Once every check finished, a person moves the PR next: the watch stays on but holds nothing.
327
- // A merged PR's watch holds until its read wakes the agent, so settling on merge waits.
328
- ...(link.watch.checksPending === false && link.snapshot?.state !== "merged"
326
+ // Once every check finished, a person moves the PR next: the watch stays on but holds
327
+ // nothing, unless the agent said it acts on the PR itself. A merged PR's watch holds
328
+ // until its read wakes the agent, so settling on merge waits.
329
+ ...(link.watch.checksPending === false &&
330
+ link.watch.until !== "merged" &&
331
+ link.snapshot?.state !== "merged"
332
? {}
333
: { awaited: true as const }),
334
},