Skip to content

improve: reduce PR activity checks to two GraphQL reads - #1159

Merged
steipete merged 3 commits into
mainfrom
steipete/graphql-activity-cursor-v2
Aug 14, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/graphql-activity-cursor-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The ranked GitHub quota analysis found PR activity revalidation as the largest bounded savings opportunity: repository_actions:reviews accounted 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 was fetchReviewedPrActivityCursor fanning out to reviews REST, inline review-comments REST, and GraphQL review threads (src/clawsweeper-github-context.ts:71-125 on the analyzed base), while readStableReviewedPrActivityCursor intentionally 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 was N × 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 side and start_side fields, so a persisted v1 cursor and a live v2 cursor are never treated as directly equal or changed. The comparison returns rebaseline, 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.md remains 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 check passed on final PR head b7b77bd816d07e17839d7ccc2342912ff991994e, including check:dashboard-strict, all builds, linters, 257 test files, and coverage gates.
  • Focused equivalence fixtures cover inline-comment edits, review dismissal, thread resolution, force-push handling, and activity arriving between the two reads. v1 and v2 agree on each stability/activity decision.
  • Loopback request counting through GITHUB_API_URL plus a GraphQL endpoint stub proves single 6 → 2 and eight-PR batch 48 → 2.
  • Partial nested GraphQL data proves fail-closed v1 fallback, an unchanged decision, and exactly one reviewed_pr_activity_cursor_v2_fallback line.
  • Pre-commit and committed-branch Codex autoreviews both completed with no accepted/actionable findings.

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, createGitHubContext v2/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, lease cbx_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 runs scripts/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.md and receipt.json. The receipt binds tested code head 221ba1c2cd159dfbc7c2e5a5fb12dbad73467bd7 and tree 0f041426798f21da69efd4214bcc2912672db3e2; 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.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 11:54 PM ET / August 14, 2026, 03:54 UTC.

ClawSweeper review

What this changes

This PR replaces repeated REST-plus-GraphQL pull-request activity snapshots with a bounded versioned GraphQL cursor and a v1 fallback for incomplete snapshots.

Merge readiness

⚠️ Needs maintainer review before merge - 2 items remain

Keep 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
Reviewed head: b7b77bd816d07e17839d7ccc2342912ff991994e

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The supplied real-behavior proof is strong, while a fresh source-level review remains unavailable because local inspection could not execute.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body provides a recorded Docker-backed loopback run through the production context and stability wrappers, with observable request counts, fallback behavior, and concurrent-change recovery; the proof does not claim live GitHub mutation coverage.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body provides a recorded Docker-backed loopback run through the production context and stability wrappers, with observable request counts, fallback behavior, and concurrent-change recovery; the proof does not claim live GitHub mutation coverage.
Evidence reviewed 3 items Cursor and guard changes: The supplied PR diff adds v2 cursor construction and comparison, then routes review planning and apply freshness checks through explicit equality results rather than raw string equality.
Controlled behavior proof: The PR body supplies a Docker-backed loopback proof receipt recording preserved two-read behavior, v1 fallback, concurrent-change instability, and request reductions from 6 to 2 for one PR and 48 to 2 for eight PRs.
Inspection infrastructure failure: Read-only local inspection could not start: the execution sandbox returned bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted before producing repository output.
Findings None None.
Security None None.

How this fits together

ClawSweeper 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
Loading

Before merge

  • Resolve merge risk (P1) - This changes a persisted review-activity cursor and apply-time automation guard; a source-level audit on the current head is still needed to confirm that the GraphQL decoder cannot omit activity or mis-handle a v1-to-v2 rebaseline.
  • Complete next step (P2) - No discrete mechanical repair was identified; the remaining requirement is a current-head source and history review in a functioning read-only environment.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch surface 14 files affected; +1,336 / -16 lines The change spans cursor logic, apply guards, loopback proof tooling, tests, and operator documentation.
Code and proof growth core source +482; tests/proof harness +695; docs +159 Most of the increase is validation and evidence around the cursor transport change.

Merge-risk options

Maintainer options:

  1. Complete a current-head cursor audit (recommended)
    Verify the v2 decoder, v1 fallback, and rebaseline comparisons against the current branch before merging this persisted-cursor and automation-guard change.
  2. Pause pending inspectable source
    Hold the PR if a current-head source review cannot be performed in an environment that can read the checkout.

Technical review

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

Labels

Label changes:

  • add P2: The PR changes bounded review-activity validation used by automation, with meaningful but limited operational blast radius.
  • add merge-risk: 🚨 compatibility: Persisted v1 review-activity cursors are deliberately rebaselined against the new v2 format.
  • add merge-risk: 🚨 automation: The changed cursor feeds review planning and apply-time freshness decisions.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a recorded Docker-backed loopback run through the production context and stability wrappers, with observable request counts, fallback behavior, and concurrent-change recovery; the proof does not claim live GitHub mutation coverage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides a recorded Docker-backed loopback run through the production context and stability wrappers, with observable request counts, fallback behavior, and concurrent-change recovery; the proof does not claim live GitHub mutation coverage.

Label justifications:

  • P2: The PR changes bounded review-activity validation used by automation, with meaningful but limited operational blast radius.
  • merge-risk: 🚨 compatibility: Persisted v1 review-activity cursors are deliberately rebaselined against the new v2 format.
  • merge-risk: 🚨 automation: The changed cursor feeds review planning and apply-time freshness decisions.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body provides a recorded Docker-backed loopback run through the production context and stability wrappers, with observable request counts, fallback behavior, and concurrent-change recovery; the proof does not claim live GitHub mutation coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a recorded Docker-backed loopback run through the production context and stability wrappers, with observable request counts, fallback behavior, and concurrent-change recovery; the proof does not claim live GitHub mutation coverage.

Evidence

What I checked:

  • Cursor and guard changes: The supplied PR diff adds v2 cursor construction and comparison, then routes review planning and apply freshness checks through explicit equality results rather than raw string equality. (src/review-activity-cursor.ts:1, b7b77bd816d0)
  • Controlled behavior proof: The PR body supplies a Docker-backed loopback proof receipt recording preserved two-read behavior, v1 fallback, concurrent-change instability, and request reductions from 6 to 2 for one PR and 48 to 2 for eight PRs. (docs/proof/graphql-activity-cursor-v2/receipt.json:1, b7b77bd816d0)
  • Inspection infrastructure failure: Read-only local inspection could not start: the execution sandbox returned bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted before producing repository output.

Likely related people:

  • Unresolved (local history unavailable): The required feature-history commands could not execute in the read-only sandbox; the supplied PR context alone does not establish a current-main owner. (role: owner trail unavailable; confidence: low; files: src/review-activity-cursor.ts, src/clawsweeper-github-context.ts)

Rank-up moves

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

  • Run a read-only review of the current head in a functioning checkout before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit c475108 into main Aug 14, 2026
20 checks passed
@steipete
steipete deleted the steipete/graphql-activity-cursor-v2 branch August 14, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant