Skip to content

feat(server): watch pull requests and settle threads on merge in own mode - #312

Merged
opficdev merged 6 commits into
mainfrom
feat/pull-request-watch
Dec 5, 2026
Merged

opficdev merged 6 commits into
mainfrom
feat/pull-request-watch

Conversation

@opficdev

@opficdev opficdev commented Dec 5, 2026

Copy link
Copy Markdown
Member

In own mode, agents can now watch a pull request, and a linked pull request's merge settles its thread.

What changed

  • Pull request sync (PullRequestSyncReactor): every minute, and at once for a new link or an agent's shell command that merged, closed, opened or pushed to a pull request, Rust reads each linked pull request's summary on upstream's cadences and commits a changed snapshot (thread.pull-request-link.sync). It links native stack layers and pull requests an agent opened with gh pr create, and a push clears a watch's pending-checks answer.
  • Watches (PullRequestWatchReactor, pullRequestWatch.ts): a watch is read at once when it starts, at startup, every two minutes and when the agent's own merge or close ends. Rust evaluates failed, passed and finished checks, checks awaiting approval, new comments and reviews, no checks after 15 minutes, conflicts, a needed rebase and merge queue removals, and queues one wake per thread as the agent's message from the server. The comment wake limit, the eight-failure give-up, until: "checks" | "merged" and the end on merge, close, settle or subagent are upstream's. A queued wake whose watch ended is cancelled, and one whose pull requests changed is rewritten.
  • Deciders: thread.pull-request.watch, -watch.sync, -watch.checks-reopen and -link.sync, ported from Orchestrator.ts.
  • Tools: watch_pull_request and unwatch_pull_request are served on /mcp with upstream's handlers and listed in own mode's tools.
  • Settlement runs at once when a linked pull request changes or a run ends, as upstream does, so a merge settles its thread without waiting out the minute.

Reads stay in the bridge

docs/bridge-to-rust.md puts source control in tern-server-vcs (18g/18h). The sync and watch rules, evaluation, wake text and deciders are there and in tern-server-threads, but the GitHub reads (summary, detail, activity, threadComments, stack, watchFingerprint) go through upstream's PullRequestService in the bridge with one new ask (pullRequests.read). Porting the GitHub provider's GraphQL reads with their decoders and batching (about 4,000 lines) is much larger than this step, so it stays 18g's work, which will replace the ask.

Left out: the host change feeds (only a GitHub app sign-in on github.com streams them), so a watch hears of a change at its next sweep; upstream's own write notifications, which the sweeps stand in for; and the read cache's invalidation, which the bridge keeps off. Wake text says tern where upstream's says T3 Code, as the packed bridge does.

Checks

  • cargo fmt --all, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo test --workspace --locked (scratch HOME, TERN_KEYCHAIN=off), scripts/check-bridge.sh.
  • New harness own_pull_request_watch against upstream 9677111 with a fake GitHub whose pull request it changes between steps. Each step stops upstream, copies its database to a new own-mode server and starts both, so both read the change from the same state as they start, and the harness waits on conditions (the wake or the recorded watch, the turn ended, the thread settled). The tool answer, the baseline, and the wakes, link and settlement after each step matched: checks failing woke the thread, checks passing was recorded without a wake, a comment woke it with the comment, and the merge woke it with the merge commit, ended the watch and settled the thread. 37 s locally.
  • Locally passing: own_agent_tools, own_mcp_sessions (tool lists updated to 17), own_agent_threads, own_commands, own_scheduled_tasks, own_steering, own_workspace. own_source_control and own_git_actions fail on this Mac with main's bridge too, so CI decides them.

🤖 Generated with Claude Code

opficdev and others added 6 commits December 6, 2026 05:33
Port the rules of upstream's pull request sync and watches to tern-server-vcs:
snapshot fields and cadences, watch evaluation and wake text, comment
snippets and the shell commands that open, push to or close a pull request.
The bridge answers upstream's PullRequestService reads (pullRequests.read).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port thread.pull-request.watch, -watch.sync, -watch.checks-reopen and
-link.sync from Orchestrator.ts. A watch sync queues its wake as the agent's
message from the server, and the queue cancels a wake whose watch ended or
moved and rewrites one whose pull requests changed, as startNextQueuedRun does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port PullRequestSyncReactor and PullRequestWatchReactor: the sweeps, the
reads on a new link or watch and after an agent's merge, close, create or
push command, held wakes per thread, and the read failure limit. Settlement
runs at once when a pull request or a run changes, so a merge settles its
thread without waiting out the sweep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Register upstream's watch tools with PullRequestWatchService on Rust's
thread shell and dispatch, and list them in own mode's tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fake GitHub whose pull request the harness changes between steps: watch,
checks failing, checks passing, a comment and the merge, each read by a
restarted upstream and own mode from the same database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@opficdev
opficdev enabled auto-merge (squash) December 5, 2026 20:38
@opficdev
opficdev merged commit e9752b6 into main Dec 5, 2026
20 checks passed
@opficdev
opficdev deleted the feat/pull-request-watch branch December 5, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant