Repository navigation
fix: avoid repeated GitHub requests when discovering fork PRs - #190003
Conversation
Reuse each head query within one discovery while preserving per-repository fork matching. Add a regression and recording owner/Gateway workloads for request volume, conditional response bytes, and sampled allocation.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses GitHub list results within one fork-PR discovery and adds recording workloads to measure request volume. Example: Discovery tries lonexreb/another-repository followed by lonexreb/paloa-claw for the same branch.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes verified duplicate discovery requests while preserving fork matching, and no actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway discovers session PRs from checkout and fork candidates, reads GitHub through the existing credential-bound transport, and supplies PR facts to publication controls and Control UI subscriptions. flowchart LR
A[Session checkout] --> B[Bounded fork candidates]
B --> C[Gateway PR discovery]
C --> D[Credential bound GitHub transport]
D --> E[Discovery local list reuse]
E --> F[Repository specific matching]
F --> G[Publication and UI subscriptions]
Technical reviewBest possible solution: Retain discovery-local query reuse and repository-specific admission, then finish the already-declared Gateway campaign before landing. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically repeats a list query when successive candidate repositories share an owner; the supplied parent-red regression and recording measurements corroborate that path, without reviewer execution. Is this the best way to solve the issue? The fix uses the existing discovery owner, retains repository filters and remote revalidation between discoveries, and adds no persistent cache or competing policy owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 52e113b095d9. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +2, Tests +4, Docs +25, Other +719. Total +750 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 Reviewed October 31, 2026, 11:14 PM ET / November 1, 2026, 03:14 UTC. |
|
Merged via squash.
|
…aw#190003) Reuse each head query within one discovery while preserving per-repository fork matching. Add a regression and recording owner/Gateway workloads for request volume, conditional response bytes, and sampled allocation.
Release adaptation: backport only the Socket Mode reconnect waiter owner and focused regression tests; omit the performance harness and main-only transport documentation addition. Add listener-count assertions for timer settlement and disconnect cancellation; adjust the test allocation to 41. Companion dispositions: #198007 is specific to SDK 3.2 callback/abort semantics and is not applicable to this line pinned to socket-mode 3.1.0. #197657 retires main allocations; other audit hits (#200523, #197009, #194964, #184507, #192197, #192051, #190003, #189850) only overlap the excluded shared perf README. No later #188745 mention through bd692e9. (cherry picked from commit a1d1da7) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes repeated GitHub requests while discovering a session's pull request when multiple candidate fork repositories belong to the same owner.
User Impact
Session PR discovery avoids an unnecessary network round trip while preserving which fork repository is accepted. With normal GitHub ETags, the eliminated request is usually a bodyless 304; without validators, it also avoids transferring and parsing the duplicate list. No configuration or data migration is needed.
Why This Change Was Made
Fork candidates are distinct by owner/repository, but the list query selects owner:branch against the same base repository. Reuse each parsed list within that one discovery, then apply the existing repository-specific filter to every candidate. Subsequent discoveries still revalidate remotely. The candidate list is already bounded to three; production code grows by two net lines, without a persistent cache or a new TTL.
The accompanying scripts make the request-volume investigation reproducible through the real owner and a local Gateway, a recording loopback GitHub server, and the actual Control UI PR subscription store. Fixture responses and credentials are synthetic; external fetches are blocked. The fixture generator now includes the explicit agent ownership required for multi-agent startup.
Evidence
The strengthened renamed-fork regression fails on the parent with two list requests where one is expected, and passes with the fix. The owner, publication, and staleness suites passed 39 tests; the final owner suite passed all 26 tests after simplification. All six fixture-generator tests passed.
pnpm check:changed --stagedand the production/full-tree unused-file scans passed. Independent Codex review found no actionable P0–P2 findings.A final-source local Gateway qualification delivered PR 17 to all four UI viewers: four successful subscription calls and four nonempty ready snapshots. The recording server saw 11 requests (seven 200s and four 304s), 75,428 response bytes, and no unmodeled routes. This short run qualifies the harness; its timings are excluded from performance claims.
Owner measurements: five A/B pairs, A/A controls, separate allocation passes
The committed
scripts/perf/github-fork-discovery-measure.tsruns the real owner with prepared repository contexts and a recording loopback server. Each arm performs 1,000 discoveries; all 48,000 measured assertions across four campaigns passed. The mock and client share a process, so these CPU/allocation figures include both. These are per-discovery measurements, not Gateway rates.fullmeans responses without validators;etagmeans warm conditional responses. Allocation uses 32 KiB V8 sampling with collected objects included and sums treeselfSize.No unprofiled candidate metric regressed by 20% or more. ETag pair 3 p50 increased 6.9%; every other unprofiled CPU/p50/p95 cell improved.
The one >=20% adverse candidate cell across all captured metrics is allocation-pass full pair 3 p95: 2.390 → 3.735 (+56.3%). Its total/named-reader allocations improved; its profiler-distorted latency is not used for timing acceptance. A/A adverse cells >=20%: unprofiled full p95 +43.9%, unprofiled ETag CPU +22.7%, profiled ETag CPU +59.7% / p50 +43.4% / p95 +158.3%. Controls and concurrent load preclude a precise latency magnitude claim. No allocation cell regressed.
Reproduce against the parent:
The shared host was busy and synthetic fixture generation ran concurrently. Counts and allocation reductions were consistent; timing magnitudes are not production forecasts. No production allocator attribution is claimed.
Completed Gateway campaign
The real source Gateway, separate recording HTTP server, and actual Control UI PR subscription store completed two A/A controls and five interleaved A/B pairs. Each warm window ran nine turns over approximately three minutes with four viewers, 13 mixed RPC methods, and a 385 ms method tick (observed session-list spacing 5.009–5.013 seconds). All arms performed 36 inference streams, nine tool calls/results, 219 source session events and 876 delivered session events, with four ready PR 17 UI snapshots. Network rates use each actual window, not nominal duration.
Every baseline arm made 17 requests; every candidate made 16. The removed request was a 304. Cold setup had median 12→10 requests (baseline range 12–15), with 75,428 body bytes in both. Initial PR discovery alone went 5→4 requests with identical 74,998 body bytes. Reset-triggered conditionals explain the extra cold-count variation. Raw async ancestry may retain the initiating subscription/reset method; endpoint grouping identifies the PR owner.
All Gateway RPC timing medians and spread
Cells below are median arm p50/p95/p99 in milliseconds, five arms per variant. These are descriptive mixed-workload observations, not a claim that the request fix caused every change.
Selected whole-workload and adverse metrics: each cell is median [minimum–maximum] across arms. CPU is ms/min, memory is decimal MB; other timings are ms. A/A lists the two control values as a range.
Frame-count medians were 9,204→9,236 and frame bytes 37,944,753→39,963,996; semantic session/stream/tool work stayed equal. Presence cadence accounts for most frame variation. First-text latency has no samples and is not claimed.
Explicit acceptance decision
Accept this bounded owner fix despite the recorded adverse whole-workload observations: cards-list p99 11.850→15.946 ms (+34.6%), chat-delta p95 1.751→3.041 ms (+73.7%), and p99 1.855→3.678 ms (+98.3%). These cells are retained as adverse; the campaign is not labeled uniformly green. The request reduction is deterministic, the repeated isolated owner proof shows reduced allocation/CPU, whole-Gateway CPU is essentially flat, and the production change adds only two lines without retaining state beyond one invocation.
The 20% stop rule triggered investigation rather than dismissal as spread. Initial startup +55.7% and cards-median +24.6% effects did not persist under reversed order and five-arm replication. Startup delay was already present in CLI/config initialization before any GitHub call. The chat maxima setting the candidate aggregate occurred in rounds 0/1/2 before the sole warm discovery at 83–86 seconds. Cold discovery precedes explicit forced GC, so its invocation-local map is gone before measurement. Cards tail requests did not overlap discovery; the median-setting candidate p99 sample occurred 53.761 seconds afterward. This separates the observed spikes from execution of the changed operation, but does not prove every indirect effect impossible. This acceptance is limited to the small request-elimination fix; it does not assert a broad Gateway latency improvement.
Separate profiles and scope limits
A descriptive main-isolate allocation pair used 4 KiB sampling including collected objects. Baseline: 3,206,636,448 sampled bytes / 182.453 seconds = 1,054,506,628 B/min. Candidate: 3,183,774,776 / 180.012 seconds = 1,061,190,428 B/min (+0.63%). The denominator is the recorded profile diagnostics window, with a brief control-edge mismatch relative to V8 sampling. This single pair cannot resolve a tiny request-level saving amid gigabytes of other allocations. Both full profile trees had zero observed
readGitHubJsonBodyself/subtree bytes. GitHub API subtree totals were 1,061,760→1,005,400 sampled bytes. Both full-profile counters recorded 876 deliveries; the baseline's narrower cohort samples contain 836, with 40 in control/cohort gaps. Neither a production named-allocator reduction nor a whole-Gateway allocation win is claimed.An ordinary no-fork control produced 15 warm requests/192 B (three PR, nine preview, three account). Nine CPU traces covered 179.553 seconds at 1 ms sampling: 158.116 s idle, 5.976 s dispatch, 2.677 s program, 0.946 s GC; GitHub API subtree 8.593 ms, PR owner 2.542 ms, zero observed reader samples. This control is excluded from timing comparisons.
The fixture has 10,800 original sessions across four agents; all survive the final canonical roster check. Its agent DB is 51.88 GiB, larger than the approximately 35 GiB target, and the active managed workspace has 62,001 tracked files / 1,116,000,022 B. An initial 48 GiB logical-history generation request was interrupted after storage expanded beyond the estimate; canonical recovery and existing fixture owners completed the remaining setup. Actual histories are 3,634 populated / 7,166 empty, with 19,078,809,866 JSONL bytes. The original history target is not claimed complete. This runs on APFS, not btrfs, with four viewers of one active PR; it does not exercise 100 distinct Activity PR rows or ETag working-set churn. Synthetic repository metadata is deliberately minimal (122 B), so absolute body rates are not typical production estimates. No production data or credentials were used.
Gateway reproduction
Use the committed synthetic fixture generator and a suitably sized isolated fixture. The original fixture-generation command requested
--sessions 10800 --agents 4 --runs 0 --approvals 0 --cron 0 --projects 1 --transcript-mib 49152 --worktree-files 62000 --worktree-file-bytes 18000 --github-options-connected; it was interrupted as disclosed above, so that command is not represented as a completed exact fixture recipe.Baseline adds
--github-volume-owner src/gateway/control-ui-session-prs.lane2080-base.tsafter creating the exact parent module using the earlier command. Timing order: AA1, AA2, A1, B1, B2, A2, A3, B3, B4, A4, A5, B5. Allocation passes separately add--allocations --heap-sampling-interval 4096. The ordinary CPU control removes--github-volume-forksand adds--workload-cpu-profile.Exact-head CI 41267254649 passed at
e4df12d75b2cd067a024e22d891126de27ba3477. No inherited-failure exception is used.