Skip to content

fix(github): enforce gh request throttling, disk quota persistence, and diff-only project sync (#211) - #212

Merged
dan-petty merged 21 commits into
release/v0.2.18from
fix/211-rate-limit-budget-pacing-project-sync
Sep 15, 2026
Merged

dan-petty merged 21 commits into
release/v0.2.18from
fix/211-rate-limit-budget-pacing-project-sync

Conversation

@dan-petty

@dan-petty dan-petty commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Enforces window-budgeted rate pacing, cross-process quota disk persistence, and diff-only project synchronization to permanently eliminate GitHub GraphQL quota exhaustion.

Closes #211.

Deliverables

  • Window-Budget Pacing: add gh request delay to prevent quota exhaustion.
  • Diff-Only Project Reconciliation: In projects.py, items and custom fields are retrieved in a single cached query (gh project item-list), and field mutations are skipped if remote values already match. Reduces steady-state mutations to 0.
  • No-REST Fallback: Removed REST fallback workarounds in PR threads to strictly honor GraphQL quotas and backoff.

@dan-petty dan-petty changed the title fix(github): enforce window-budgeted rate pacing, disk quota persistence, and diff-only project sync (#211) fix(github): enforce gh request throttling, disk quota persistence, and diff-only project sync (#211) Sep 15, 2026
@dan-petty
dan-petty marked this pull request as ready for review September 15, 2026 21:41
Copilot AI lite review requested due to automatic review settings September 15, 2026 21:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical workflow security exposure and multiple moderate correctness issues remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR adds GitHub request pacing and quota persistence, implements diff-only project synchronization, removes PR-thread REST fallbacks, and updates sandbox defaults and related coverage.

Changes:

  • Adds adaptive, persistent GitHub quota management.
  • Reconciles project fields only when values differ.
  • Updates sandbox, workflow, documentation, and test support.
File summaries
File Reviewed change / final note
tests/test_valkey.py Valkey CLI error-path coverage.
tests/test_ui_dashboard.py Dashboard lifecycle timing stabilization.
tests/test_test_runner.py Sandbox and profiling coverage. Nit (1 vote): use example.com consistently instead of api.service in fixtures.
tests/test_repos.py Repository command coverage.
tests/test_pr_cmd.py Pull-request command coverage.
tests/test_github_projects.py Project synchronization coverage.
tests/test_github_projects_reconcile.py Project field reconciliation coverage.
tests/test_github_pr_threads.py GraphQL review-thread coverage.
tests/test_argo_gitops.py Argo manifest handling coverage.
src/devops_cli/watchers/live_resource.py Watcher maintenance.
src/devops_cli/watchers/file_watcher.py File-watcher maintenance.
src/devops_cli/valkey/rate_limiter.py Valkey limiter updates.
src/devops_cli/valkey/client.py Valkey client updates.
src/devops_cli/security/sbom.py SBOM metadata handling.
src/devops_cli/security/gitleaks.py Safe-file filtering updates.
src/devops_cli/security/dependency_remediator.py Dependency remediation updates.
src/devops_cli/security/complexity.py Complexity scan maintenance.
src/devops_cli/security/checkov.py IaC path filtering updates.
src/devops_cli/security/aibom.py AIBOM metadata handling.
src/devops_cli/sandbox/models.py Sandbox network-mode validation.
src/devops_cli/k8s/policy.py Kubernetes policy maintenance.
src/devops_cli/k8s/logs.py Kubernetes logging maintenance.
src/devops_cli/k8s/logql.py Log query maintenance.
src/devops_cli/k8s/credentials.py Credential handling updates.
src/devops_cli/k8s/chaos.py Kubernetes chaos maintenance.
src/devops_cli/github/projects.py Cached project reconciliation. Moderate (2 votes): distinguish a valid empty item list from {} fetch failure. Moderate (1 vote): validate nested response mappings before chained .get() calls. Moderate (1 vote): invalidate or bypass the 60-second cache after item mutations. Moderate (1 vote): preserve unknown field state on fallback and skip mutations until values are fetched.
src/devops_cli/github/pr_threads.py GraphQL-only review-thread operations.
src/devops_cli/github/pr_monitor.py Pull-request monitoring updates.
src/devops_cli/exceptions/git.py GitHub rate-limit exception support.
src/devops_cli/exceptions/__init__.py Exception exports.
src/devops_cli/docker/sandbox.py Sandbox network configuration. Moderate (3 votes): use the centralized isolated default in the validator and Docker command defaults instead of bridge.
src/devops_cli/core/process.py Subprocess environment isolation.
src/devops_cli/config/settings.py Configuration path hardening.
src/devops_cli/config/defaults.py Centralized defaults. Moderate (2 votes): SBOM/AIBOM default version 0.1.0 conflicts with package version 0.2.18. Moderate (1 vote): sandbox and Docker entry points still use literal bridge defaults.
src/devops_cli/config/constants.py Shared constants.
src/devops_cli/config/commands.py Command configuration updates.
src/devops_cli/config/__init__.py Configuration exports.
src/devops_cli/commands/vault.py Vault error sanitization.
src/devops_cli/commands/test_cmd.py Sandbox validation and masking. Moderate (1 vote): reuse canonical network-mode constants and aliases. Moderate (2 votes): delegate whitelist URL validation to the shared sandbox model rather than the restrictive regex.
src/devops_cli/commands/repos.py Repository command updates.
src/devops_cli/commands/pr.py Pull-request command updates.
src/devops_cli/commands/k8s/cluster_context.py Cluster output masking.
src/devops_cli/argo/rollouts.py Rollout maintenance.
src/devops_cli/argo/gitops.py Manifest path safeguards.
src/devops_cli/argo/fleet.py Argo fleet maintenance.
src/devops_cli/ai/test_gen.py Test-generation updates.
src/devops_cli/ai/tasks/review.md Review task guidance.
src/devops_cli/ai/router.py AI routing updates.
src/devops_cli/ai/review_schema.py Review schema updates.
src/devops_cli/ai/response_repair.py Response repair updates.
src/devops_cli/ai/repomap.py Repository mapping updates.
src/devops_cli/ai/rag/indexer.py Indexing path safeguards.
src/devops_cli/ai/pydantic_ai_bridge.py Provider bridge updates.
src/devops_cli/ai/mcp/server.py MCP integration updates.
src/devops_cli/ai/instruction_generator.py Instruction generation updates.
src/devops_cli/ai/harness/filesystem.py Filesystem symlink safeguards.
src/devops_cli/ai/function_signature.py Function signature updates.
src/devops_cli/ai/format_prompt.py Prompt formatting updates.
src/devops_cli/ai/durable.py Durable-state updates.
src/devops_cli/ai/context_packer.py Context packing updates.
src/devops_cli/ai/concurrency.py AI concurrency updates.
src/devops_cli/ai/common_tools.py AI tool maintenance.
src/devops_cli/ai/agents/media.py Media handling updates.
src/devops_cli/ai/agents/guardrails.py Guardrail updates.
src/devops_cli/ai/agents/embeddings.py Embedding helper updates.
src/devops_cli/ai/agents/capabilities.py Capability updates.
src/devops_cli/ai/agents/agent.py AI agent refactor.
docs/SELF_IMPROVEMENT.md Remediation records. Nit (1 vote): documented Docker sandbox default does not match the bridge default in the entry point. Nit (1 vote): the documented run_gh() PR-check fallback still uses direct gh api.
docs/MCP_TOOLS.md Sandbox default documentation.
docs/ERRORS.md Rate-limit error documentation.
docs/commands/test.md Test command documentation.
docs/CLI_REFERENCE.md CLI reference updates.
docs/agent/tasks/task-211-rate-limit-budget-pacing-project-sync.md Task acceptance record. Nit (1 vote): the no-REST claim overstates coverage because PR monitor requests still call gh api directly.
AGENTS.md Engineering workflow guidance.
.pre-commit-config.yaml Pre-push CI enforcement.
.github/workflows/project-automation.yml Project synchronization workflow. Critical (1 vote): PR-tree code runs with GH_TOKEN and project write access; use trusted base-branch or pinned code. Moderate (2 votes): concurrency permits simultaneous reconciliations; serialize or coalesce runs project-wide.
.github/workflows/ci.yml CI trigger adjustments.
Review details

Suppressed comments (15)

docs/SELF_IMPROVEMENT.md:198

  • This documentation claims the default changed for devops docker sandbox, but that command still declares network="bridge" in src/devops_cli/commands/docker.py and passes it through unchanged. Update the Docker entry point to use the isolated default (or correct this claim); otherwise users receive a networked sandbox despite the documented security default.
   - Switched default network mode from insecure `bridge` to `isolated` across `devops test sandbox`, `devops docker sandbox`, and FastMCP tools (`docker_sandbox`, `sandbox_deploy`, `sandbox_network_policy`).

docs/SELF_IMPROVEMENT.md:213

  • This session record says PR check fallbacks were routed through run_gh(), but _render_pr_checks_fallback() still invokes run_subprocess(["gh", "api", ...]) in src/devops_cli/commands/pr.py. The claim is false and the fallback still bypasses the centralized GitHub pacing/quota accounting; either migrate that call or document the remaining exception accurately.
   - Routed PR check fallbacks through `run_gh()` with secret masking.

docs/agent/tasks/task-211-rate-limit-budget-pacing-project-sync.md:42

  • The acceptance record overstates the implementation: src/devops_cli/github/pr_monitor.py still resolves PRs and fetches details, reviews, checks, status, and Copilot timeline through direct run_subprocess(["gh", "api", ...]) calls. Those monitor requests bypass the new limiter, so this line must either be narrowed to PR-thread operations or the monitor's REST calls must be migrated before marking the no-REST deliverable complete.
   - Decoupled GitHub Projects v2 automation and card synchronization from the heavy CI quality gate.

src/devops_cli/commands/test_cmd.py:263

  • This new local mode set duplicates SandboxNetworkMode and the centralized mode/alias constants, and it omits accepted aliases such as namespace, public, and local. The test sandbox therefore rejects modes that the underlying model accepts and will drift when a mode is added; validate through the shared model or reuse its canonical constants.
    src/devops_cli/config/defaults.py:504
  • This new constant is not wired into all sandbox CLI entry points: commands/sandbox.py:113 and commands/docker.py still pass a literal "bridge" default. Thus devops sandbox deploy and devops docker sandbox retain the insecure default while only devops test sandbox uses isolated; update the other entry points as part of the default change.
    src/devops_cli/github/projects.py:1269
  • A successful process response can still contain data, repository, or projectsV2 as null or a non-mapping value. This chained .get() then raises AttributeError instead of returning the already-established empty result (None, None, []); validate each nested mapping before traversing it.
    src/devops_cli/github/projects.py:700
  • This cached item-list is also used by sync_remote_project before and after sync_repository_issues_to_project; newly added items can therefore be hidden by the 60-second cache during the immediate reconciliation pass. Their custom fields are not initialized until a later run. Invalidate this query after item mutations, or bypass the cache for the post-mutation reconciliation fetch.
    src/devops_cli/github/projects.py:730
  • When the structured item-list query fails or cannot be parsed, this fallback returns every URL with all field values set to None. _filter_differing_fields() treats each None as drift, so reconciliation then issues all five field mutations for every fallback item—the broad mutation behavior this PR is intended to eliminate. Preserve an explicit unknown state and skip field edits until current values are fetched successfully.
    src/devops_cli/github/rate_limiter.py:928
  • acquire() already decrements a valid quota before every request, so this headerless-response path charges the same request a second time. GraphQL mutations without a rateLimit selection will therefore consume two estimated tokens per call and can trigger the low-quota circuit breaker prematurely; make the pre-request debit and post-request estimate mutually exclusive.
    src/devops_cli/github/rate_limiter.py:516
  • When quota resolution fails, this handler converts GitHubRateLimitError into min_interval (0.0 by default) and continues. An unknown or expired quota can therefore send the request immediately, defeating the exhaustion-prevention guarantee; let the error propagate or fail closed with a bounded wait instead.
    src/devops_cli/github/rate_limiter.py:409
  • Because this valid local state returns before the disk reload below, a long-lived process never observes quota decrements persisted by another process while its own state remains valid. That defeats cross-process quota accounting and lets each process pace from stale remaining values; reload/merge the persisted state before reserving quota, with inter-process coordination.
    src/devops_cli/github/rate_limiter.py:149
  • The temporary-file replacement is atomic against partial writes, but it does not serialize processes or merge their current quota state. Two processes can decrement the same old value and the last replacement can erase the other request's usage, so the disk cache undercounts consumption; protect the read-modify-write sequence with an inter-process lock or equivalent.
    src/devops_cli/github/rate_limiter.py:943
  • The public cost argument is accepted by run_gh, but the normal execution path calls _post_process_run() without passing it, so headerless requests always decrement the quota estimate by 1. Any caller supplying a higher GraphQL cost therefore gets no protection; propagate cost through both normal and paginated execution paths.
    src/devops_cli/github/rate_limiter.py:58
  • The quota model’s validation path raises a bare ValueError (and the same pattern is repeated throughout this limiter), which violates the repository’s domain-exception contract (AGENTS.md:330). Use a DevOpsCLIError-derived GitHub quota exception for invalid state so callers receive the canonical exit code/error metadata; retain ValueError only through multiple inheritance if compatibility with these tests is required.
    tests/test_test_runner.py:139
  • Repository test fixtures use the bare example.com placeholder; introducing api.service creates a nonstandard internal-looking dummy hostname and violates the repository's fixture sanitization convention. Use example.com consistently, including for the port-bearing token.
  • Files reviewed: 79/79 changed files
  • Comments generated: 7
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/devops_cli/commands/test_cmd.py Resolved
Comment thread src/devops_cli/config/defaults.py Resolved
Comment thread src/devops_cli/docker/sandbox.py Resolved
Comment thread src/devops_cli/github/projects.py Resolved
Comment thread src/devops_cli/github/rate_limiter.py Resolved
@dan-petty
dan-petty merged commit a67eb49 into release/v0.2.18 Sep 15, 2026
4 of 5 checks passed
@dan-petty
dan-petty deleted the fix/211-rate-limit-budget-pacing-project-sync branch September 15, 2026 22:35
dan-petty added a commit that referenced this pull request Sep 16, 2026
* feat(release): v0.2.18

* fix(security): harden secret sanitizer boundaries and safe path exclusions (#116) (#203)

* fix(security): harden secret sanitizer boundaries and safe path exclusions (#116)

* fix(release): default release PRs to draft mode

* fix(security): harden secret boundaries, remove extension lookahead, and update task status (#116)

* fix(security): remediate devsecops findings and add native rate management (#204)

* test

* fix(security): remediate devsecops findings and add native rate management

* docs(task): update task-204 status to in review and link PR #204

* fix(security): permit token masking in filesystem path arguments

* fix(security): remediate review findings, exclude home in sandbox, and relocate MockProvider (#205) (#206)

* fix(security): remediate review findings, exclude home in sandbox, and relocate MockProvider (#205)

* docs(task): update task-205 status to in review and link PR #206

* test(sandbox): provide explicit tmp_path workspace_dir in test_docker_sandbox_wait_timeout

* fix(rag): support both gitignore and gitwildmatch pathspec factories

* feat(sandbox): multi-tier networking options and decommission task.md (#207) (#208)

* feat(sandbox): multi-tier networking options and decommission task.md index (#207)

* docs(agent): transition task 207 to in-review with PR #208

* test(projects): update test fixtures to eliminate task.md references

* fix(security): replace concrete RFC 1918 and internal homelab endpoints with standard documentation values

* fix(sandbox): harden network containment, secret output masking, and rate limiter caching

* fix(sandbox): remediate egress containment, dns resolution, and output masking findings (#207)

* fix(security): stream sandbox container output directly to sys streams avoiding logger sink cleartext alerts (#207)

* docs(agents): mandate working pull requests from oldest to newest (FIFO)

* docs(roadmap): add v0.2.23 reactive workstation command center and interactive TUI

* docs(agents): mandate root-cause remediation, roadmap synthesis, and interaction improvement

* fix(docs): escape placeholder angle brackets and prune completed roadmap matrix items

* fix(security): stream sandbox output via centralized output writers to resolve codeql cleartext alerts

* fix(k8s): uncap ollama memory limits and elevate daemonset/deployment thresholds (#209) (#210)

* fix(k8s): uncap ollama memory limits and elevate daemonset/deployment thresholds (#209)

* fix(k8s): add CoreDNS resource configs and tighten test assertions (#209)

* fix(github): enforce gh request throttling, disk quota persistence, and diff-only project sync (#211) (#212)

* fix(github): enforce window-budgeted rate pacing, disk quota persistence, and diff-only project sync (#211)

* docs(agent): record PR #212 in task 211 tracking

* fix(github): enforce low-quota circuit breakers, preamble-tolerant JSON parsing, and casing-safe project diffing (#211)

* fix(github): replace quota thresholds with logical exponential backoff (#211)

* test(github): patch run_gh instead of run_subprocess in reconcile tests (#211)

* fix(github): derive rate limit pacing from actual response values without hardcoded windows (#211)

* fix(ci): stop running all of the ci tasks every time a pr is marked ready for review.

* fix(ci): decouple project automation into dedicated workflow and add quota safety guards (#211)

* fix(github): align rate limiter baseline velocity and add quota test coverage (#211)

* refactor(ai): eliminate inline function parameter defaults in favor of defaults submodule

* fix(github): enforce strict non-negative rate quotas, 25% threshold, and remediate review findings (#211)

* fix(typecheck): resolve Path None guard and optional quota remaining in mypy (#211)

* docs: refresh CLI and MCP references for updated commands and errors (#211)

* fix(ci): enforce mandatory pre-push devops ci gate, handle unauthenticated acquire, and expand test coverage (#211)

* fix(pr): align checks fallback to run_subprocess and isolate rate limiter sleep test (#211)

* fix(ci): complete pre-push gate, argo drift tests, and coverage expansion (#211)

* docs(agent): update task-211 documentation with linear window pacing and pre-push quality gate (#211)

* fix(pr): guard pr ready against failing checks and fix project automation uv sync (#211)

* docs(pr): update cli and mcp reference for pr ready --force

* fix(github): address pr 212 review comments on workflows, sandbox, defaults, and rate limiter (#211)

* fix(security): derive artifact version from package metadata and validate whitelist tokens (#211)

* feat(security): sigstore cosign container provenance and image signing (#112) (#213)

* fix(ci): prune all merged PR devcontainer images from ghcr and guard in-flight builds

* feat(security): sigstore cosign container provenance and image signing (#112)

* docs(agent): link PR 213 in task 112 tracking doc

* fix(security): resolve review comments for cosign container provenance (#112)

* ci: re-trigger validation after resolving all review threads

* feat(security): falco ebpf runtime security and anomaly streamer (#113) (#214)

* feat(security): falco ebpf runtime security and anomaly streamer (#113)

* fix(security): resolve review comments for falco ebpf runtime security (#113)

* chore: retrigger validation after resolving all review threads

* feat(security): distributed threat intelligence valkey l2 cache and radar batching (#122) (#215)

* feat(security): distributed threat intelligence valkey l2 cache and radar batching (#122)

* fix(security): resolve review comments for threat intel valkey l2 cache and batching (#122)

* chore: retrigger validation after resolving all review threads

* perf(github): adjust rate limit no-delay used threshold to 30%
@dan-petty dan-petty mentioned this pull request Sep 16, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants