Skip to content

Meter GitHub API point budgets per HTTP request - #11915

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-cli-proxy-github-api-point-limiter
Nov 21, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/fix-cli-proxy-github-api-point-limiter

Conversation

@lpcox

@lpcox lpcox commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

GitHub API point budgets counted only literal gh api invocations, leaving high-level commands unmetered and pagination undercounted. Implicit POSTs and GraphQL mutations were also underpriced.

  • HTTP enforcement: Move accounting into the protected CLI proxy’s HTTP shim. High-level commands, pagination, and retries share independent REST/GraphQL counters; over-budget requests receive HTTP 429 before forwarding.
  • Correct costs: Charge reads one point and writes five. Classify GraphQL operations with a bounded lexical scanner; mutations and ambiguous documents conservatively cost five.
  • Boundary handling: Reject malformed request targets, recognize non-canonical GraphQL paths, and cap buffered GraphQL bodies at 1 MiB.
  • Documented semantics: Exclude startup probes. Clarify that enforcement is per request—not atomic per command—so earlier requests may complete before a later denial.
  • Regression coverage: Exercise pr comment, issue create, pagination, implicit POSTs, concurrent requests, and accounting bypasses.

@lpcox lpcox changed the title [WIP] Fix cli-proxy GitHub API point budget counting Meter GitHub API point budgets per HTTP request Nov 21, 2026
@lpcox
lpcox marked this pull request as ready for review November 21, 2026 18:27
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The startup probe forwards a dummy authorization token that breaks liveness checks, while GraphQL misclassification allows budget and body-cap bypasses and can reject valid reads.

3 open issues
What changed in this PR

This PR moves GitHub API point accounting from command parsing to the protected gh HTTP shim, addressing the high-level command and pagination gaps in #11914.

Changes:

  • Enforce independent REST and GraphQL budgets per HTTP request, including pagination and retries.
  • Classify read/write costs, validate request targets, and cap buffered GraphQL bodies at 1 MiB.
  • Expand regression coverage and document startup-probe exclusion and partial command execution.
File Description
docs/​awf-config-spec.md Documents per-request costs, limits, and failure semantics.
containers/​cli-proxy/​server.test.js Adds real-gh regressions against a local upstream.
containers/​cli-proxy/​server.js Removes command-level point enforcement.
containers/​cli-proxy/​github-api-point-limiter.test.js Tests HTTP costs, GraphQL classification, and independent budgets.
containers/​cli-proxy/​github-api-point-limiter.js Replaces argument pricing with HTTP request accounting.
containers/​cli-proxy/​gh-http-shim.test.js Covers budget denials, concurrency, request targets, and body limits.
containers/​cli-proxy/​gh-http-shim.js Enforces budgets before forwarding requests.
containers/​cli-proxy/​entrypoint.sh Moves shim startup after liveness probes and changes probe headers.

Review effort: Max (adaptive)

Comment thread containers/cli-proxy/entrypoint.sh Outdated
if timeout "${LIVENESS_TIMEOUT_SECONDS}" gh api rate_limit \
# The HTTP shim is not running yet; remove gh's placeholder authorization
# here just as the shim does for agent traffic.
if timeout "${LIVENESS_TIMEOUT_SECONDS}" gh api rate_limit -H 'Authorization:' \
function isGraphqlRequest(url) {
const path = decodeURIComponent(url.split('?', 1)[0]).replace(/\/+/g, '/');
const pathname = new URL(`http://localhost${path}`).pathname.replace(/\/+$/, '');
return pathname === '/graphql' || pathname === '/api/graphql';
}
if (!endpoint || invalidMethod) return null;
if (endpoint === 'graphql') return { kind: 'graphql', points: READ_POINTS };
return firstToken === 'query' || firstToken === '{';
@lpcox

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

Copilot AI commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed the probe auth, GraphQL path normalization, and top-level operation classification feedback in f3e051a.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@lpcox Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation has been built for this PR.

Download preview artifact

To view locally:

  1. Download the docs-preview-pr-11915 artifact from the workflow run
  2. Unzip and open index.html in your browser

Built from commit 1dfb9e7

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 94.41% 94.44% 📈 +0.03%
Statements 93.04% 93.07% 📈 +0.03%
Functions 93.62% 93.64% 📈 +0.02%
Branches 87.36% 87.36% ➡️ +0.00%
📁 Per-file Coverage Changes (4 files)
File Lines (Before → After) Statements (Before → After)
src/enclave/docker-host-execute.ts 97.2% → 96.2% (-1.00%) 92.7% → 90.5% (-2.14%)
src/cloud-hypervisor/manager-start.ts 88.5% → 89.1% (+0.59%) 89.9% → 89.8% (-0.07%)
src/nfs-home.ts 90.6% → 91.2% (+0.59%) 85.9% → 91.9% (+5.96%)
src/commands/main-action-cleanup.ts 96.9% → 97.9% (+1.03%) 97.0% → 98.0% (+0.99%)
✨ New Files (9 files)
  • src/nfs-home-copy.ts: 88.0% lines
  • src/nfs-home-exclusions.ts: 100.0% lines
  • src/nfs-home-tools.ts: 97.9% lines
  • src/cloud-hypervisor/manager-start-launch.ts: 97.8% lines
  • src/cloud-hypervisor/manager-start-network.ts: 86.1% lines
  • src/cloud-hypervisor/manager-start-stage.ts: 100.0% lines
  • src/enclave/docker-host-cleanup-stage.ts: 97.8% lines
  • src/enclave/docker-host-run-stage.ts: 98.7% lines
  • src/enclave/docker-host-storage-stage.ts: 100.0% lines

Coverage comparison generated by scripts/ci/compare-coverage.ts

@lpcox
lpcox merged commit cd8b83e into main Nov 21, 2026
43 of 44 checks passed
@lpcox
lpcox deleted the copilot/fix-cli-proxy-github-api-point-limiter branch November 21, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli-proxy GitHub API point budget only counts literal gh api invocations

3 participants