Skip to content

feat(gateway): let agents watch ci checks of linked pull requests - #803

Merged
nixuuu merged 1 commit into
devfrom
feat/pr-check-watches
Nov 15, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/pr-check-watches

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Stage 1 of 2 (stack #805, bottom). Agents get watch_pr_checks, list_pr_watches and cancel_pr_watch on the agent bus, so after opening a PR they hear about CI instead of polling or sleeping.

What it does

  • watch_pr_checks({ pull_request, notify_on?, timeout_minutes? }) names a pull request linked to the calling thread: a URL, owner/repo#n or #n. It waits up to 10 s for a PR just opened with gh pr create to be linked.
    • notify_on is any of failure, complete, each. Default: [failure, complete].
    • It returns at once with the current counts and any checks that already failed.
    • If every check already passed, no watch is created.
  • The gateway polls with the owner's GitHub account, through the shared visible-PR producer (github/watch.ts, pollAgentWatches). That means the same deadlines, ETags, budgets and single flight. It reads check pages only when the producer's signal changes. While checks are pending it also re-reads at most once every 2 min, because the producer sets a new commit's baseline one tick late.
  • Follows new commits. Each followed commit adds a hop, so a fix–push–fail loop with no human input stops waking the thread at the hop limit (8).
  • Notes. Notes are delivered like background task notes: a steer of the running turn, otherwise a turn of its own (new trigger pr_checks). A steer that does not join gets its notes back for delivery. The turn and steer input carries the notes (sourceKind, prChecks), so the timeline reads Turn.pr_checks and Steer.pr_checks without joins.
  • How a watch ends:
    • With a note: passed, merged, closed, timeout, no_checks (10 min), access, unlinked.
    • Without a note: cancelled, replaced, or the thread closed.
    • A failed run keeps the watch open until its time limit, waiting for a fix.
  • Data. Migration 0148_pr_check_watches (tables pr_check_watches and pr_check_notes, the pr_checks trigger, bus tool names). Proto changes are additive (PullRequestChecksNote, field 480 on Turn and Steer).
  • Policy. Agents get no access to the GitHub connection. Canopy shares the check state it already reads for the PR panel, only for PRs linked to the caller's thread. The token stays in the gateway, and the agent performs no GitHub operation through the integration. Notes carry check names, states, providers, URLs and run ids, never logs. Bots don't get the tool. Docs: agent-bus.md ("Checki CI"), github.md §1/§5/§10, execution.md.

Verification

Ran locally:

  • bun run check:tmp on the new tests/integration/pr-check-watches.test.ts. It covers a failed run, a followed commit with one more hop, the passing run ending the watch, a refused unlinked PR, cancel, replace, and merged.
  • The affected github-panel-polling, background-task-notes, agent-bus and db/schema tests.
  • The domain tools/policy tests.
  • Gateway and domain typecheck, plus lint and format on the changed files.

Everything else is left to CI.

🤖 Generated with Claude Code

watch_pr_checks, list_pr_watches and cancel_pr_watch on the agent bus.
The gateway polls a linked pull request's checks with the owner's GitHub
account through the shared visible PR producer, follows new commits and
tells the agent about failures and finished runs as a platform note: a
steer of the running turn, else a turn of its own (trigger pr_checks).
Each followed commit adds a hop, so a fix loop without a human stops
waking the thread at the hop limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu added this pull request to stack #805 November 15, 2026 08:37
@nixuuu nixuuu changed the title feat/pr check watches feat(gateway): let agents watch ci checks of linked pull requests Nov 15, 2026
@nixuuu
nixuuu marked this pull request as ready for review November 15, 2026 08:49
@nixuuu
nixuuu merged commit 52e6f0d into dev Nov 15, 2026
13 checks passed
@nixuuu
nixuuu deleted the feat/pr-check-watches branch November 15, 2026 09:02
nixuuu added a commit that referenced this pull request Nov 15, 2026
Stage 2 of 2 (stack #805, top, on #803). Timeline UI for the CI check
notes and watch tool calls, on web and mobile.

## What it does
- A `pr_checks` turn, or a CI note steered into a running turn, renders
as one compact system line per note. The line says what happened, links
to the pull request, and names the commit when a new one was followed.
Failed and passed lines get a rose or emerald icon; the text never
relies on colour alone.
- The pending-steer list leaves out these platform notes.
- `watch_pr_checks`, `list_pr_watches` and `cancel_pr_watch` get bus
card titles and icons. A watch card shows the pull request, when the
agent hears back, and until when. When every check had already passed,
the title is "Checked CI checks".
- Shared wording lives in `@canopy/domain/pr-check-display`. The dev
gallery (`/dev/tool-calls`) gains watch call fixtures.

## Copy audit (docs/copy.md §8)
| Before | After | Reason |
|---|---|---|
| (new) | `Watching CI checks` / `Starting to watch CI checks` / `Tried
to watch CI checks` | Matches the bus card pattern (doing, done, tried)
|
| (new) | `Checked CI checks` | Every check had already passed; no watch
started, so the title doesn't claim one |
| (new) | `Listed CI check watches`, `Stopped a CI check watch` | Verb
first, sentence case |
| (new) | `#792 · Tells this agent when a check fails or
all checks finish · Until 11:12 AM` | Facts line; time formatted with
`toLocaleTimeString` |
| (new) | `All checks already passed` | One idea, no period (fact
fragment) |
| (new) | `test (3/4) failed`, `2 of 14 checks failed`, `All 14 checks
passed`, `lint finished` | Short statuses with correct plurals |
| (new) | `Pull request merged`, `Pull request closed`, `No checks
reported in 10 min`, `Stopped watching checks at the time limit`,
`Stopped watching checks without access`, `Stopped watching checks of an
unlinked pull request` | What happened, in plain words; "turn" glossary
respected (no "run") |
| (new) | `New commit 1a2b3c4` | Names the followed commit |

Checked with short, typical and long repository names. A long name wraps
cleanly at phone width.

## Verification
- **Looked at in Chromium:** light and dark themes, at 1280 px and 390
px wide.
  - Tool cards came from the `/dev/tool-calls` gallery.
- Note rows came from `TurnInput` with fixture turns, added to the
gallery only for the screenshots and not committed.
  - The app shell was bypassed locally because no gateway was running.
- **Ran locally:** web `svelte-check`, mobile and domain typecheck, and
lint and format on the changed files.

Everything else is left to CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
nixuuu added a commit that referenced this pull request Nov 15, 2026
## Change

Proxy accounts with undetectable plans can now use a manual plan in
Settings → Proxies → Accounts on web and mobile. For example, Claude
Ultra counts as ×10 and Team as ×5. Automatic keeps detection as the
default; a manual choice takes precedence over later detection until
reset, with a subtle “Set manually” hint.

- Migration 0149 stores the choices on the owner-scoped proxy row, keyed
by a hash of provider + upstream stable ID (fallback: auth_index).
Missing accounts are ignored. Refresh and gateway restarts retain the
choices; deleting the proxy deletes them.
- The effective plan reaches ListProxies, overview updates and the
shared weighted capacity calculation used by the sidebar indicator,
usage popover and mobile sheet. Detection remains separately available.
- Additive RPC and account fields; regenerated contracts. Team already
existed in the enum, so its numeric value is preserved. Its Claude ×5
weight is explicitly documented as a user-provided equivalence dated
2026-11-15, not independently confirmed by Anthropic.
- Claude and Codex offer the requested known plans. Grok currently has
no known weights in the table, so its picker offers Automatic only. No
fork-specific multiplier or plan field was added.

## Verification

Local checks passed:

- `bun run gen`.
- `bun run check:tmp` for
`tests/integration/proxy-account-plans.test.ts`,
`tests/integration/proxy-accounts.test.ts`, gateway
`management-plan.test.ts` and `management.test.ts`, domain
`proxy-capacity.test.ts`, and DB `schema.test.ts`: 48 tests passed
across the focused runs, with no temporary files left. The new
integration test covers set/clear, later detection precedence, weighted
capacity, foreign-owner read/write refusal, refresh with changed
email/runtime index, and removed accounts.
- Typechecks for gateway, contracts, db, domain, mobile and web; Svelte
reports 0 errors and 0 warnings. Lint and formatting on edited files;
diff/content/link review.
- Real browser review using an isolated remote gateway/web and
PostgreSQL plus fake management accounts: light/dark at desktop (1280
px), phone (390 px) and narrow phone (320 px). Short, typical and long
emails remain blurred; dropdown/sheet selection, reset, Refresh, and a
failed save with rollback/retry were checked. Review processes and
container are cleaned up. Screenshots stay outside the repository.

Rebased onto current dev after #803, #804, #806 and #807. Renumbered the
migration to 0149 and regenerated the combined proto. Focused tests and
affected typechecks were repeated. The web row keeps the provider mark,
blurred identity and status on its first line. A muted, borderless kit
trigger occupies one 20 px plan line below, followed inline by “· Set
manually”. There is no empty hint line. Switching to Automatic leaves
row height unchanged on desktop and at 320 px. Browser shots were
refreshed at desktop, 390 px and 320 px in light/dark with short and
long identities. The final visual-only change passed web typecheck and
edited-file lint/format; the 48 focused backend tests remain valid for
unchanged backend inputs.

Full frozen install, gen:check, repository-wide typecheck/lint/format,
complete check:tmp suite and selected builds remain with CI. No UI test
suite was added. Native mobile was typechecked but not run on an
iOS/Android device.

## Copy audit — docs/copy.md §8

| Before | After | Reason |
| --- | --- | --- |
| Unknown plan with no way to set it | Automatic · Unknown plan;
provider plan options with × multipliers | Offers a concrete choice
without guessing detection. |
| Repeated plan label beside the picker | One selected plan in the
picker | One fact once; account identity keeps its space. |
| — | Set manually | Short, subtle status; meaning does not rely on
colour. |
| — | Saving plan… | Present ongoing action with the standard ellipsis.
|
| — | Could not save the plan. Choose it again to retry. | What
happened, followed by an action; no transport details. |

Checklist 1–10 passed: short active sentences, sentence case and
punctuation; existing plan/account glossary; menu entries are selection
values, not commands; errors end with an action; no new empty states,
duplicate facts, jargon, or “soul” copy. Automatic preserves honest
unknown detection. Short/typical/long identities checked at desktop and
phone widths with blur intact. Accessible “Account plan”, status text
and numbers carry meaning without colour or position. No failing items.

Related: #763
nixuuu added a commit that referenced this pull request Nov 15, 2026
## Change

After `watch_pr_checks` reports that CI passed, the gateway keeps the
existing shared pull request producer alive for a short merge follow-up.
It probes PR metadata immediately and about every 10 seconds for up to
two minutes, using conditional REST requests. If GitHub completes
auto-merge, the updated merged state is published through the thread
revision so the sidebar and thread summary catch up promptly.

The follow-up stops as soon as the PR is merged or closed, and it
fetches the full GraphQL summary only after metadata changes. The
regular five-minute linked-summary refresh remains unchanged for other
cases.

## Verification

- `bun run --filter @canopy/gateway typecheck`
- `bun run lint -- apps/gateway/src/github/watch.ts
apps/gateway/src/github/watch-probes.ts
apps/gateway/src/core/pr-check-watches.ts
tests/integration/github-panel-polling.test.ts`
- `bun run check:tmp ./tests/integration/github-panel-polling.test.ts`
(9 passed)
- `bun run check:tmp ./tests/integration/pr-check-watches.test.ts` (2
passed)
- `bun run format -- apps/gateway/src/github/watch.ts
apps/gateway/src/github/watch-probes.ts
apps/gateway/src/core/pr-check-watches.ts
tests/integration/github-panel-polling.test.ts`

Fixes an earlier change: #803
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