Repository navigation
feat(server): accept pull-request state from an external syncer - #217
Merged
Merged
Conversation
GET /api/orchestration/events?after=<seq>&limit=<1..1000>&wait=<0..25> returns events after a cursor in sequence order, shaped like the WebSocket replay. An empty read is held until the engine publishes a newer event or the wait elapses (woken by the live event stream, no polling). A cursor ahead of the log gets 410 cursor-invalid. This lets the Linear bridge stop polling the full shell every 2 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /api/orchestration/pull-request-state lets the Linear bridge push PR state built from GitHub webhooks. bkt3 makes no outside calls: it refreshes the snapshot of threads linked to the PR and sets the branch PR of unarchived threads on its head branch in the same repository, with the same commands the upstream PR reactors dispatch. Older or identical writes are ignored; command ids derive from the delivery id. The endpoint needs the new external-sync:write scope, granted with `t3 auth session issue --with-scope external-sync:write`. T3_EXTERNAL_PR_SYNC=1 stops ThreadPullRequestReactor and PullRequestSyncReactor from starting. It is not set anywhere yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ThreadPullRequestReactorandPullRequestSyncReactor(pure upstream code) sweep every unsettled branch thread each minute withgitandgh./api/healthgoes from 2 ms to 400–820 ms for 40–60 s out of every ~110 s.The approved plan moves PR state to the Linear bridge, which already receives GitHub webhooks. bkt3 needs a way to accept that state, and a way to stop its own sweep.
Fix
This implements sections 2 and 3 of the bridge API contract.
POST /api/orchestration/pull-request-stateNew fork module
orchestration/pullRequestStateHttp.expbkt3.ts. Body:{ deliveryId, host, repository, number, url, snapshot: ThreadPullRequestSnapshot }. bkt3 makes no outside calls.Which threads a write applies to:
projection_thread_pull_requests. Their snapshot is replaced throughthread.pull-request-link.sync, and the stored stack is kept.snapshot.headBranchwhose project's repository identity (the cachedRepositoryIdentityResolver, viagetProjectShellById) is this PR's repository. Their branch PR is set throughthread.pull-request.sync, with the sameexpectedguard upstream's branch discovery uses.When a write is ignored:
stale:snapshot.updatedAtis older than the stored one, or a closed/merged PR would replace a different branch PR.unchanged: every field exceptsyncedAtis equal, using the same comparison asPullRequestSyncReactor.bridge:pr-state:<deliveryId>:<threadId>:link|branch.Response and errors:
{ applied: [threadId], ignored: [{ threadId, reason }] }. No match returnsapplied: [], never a 404.{ error: "invalid-request" }for a body that does not decode.New scope
external-sync:writepackages/contracts/src/auth.ts. It is not in the standard or administrative sets.t3 auth session issue --with-scope external-sync:write, needed because scopes are fixed when a token is issued. The exact command is indocs/operations/external-pr-sync.md.T3_EXTERNAL_PR_SYNC=1Layers/OrchestrationReactor.tsskip starting both reactors, loggingpull request reactor not started: external sync owns PR state.deploy/bkt3/start.sh: that flip is a later, human-gated step.Not reproduced, by design
thread.pull-request.linkwith sourcestack) needs host reads the webhook does not carry.linkedPullRequestneeds the old PR's state.Follow-up, outside this PR
ThreadSettlementReactordoes its ownpullRequests.summaryandgit.branchPullRequestreads rather than reading the stored snapshot. It keeps working with the switch on, but it still calls GitHub.Evidence
pullRequestStateHttp.expbkt3.test.ts, 6 tests, against a real in-memory engine and temporary git repos with GitHub remotes:unchanged;updatedAtisstale, and the title is kept;unchanged;stale;Mutation checks: disabling the branch path fails the branch test, and disabling the stale guard fails the linked test.
CLI checked against a scratch base dir.
--with-scope external-sync:writeissues a session with the 8 administrative scopes plusexternal-sync:write, and--with-scope bogusis rejected.Also run:
vp run typecheckinapps/serverandpackages/contracts: clean;OrchestrationReactor.test.ts: passes;Model/harness: Claude Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.