Repository navigation
improve: reduce PR activity checks to two GraphQL reads - #1159
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 11:54 PM ET / August 14, 2026, 03:54 UTC. ClawSweeper reviewWhat this changesThis PR replaces repeated REST-plus-GraphQL pull-request activity snapshots with a bounded versioned GraphQL cursor and a v1 fallback for incomplete snapshots. Merge readinessKeep open. The supplied patch and proof indicate a focused efficiency improvement with preserved safety guards, but the mandated local source/history inspection could not run because the read-only sandbox failed before executing commands. Priority: P2 Review scores
Verification
How this fits togetherClawSweeper reads pull-request review activity before publishing or applying automated decisions. Those snapshots become a stable cursor used by review-planning and apply-time freshness guards. flowchart LR
A[Pull request activity] --> B[GitHub context reader]
B --> C[Versioned activity cursor]
C --> D[Two-read stability check]
D --> E[Review and apply guards]
B --> F[Complete v1 fallback]
F --> C
Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the bounded v2 snapshot with complete v1 fallback once a fresh current-head source review confirms decoder completeness, migration behavior, and every freshness call site. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes an internal activity-validation path rather than fixing a reported user-visible defect. Is this the best way to solve the issue? Unclear until a current-head source audit confirms that the new bounded GraphQL representation covers every activity field required by the existing safety contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c175faa03a95. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
What Problem This Solves
The ranked GitHub quota analysis found PR activity revalidation as the largest bounded savings opportunity:
repository_actions:reviewsaccounted for 37,144 observed operations (12.0% of the supplied total), while comments accounted for 74,787 (24.1%) and include the PR-inline share. The hot path wasfetchReviewedPrActivityCursorfanning out to reviews REST, inline review-comments REST, and GraphQL review threads (src/clawsweeper-github-context.ts:71-125on the analyzed base), whilereadStableReviewedPrActivityCursorintentionally read that complete unit twice (src/review-activity-cursor.ts:69-73). Apply repeats the stability check at lease and mutation boundaries (src/clawsweeper-apply-review-activity.ts:15-45,src/clawsweeper-apply-lease-guards.ts:170-205,251-257).Before: one stable check was
2 × (reviews REST + inline-comments REST + review-threads GraphQL) = 6+ requests. A batch of N PRs wasN × 6+requests.After: one stable check is
2 × one complete GraphQL snapshot = 2 requests. A publication batch of up to eight PRs can alias every PR into the same two snapshots, so its formula is also 2 requests.Why This Change Was Made
This adds a versioned v2 cursor built from one bounded GraphQL query containing reviews, nested inline review comments, and review-thread resolution state. The decoder rejects GraphQL errors, missing fields, partial node sets, and any paginated connection; that PR then uses the complete v1 reader and emits one structured fallback line. Throttle and transient failures still propagate instead of amplifying an outage with REST fan-out.
The two-read invariant is unchanged for both single and batched reads. No apply freshness, lease, or mutation boundary was removed.
Migration uses an explicit re-baseline. GitHub GraphQL does not expose REST's immutable
sideandstart_sidefields, so a persisted v1 cursor and a live v2 cursor are never treated as directly equal or changed. The comparison returnsrebaseline, apply reports that the cursor version requires a fresh review, and the next review persists v2. This avoids a spurious “activity changed” result.User Impact
Operators retain the same conservative PR-activity safety decisions while moving the normal activity check off the REST installation pool and reducing its request count from at least six to two. Oversized or incomplete GraphQL snapshots keep the previous complete behavior.
OpenClaw Bay Impact
OpenClaw Bay is unaffected. This changes internal GitHub read transport and cursor comparison only; Bay's observer-only lanes, public fields, and no-action boundary do not change.
Documentation Lifecycle
docs/github-egress-telemetry.mdremains active operator documentation and now describes the v2 request unit and fallback.docs/proof/graphql-activity-cursor-v2/is a historical proof artifact with its owner, tested source, update triggers, limits, and a static verification recipe.Evidence
pnpm run checkpassed on final PR headb7b77bd816d07e17839d7ccc2342912ff991994e, includingcheck:dashboard-strict, all builds, linters, 257 test files, and coverage gates.GITHUB_API_URLplus a GraphQL endpoint stub proves single6 → 2and eight-PR batch48 → 2.reviewed_pr_activity_cursor_v2_fallbackline.Real Behavior Proof
Claim: v2 preserves the stable activity decision while replacing each normal three-endpoint snapshot with one GraphQL request, including the size-eight alias path.
Exercised surface: the production query builder, decoder,
createGitHubContextv2/v1 selection, single and batch stability wrappers, and structured fallback telemetry.Scenario: an isolated loopback GitHub API serves reviews, inline comments, and threads; the harness runs unchanged, edited, dismissed, resolved, force-pushed, partial, and concurrent-change fixtures. The same scenario runs both the v1 and v2 readers and counts every request.
Command and environment: Docker-backed Crabbox
provider=local-container, leasecbx_d96385e7eb89, Ubuntu 26.04/arm64, Node 24.19.0, pnpm 11.10.0. The checked-in container wrapper performs a checksummed Node install, builds all TypeScript targets, verifies the supplied Git commit/tree objects, and runsscripts/e2e/graphql-activity-cursor-v2-loopback.mjs.Observed result: exit 0; single v1/v2 counts 6/2; batch v1/v2 counts 48/2; fallback decision unchanged; one fallback telemetry line; concurrent change unstable; both single and batch v2 paths made exactly two reads. Crabbox auto-stopped the one-shot lease.
Artifact/trace:
docs/proof/graphql-activity-cursor-v2/README.mdandreceipt.json. The receipt binds tested code head221ba1c2cd159dfbc7c2e5a5fb12dbad73467bd7and tree0f041426798f21da69efd4214bcc2912672db3e2; the final PR head adds only the proof directory, which the committed static recipe verifies.Limits: the proof uses deterministic loopback fixtures, not live GitHub mutations. Connections beyond 100 reviews, 100 threads, or 100 comments per thread intentionally fall back to v1. Actual GitHub latency and quota-reset behavior are not measured.