Skip to content

perf(gateway): move GitHub discovery off agent turns - #169488

Merged
steipete merged 7 commits into
mainfrom
perf/github-background-facts
Oct 12, 2026
Merged

steipete merged 7 commits into
mainfrom
perf/github-background-facts

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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:

Median (ms) Local before → after Loopback node before → after
Request start → provider request 407 → 389 (−18) 485 → 457 (−28)
TTFT 1960.7 → 1740.8 1735.4 → 1644.3
Provider terminal → final 122.7 → 119.4 406.8 → 361.6
Final reply 2422.2 → 2210.6 2472.5 → 2265.6

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:40 accessor/Element mismatch and mcp-app-view.test.ts:801,804,815 missing updateComplete. The same four errors reproduce on clean baseline a22eb8a; these UI files are unchanged. At feature head 63427a935395, 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This 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.

  • Before: The turn awaits separate GitHub availability and credential preparations.
  • After: The turn reads published facts synchronously; reported median pre-provider latency falls from 485 ms to 457 ms.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, approved performance work with no definite correctness finding; credential-boundary evidence limits confidence.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repository agent turns wait for repeated GitHub discovery before reaching the provider.
Reason: The feature-history owner explicitly approves the direction and freshness tradeoff, and reported Gateway measurements show a modest pre-provider improvement.

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
Reviewed head: 3f4c0b1c76c15c411ff19bcfe3d896c8e1cdd809

Before merge

  • Add real behavior proof - Authority-chain proof required: reported Gateway WebSocket runs exercise the performance path, but do not show a current cached identity reaching its intended worker and an identity invalidated before the pre-launch check being withheld from transport; provide a redacted production-path trace or authorized harness through the real owners, excluding the explicitly accepted post-check window and redacting credentials, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security review attention item - No concrete credential leak was found, and the post-check handoff window has explicit maintainer acceptance.

Findings

None.

Tests

  • Missing end-to-end proof: Supply an allowed-versus-invalidated worker-launch trace through the real discovery owner and transport; the private-session regression is reported to fail before the fix and pass afterward.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Shared tool availability changes intended behavior with a stated reason (45849c0: One host-owned preparation boundary kept publication tools consistent across harnesses and continuations.)
  • Worker GitHub credential preparation changes intended behavior with a stated reason (56d4058: Workers receive the selected shared identity through a private turn envelope and isolated credential profile.)
  • Workspace and private-session reads keeps the original intent (623d8e0: Worker-owned reads preserve live workspace authority while avoiding Gateway-thread SQL; the replacement retains those readers and gives private discovery its own acquisition lifetime.)

Testing

Proof path: shipped entry point.

Security

Needs attention: No concrete credential leak was found, and the post-check handoff window has explicit maintainer acceptance.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0606e31 adds src/gateway/github-publication-availability.ts:28 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0606e31d0e62; files: src/gateway/github-publication-availability.ts)

PR surface

Source -14, Tests +79, Docs +2, Other -7. Total +60 across 25 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 10 240 254 -14
Tests 13 346 267 +79
Docs 1 5 3 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 7 -7
Total 25 591 531 +60

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded agent-turn performance improvement without an established urgent user-facing failure.
  • merge-risk: 🚨 security-boundary: Worker credentials now come from retained background facts; the maintainer explicitly accepts the post-check handoff window, while credential-boundary proof remains tracked separately.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Demonstrate authorized worker credential delivery and rejection when the real identity owner invalidates the captured credential before the pre-launch check.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-12T01:03:48.267Z sha cd821f0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T03:06:56.307Z sha e2a1277 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T03:39:52.154Z sha 63427a9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T04:43:17.824Z sha 63427a9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T05:38:43.658Z sha 63427a9 :: needs real behavior proof before merge. :: none

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.
@steipete
steipete marked this pull request as ready for review October 12, 2026 03:01
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 12, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

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.

@steipete
steipete merged commit c7fae40 into main Oct 12, 2026
139 checks passed
@steipete
steipete deleted the perf/github-background-facts branch October 12, 2026 06:56
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant