Repository navigation
perf(gateway): move GitHub discovery off agent turns - #169488
Conversation
Move GitHub availability and worker identity discovery out of agent turns. The Gateway publishes bounded session facts at startup, workspace binding changes, and identity/configuration changes. Turns read them synchronously. Peter, 2026-10-11: GitHub identity preparation must never be awaited by a turn. Until a fact is ready, expose identity status; tool visibility may lag an asynchronous refresh. Retire worker credentials on identity invalidation and check the current published token immediately before launching a worker. Publication and process launch retain their effect-point validation.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR moves GitHub discovery into a Gateway background owner so agent turns consume cached availability and worker credentials. Example: A repository session sends another message through a loopback worker.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open: it delivers an approved performance improvement absent from current main, with no definite introduced bug found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway combines session workspace metadata and the selected GitHub identity into facts consumed by tool discovery and worker launch envelopes. flowchart TD
A[Session workspace changes] --> C[Background discovery]
B[GitHub identity changes] --> C
C --> D[Bounded published facts]
D --> E[Agent tool availability]
D --> F[Worker prelaunch check]
F --> G[Worker credential profile]
Technical reviewBest possible solution: Retain the approved background owner and single pre-launch check, with credential-boundary behavior demonstrated before merge. Do we have a high-confidence way to reproduce the issue? Current main visibly awaits GitHub preparation on agent turns, and the PR reports matched real-Gateway measurements; no target code was executed during this read-only review. Is this the best way to solve the issue? The shared background owner removes duplicate preparation and preserves effect-point checks; the explicit maintainer decision supersedes the earlier request for additional tunnel authorization plumbing. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f59ae8cd0730. Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: No concrete credential leak was found, and the post-check handoff window has explicit maintainer acceptance. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -14, Tests +79, Docs +2, Other -7. Total +60 across 25 files. Added test files: 1. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed October 12, 2026, 2:54 AM ET / 06:54 UTC (Revision 6). |
Background discovery acquires an existing private-session reference under its own lifetime. It keeps the captured namespace incarnation while surviving cancellation and release of the originating turn. Remove the admitted-turn workspace branch and tests now that no production caller uses it.
|
Peter, 2026-10-11: keep the published-head handling: the change handler drops the cached token on identity/config change, and one check immediately before launch rejects a changed identity. The proposed tunnel/adapter authorization plumbing is dropped. Accepted edge case: identity changed between the pre-launch check and the worker receiving the envelope (sub-second) → the next turn uses the new identity; the token is revoked at GitHub if the user disconnected. The existing main-conflict resolution preserves main’s memory-backed session detection. No additional launch-authorization machinery is included. |
Prepare GitHub publication availability and worker launch identity through a Gateway-owned background lifecycle. Local and worker turns consume published facts synchronously; unknown facts expose identity status while preparation runs. Keep immediate cached-token invalidation and one pre-launch identity check. Accepted edge case (Peter, 2026-10-11): identity changed between the pre-launch check and the worker receiving the envelope (sub-second) means the next turn uses the new identity; the token is revoked at GitHub if the user disconnected. Same-host five-run warm medians improved request-to-provider by 18 ms locally and 28 ms over the loopback node. Warm GitHub preparation and its child processes are removed. Production LOC: -14. Focused proof: 17 files, 212 tests; final-head CI passed. Peter, 2026-10-11: GitHub identity preparation must be fully asynchronous and never awaited by a turn.
What Problem This Solves
Every Gateway agent turn repeated GitHub account and workspace discovery before reaching the provider. Worker turns performed the work twice to obtain availability and launch credentials.
User Impact
Ordinary messages and internal continuations now read the last published GitHub fact synchronously. A background owner prepares it at startup, on workspace binding and GitHub identity/configuration changes, and periodically for native CLI login changes. Until a fact exists, the agent exposes
github_identity_status.Tool visibility may briefly reflect the previous account while a refresh runs. Credential invalidation immediately removes the old worker token, and worker launch checks its captured token again immediately before dispatch. Publication and process-launch credential validation remain at their effect points.
Accepted edge case (Peter, 2026-10-11): identity changed between the pre-launch check and the worker receiving the envelope (sub-second) → the next turn uses the new identity; the token is revoked at GitHub if the user disconnected. The change deliberately keeps one pre-launch check without adding authorization plumbing through the tunnel and launch adapter.
Why This Change Was Made
Peter, 2026-10-11: GitHub identity preparation must never run as awaited turn work; it must be fully asynchronous. This replaces the retired per-turn discovery contract. A bounded Gateway-owned cache and its lifecycle subscriptions serve both local tool discovery and worker launches. Repository setup still prepares credentials before its Git operations.
Production LOC: −14 (240 additions, 254 deletions), across 25 changed files. The background owner replaces duplicate turn preparation and the retired admitted-turn workspace reader. Private-session discovery acquires its own existing reference and checks the captured namespace incarnation; it survives cancellation and release of the originating turn. No schema, configuration, or protocol change.
Evidence
Independent review found and verified the worker credential invalidation fix; the corrected change has no actionable P0/P1 findings. Focused discovery, binding, and workspace-authority checks cover pending preparation, credential changes, stale completion, shutdown, and revoked credentials before launch.
Same Hetzner ccx33 host, Node 24.21.0, two warmups and five recorded turns per route, using the real Gateway WebSocket path and the same provider/model:
All measured turns completed successfully. Provider latency also changed, so only the pre-provider improvement is attributed to this change. No separate remote-node result is claimed.
The separate census shows GitHub preparation leaving the warm path: local availability preparation was 11.5 ms/turn; loopback availability and binding preparations were 9.4 and 15.9 ms/turn (inclusive timings). Afterward, only synchronous fact reads remain: 0.010 ms locally and 0.014 ms for loopback. Native child launches fall from 1 → 0 locally and 2 → 0 for loopback; IPC counts fall 26 → 24 and 52 → 48. Aggregate SQL counts do not improve (202 → 203 locally, 434 → 434 for loopback); no SQL performance claim is made.
The new private-session cancellation/release regression fails against the previous discovery owner (availability remains false) and passes with the independent background acquisition. The prepublication dbasync overlap check found no overlapping owners.
Broad static verification passed production types and 27 core-test graphs. The UI-components graph reports existing MCP app test errors:
mcp-app-unmount.test.ts:40accessor/Element mismatch andmcp-app-view.test.ts:801,804,815missingupdateComplete. The same four errors reproduce on clean baselinea22eb8a; these UI files are unchanged. At feature head63427a935395, all 17 focused files / 212 tests passed (1000.23 s wrapper wall time); production types, four Gateway test graphs, type-aware lint and export-collision checks passed. Dead-export and Knip findings matched the baseline exactly (84 and 55 respectively). These are pre-main-integration results, not final-head CI claims.Local focused proof: discovery 5/5, binding 16/16, and final workspace/private availability 9/9 tests passed. Measured wrapper wall times were 48.49 s, 37.00 s, and 388.49 s respectively, including compiled-worker preparation on the loaded host. Cold compiler preparation dominated. The existing main conflict was resolved in
43e772d173b3, preserving main’s memory-backed session detection; that merged tree passed independent review. A later documentation-only conflict resolution (3f4c0b1c76c15) retains main’s worker sandbox-policy clarification and the background identity contract. Measurements compare the original baseline with the initial feature commit; later fixes do not change the measured warm entrypoints.