diff --git a/apps/server/src/mcp/toolkits/pullRequests/handlers.ts b/apps/server/src/mcp/toolkits/pullRequests/handlers.ts
index 884dd09a3dea4..46afff241f408 100644
--- a/apps/server/src/mcp/toolkits/pullRequests/handlers.ts
+++ b/apps/server/src/mcp/toolkits/pullRequests/handlers.ts
@@ -2,6 +2,7 @@ import {
CommandId,
type OrchestrationProjectShell,
type PullRequestState,
+ type PullRequestWatchUntil,
type OrchestrationV2ThreadShell,
type ThreadId,
type ThreadPullRequestLink,
@@ -199,18 +200,20 @@ const make = Effect.gen(function* () {
// The domain service owns the registration span.
const setWatching = Effect.fnUntraced(function* (
- input: PullRequestTargetInput,
+ input: PullRequestTargetInput & { readonly until?: PullRequestWatchUntil | undefined },
watching: boolean,
) {
const scope = yield* McpInvocationContext.requireMcpCapability("pull-requests");
const threadId = input.threadId ?? scope.thread?.threadId;
if (threadId === undefined) return yield* new PullRequestThreadRequiredError();
- return yield* watches.setWatching({ threadId, target: input, watching }).pipe(
- Effect.catchTags({
- PullRequestWatchThreadNotFoundError: (error) =>
- threadNotFound(engine, scope, error.threadId, error.message),
- }),
- );
+ return yield* watches
+ .setWatching({ threadId, target: input, watching, until: input.until })
+ .pipe(
+ Effect.catchTags({
+ PullRequestWatchThreadNotFoundError: (error) =>
+ threadNotFound(engine, scope, error.threadId, error.message),
+ }),
+ );
});
const locateAll = Effect.fn("PullRequestsToolkit.locateAll")(function* (
diff --git a/apps/server/src/mcp/toolkits/pullRequests/tools.ts b/apps/server/src/mcp/toolkits/pullRequests/tools.ts
index 376817db10079..685cfd02782b5 100644
--- a/apps/server/src/mcp/toolkits/pullRequests/tools.ts
+++ b/apps/server/src/mcp/toolkits/pullRequests/tools.ts
@@ -7,6 +7,7 @@ import {
PullRequestReviewGuideRun,
PullRequestState,
PullRequestUnavailableError,
+ PullRequestWatchUntil,
ThreadPullRequestLinkSource,
TrimmedNonEmptyString,
ThreadId,
@@ -324,10 +325,20 @@ const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
.annotate(Tool.Idempotent, true)
.annotate(Tool.OpenWorld, false);
+const WatchPullRequestInput = Schema.Struct({
+ ...PullRequestTargetInput.fields,
+ until: Schema.optional(
+ PullRequestWatchUntil.annotate({
+ description:
+ '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.',
+ }),
+ ),
+});
+
const WatchPullRequestTool = Tool.make("watch_pull_request", {
description:
"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.",
- parameters: PullRequestTargetInput,
+ parameters: WatchPullRequestInput,
success: WatchPullRequestResult,
failure: PullRequestToolError,
dependencies: watchDependencies,
diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts
index 3dc32ee9863b2..8a34a55e07534 100644
--- a/apps/server/src/orchestration-v2/Orchestrator.ts
+++ b/apps/server/src/orchestration-v2/Orchestrator.ts
@@ -40,6 +40,7 @@ import {
type OrchestrationV2ServerCommand,
type ThreadPullRequestLink,
type ThreadPullRequestWatch,
+ type PullRequestWatchUntil,
type OrchestrationV2AppThread,
type OrchestrationV2ContextHandoff,
type OrchestrationV2ContextSourcePoint,
@@ -892,11 +893,23 @@ function syncedPullRequestWatch(
},
): ThreadPullRequestWatch | undefined {
if (command.watch === null) return undefined;
+ // Only the agent sets `until`, so a read in flight keeps what the watch has now.
+ const watch = withUntil(command.watch, existing?.until ?? "checks");
// A push cleared the answer while this read was in flight, so its answer is the old head's.
if (command.checksPendingBefore === undefined || existing?.checksPending !== undefined) {
- return command.watch;
+ return watch;
}
- return withoutChecksAnswer(command.watch);
+ return withoutChecksAnswer(watch);
+}
+
+function withUntil(
+ watch: ThreadPullRequestWatch,
+ until: PullRequestWatchUntil | undefined,
+): ThreadPullRequestWatch {
+ if (until === undefined || until === (watch.until ?? "checks")) return watch;
+ if (until === "merged") return { ...watch, until };
+ const { until: _checks, ...rest } = watch;
+ return rest;
}
const withoutChecksAnswer = ({
@@ -5077,43 +5090,46 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
: existing.watch
: !command.watching
? undefined
- : (existing.watch ?? {
- startedAt,
- headSha: null,
- failedChecks: [],
- passed: false,
- passedChecks: [],
- conflicting: false,
- // Watching again must not repeat check or conflict news the last watch told.
- ...(existing.endedWatch && {
- headSha: existing.endedWatch.headSha,
- failedChecks: existing.endedWatch.failedChecks,
- passed: existing.endedWatch.passed,
- passedChecks: existing.endedWatch.passedChecks,
- conflicting: existing.endedWatch.conflicting,
- rebaseRequired: existing.endedWatch.rebaseRequired,
- }),
- awaitingBaseline: existing.endedWatch
- ? existing.endedWatch.awaitingBaseline
- : "all",
- ...(existing.endedWatch?.owedChecks !== undefined && {
- owedChecks: existing.endedWatch.owedChecks,
- }),
- ...(existing.endedWatch?.awaitingApproval !== undefined && {
- awaitingApproval: existing.endedWatch.awaitingApproval,
- }),
- ...(existing.endedWatch?.approvalAnnounced !== undefined && {
- approvalAnnounced: existing.endedWatch.approvalAnnounced,
- }),
- // A finished-checks answer may be an older head's; a fresh read decides.
- ...(existing.endedWatch?.checksPending === true && { checksPending: true }),
- ...(existing.endedWatch?.checksAwaitedSince !== undefined && {
- checksAwaitedSince: existing.endedWatch.checksAwaitedSince,
- }),
- remarksThrough: startedAt,
- remarkIds: [],
- wakes: 0,
- });
+ : withUntil(
+ existing.watch ?? {
+ startedAt,
+ headSha: null,
+ failedChecks: [],
+ passed: false,
+ passedChecks: [],
+ conflicting: false,
+ // Watching again must not repeat check or conflict news the last watch told.
+ ...(existing.endedWatch && {
+ headSha: existing.endedWatch.headSha,
+ failedChecks: existing.endedWatch.failedChecks,
+ passed: existing.endedWatch.passed,
+ passedChecks: existing.endedWatch.passedChecks,
+ conflicting: existing.endedWatch.conflicting,
+ rebaseRequired: existing.endedWatch.rebaseRequired,
+ }),
+ awaitingBaseline: existing.endedWatch
+ ? existing.endedWatch.awaitingBaseline
+ : "all",
+ ...(existing.endedWatch?.owedChecks !== undefined && {
+ owedChecks: existing.endedWatch.owedChecks,
+ }),
+ ...(existing.endedWatch?.awaitingApproval !== undefined && {
+ awaitingApproval: existing.endedWatch.awaitingApproval,
+ }),
+ ...(existing.endedWatch?.approvalAnnounced !== undefined && {
+ approvalAnnounced: existing.endedWatch.approvalAnnounced,
+ }),
+ // A finished-checks answer may be an older head's; a fresh read decides.
+ ...(existing.endedWatch?.checksPending === true && { checksPending: true }),
+ ...(existing.endedWatch?.checksAwaitedSince !== undefined && {
+ checksAwaitedSince: existing.endedWatch.checksAwaitedSince,
+ }),
+ remarksThrough: startedAt,
+ remarkIds: [],
+ wakes: 0,
+ },
+ command.until,
+ );
if (watch === existing.watch && links === linked) return thread;
const final =
command.type === "thread.pull-request-watch.sync" && watch === undefined
diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
index 8fdab0f30fee2..7590ee3c11b3e 100644
--- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
@@ -229,7 +229,8 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
left.wakes === right.wakes &&
left.awaitingBaseline === right.awaitingBaseline &&
left.checksAwaitedSince === right.checksAwaitedSince &&
- left.checksPending === right.checksPending
+ left.checksPending === right.checksPending &&
+ left.until === right.until
);
}
diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.ts b/apps/server/src/orchestration-v2/pullRequestWatch.ts
index ad7ad80f72638..eedbe47d1a01f 100644
--- a/apps/server/src/orchestration-v2/pullRequestWatch.ts
+++ b/apps/server/src/orchestration-v2/pullRequestWatch.ts
@@ -256,6 +256,7 @@ export function evaluatePullRequestWatch(
}),
checksAwaitedSince,
checksPending,
+ ...(watch.until !== undefined && { until: watch.until }),
},
exhausted: commentsOnly && wakes >= PULL_REQUEST_WATCH_WAKE_LIMIT,
};
diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts
index 29aac0d000cf4..0fedb489f451a 100644
--- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts
+++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts
@@ -31,6 +31,7 @@ import {
type PullRequestDetail,
type PullRequestComment,
PullRequestOperationError,
+ type PullRequestWatchUntil,
ProviderDriverKind,
ProviderInstanceId,
ProviderSessionId,
@@ -4280,6 +4281,73 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
}),
);
+ it.effect("keeps how long a watch holds across reads until the agent changes it", () =>
+ Effect.gen(function* () {
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
+ const maintenance = yield* ProjectionReplay.ProjectionReplay;
+ const threadId = ThreadId.make("runtime-pull-request-watch-until-merged");
+ yield* orchestrator.dispatch({
+ type: "thread.create",
+ createdBy: "user",
+ creationSource: "web",
+ commandId: CommandId.make("pr-watch-until-create"),
+ threadId,
+ projectId: ProjectId.make("pr-watch-project"),
+ title: "Watch until merged",
+ modelSelection,
+ runtimeMode: "full-access",
+ interactionMode: "default",
+ branch: null,
+ worktreePath: null,
+ });
+ const key = { host: "github.com", repository: "pingdotgg/t3code", number: 7 };
+ const watchOf = Effect.map(
+ orchestrator.getThreadShell(threadId),
+ (thread) => thread?.pullRequests?.[0]?.watch,
+ );
+ const watch = (id: string, until?: PullRequestWatchUntil) =>
+ orchestrator.dispatch({
+ type: "thread.pull-request.watch",
+ commandId: CommandId.make(id),
+ threadId,
+ ...key,
+ watching: true,
+ link: { url: "https://github.com/pingdotgg/t3code/pull/7", source: "agent" },
+ ...(until !== undefined && { until }),
+ });
+
+ yield* watch("pr-watch-until-start");
+ assert.isUndefined((yield* watchOf)?.until);
+
+ yield* watch("pr-watch-until-on", "merged");
+ const started = yield* watchOf;
+ assert.equal(started?.until, "merged");
+ if (started === undefined) return;
+
+ // A read that began before the agent set it must not drop it.
+ const { until: _read, ...readBefore } = started;
+ yield* orchestrator.dispatch({
+ type: "thread.pull-request-watch.sync",
+ commandId: CommandId.make("pr-watch-until-record"),
+ threadId,
+ ...key,
+ startedAt: started.startedAt,
+ watch: { ...readBefore, headSha: "abc123", checksPending: false },
+ });
+ assert.equal((yield* watchOf)?.until, "merged");
+ assert.equal((yield* watchOf)?.headSha, "abc123");
+
+ yield* watch("pr-watch-until-again");
+ assert.equal((yield* watchOf)?.until, "merged");
+ assert.isTrue((yield* maintenance.rebuild).valid);
+ assert.equal((yield* watchOf)?.until, "merged");
+
+ yield* watch("pr-watch-until-off", "checks");
+ assert.isUndefined((yield* watchOf)?.until);
+ assert.equal((yield* watchOf)?.headSha, "abc123");
+ }),
+ );
+
it.effect.each(["manual", "automatic"])("settling ends every pull request watch: %s", (mode) =>
Effect.gen(function* () {
const orchestrator = yield* Orchestrator.OrchestratorV2;
diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json
index 6658b3beaea3b..f1a1aa442807f 100644
--- a/apps/server/src/provider/agentContextBudget.json
+++ b/apps/server/src/provider/agentContextBudget.json
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 6037,
"codexAdditionalContextBytes": 7431,
- "mcpToolListJsonBytes": 52145
+ "mcpToolListJsonBytes": 52519
}
diff --git a/apps/server/src/pullRequest/PullRequestWatchService.ts b/apps/server/src/pullRequest/PullRequestWatchService.ts
index 6ed736075c018..c50de1a847f98 100644
--- a/apps/server/src/pullRequest/PullRequestWatchService.ts
+++ b/apps/server/src/pullRequest/PullRequestWatchService.ts
@@ -3,6 +3,7 @@ import {
ThreadId,
type OrchestrationV2ThreadShell,
type PullRequestUnavailableError,
+ type PullRequestWatchUntil,
} from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
@@ -69,6 +70,7 @@ export class PullRequestWatchService extends Context.Service<
readonly threadId: ThreadId;
readonly target: PullRequestTarget;
readonly watching: boolean;
+ readonly until?: PullRequestWatchUntil | undefined;
}) => Effect.Effect<
ResolvedTarget & { readonly watching: boolean; readonly wasWatching: boolean },
| PullRequestWatchFailedError
@@ -104,6 +106,7 @@ const make = Effect.gen(function* () {
readonly threadId: ThreadId;
readonly target: PullRequestTarget;
readonly watching: boolean;
+ readonly until?: PullRequestWatchUntil | undefined;
}) {
const { watching } = input;
const thread = yield* requireThread(input.threadId);
@@ -158,6 +161,7 @@ const make = Effect.gen(function* () {
number: target.number,
watching,
...(watching ? { link: { url: target.url, source: "agent" as const } } : {}),
+ ...(watching && input.until !== undefined && { until: input.until }),
})
.pipe(
Effect.catchCause((cause) =>
diff --git a/docs/user/source-control.md b/docs/user/source-control.md
index d419a6a55ca0b..73a2b95154d47 100644
--- a/docs/user/source-control.md
+++ b/docs/user/source-control.md
@@ -351,8 +351,10 @@ A watched thread counts as working while the pull request still has checks runni
the **Working** section, including after the agent pushes a fix. Once every check has finished,
including review bots that report as checks, the thread returns to your inbox: what happens next is
up to a person. That includes a workflow waiting for a maintainer to approve it, which runs only
-once someone does. The watch stays on and still wakes the agent on new comments, failed checks or
-conflicts, and a watched thread never auto-settles.
+once someone does. If you ask the agent to act on the pull request itself, such as merging it once
+a teammate approves, the thread stays in **Working** until the pull request merges or closes. The
+watch stays on and still wakes the agent on new comments, failed checks or conflicts, and a watched
+thread never auto-settles.
Cross-repository links use a project on the same host. Azure DevOps reviews require a project checked
out from the matching organization and repository.
diff --git a/evals/mcp-tool-use/cases/pull-requests.ndjson b/evals/mcp-tool-use/cases/pull-requests.ndjson
index 2e14e45f7f250..b07a121db42ad 100644
--- a/evals/mcp-tool-use/cases/pull-requests.ndjson
+++ b/evals/mcp-tool-use/cases/pull-requests.ndjson
@@ -37,3 +37,5 @@
{"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"}}
{"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."}
{"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."}
+{"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 ;\n+ return ;\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 ;\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."}
+{"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 ;\n+ return ;\n }\n", "files": {"apps/web/src/HtmlPreview.tsx": "export function HtmlPreview({ html }: { html: string }) {\n return ;\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."}
diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts
index 48ccf7c3f1641..c5286116655dd 100644
--- a/packages/contracts/src/orchestrationV2.ts
+++ b/packages/contracts/src/orchestrationV2.ts
@@ -66,6 +66,7 @@ import {
ThreadPullRequestSnapshot,
ThreadPullRequestStack,
ThreadPullRequestWatch,
+ PullRequestWatchUntil,
} from "./threadPullRequest.ts";
import {
ProviderApprovalDecision,
@@ -3320,6 +3321,8 @@ export const OrchestrationV2Command = Schema.Union([
threadId: ThreadId,
...ThreadPullRequestKey.fields,
watching: Schema.Boolean,
+ /** With `watching`, sets how long the watch holds its thread; absent keeps the current one. */
+ until: Schema.optional(PullRequestWatchUntil),
link: Schema.optional(
Schema.Struct({
url: TrimmedNonEmptyString,
diff --git a/packages/contracts/src/threadPullRequest.ts b/packages/contracts/src/threadPullRequest.ts
index 0c8d7a61fe92d..252194f48b1f5 100644
--- a/packages/contracts/src/threadPullRequest.ts
+++ b/packages/contracts/src/threadPullRequest.ts
@@ -118,9 +118,15 @@ export const ThreadPullRequestWatch = Schema.Struct({
* watch keep its thread waiting; absent on watches not read since it existed.
*/
checksPending: Schema.optional(Schema.Boolean),
+ /** How long the watch holds its thread. Absent means until every check finished. */
+ until: Schema.optional(Schema.Literal("merged")),
});
export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
+/** `merged` also ends when the PR closes or the agent unwatches it. */
+export const PullRequestWatchUntil = Schema.Literals(["checks", "merged"]);
+export type PullRequestWatchUntil = typeof PullRequestWatchUntil.Type;
+
export const ThreadPullRequestLink = Schema.Struct({
...ThreadPullRequestKey.fields,
url: TrimmedNonEmptyString,
diff --git a/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts b/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
index b7ff7369494c2..6948e9e3eda1a 100644
--- a/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
+++ b/packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
@@ -492,6 +492,19 @@ describe("derivePendingBackgroundWork kinds", () => {
],
});
expect(backgroundWorkHoldsCompletion(merged)).toBe(true);
+
+ const untilMerged = derivePendingBackgroundWork({
+ latestRun: { id: "run-1" as never, ordinal: 1, status: "completed" },
+ providerThreads: [],
+ turnItems: [],
+ pullRequests: [
+ {
+ ...link(1, { state: "open" }),
+ watch: { ...watch, passed: true, checksPending: false, until: "merged" as const },
+ },
+ ],
+ });
+ expect(backgroundWorkHoldsCompletion(untilMerged)).toBe(true);
});
it("lists no watch while a run is active", () => {
diff --git a/packages/shared/src/orchestrationV2PendingBackgroundWork.ts b/packages/shared/src/orchestrationV2PendingBackgroundWork.ts
index a0dd8045dcfe4..9753f06060655 100644
--- a/packages/shared/src/orchestrationV2PendingBackgroundWork.ts
+++ b/packages/shared/src/orchestrationV2PendingBackgroundWork.ts
@@ -323,9 +323,12 @@ function pullRequestWatchTasks(
taskId: `${PULL_REQUEST_WATCH_TASK_ID}${link.host.toLowerCase()}/${link.repository.toLowerCase()}#${link.number}`,
description: `Watching pull request #${link.number}`,
kind: "monitor" as const,
- // Once every check finished, a person moves the PR next: the watch stays on but holds nothing.
- // A merged PR's watch holds until its read wakes the agent, so settling on merge waits.
- ...(link.watch.checksPending === false && link.snapshot?.state !== "merged"
+ // Once every check finished, a person moves the PR next: the watch stays on but holds
+ // nothing, unless the agent said it acts on the PR itself. A merged PR's watch holds
+ // until its read wakes the agent, so settling on merge waits.
+ ...(link.watch.checksPending === false &&
+ link.watch.until !== "merged" &&
+ link.snapshot?.state !== "merged"
? {}
: { awaited: true as const }),
},