Skip to content

feat(miner): cache policy docs with conditional-GET ETags in discovery (#4842) - #5474

Closed
rust-toml wants to merge 2 commits into
JSONbored:mainfrom
rust-toml:feat/policy-doc-conditional-get
Closed

feat(miner): cache policy docs with conditional-GET ETags in discovery (#4842)#5474
rust-toml wants to merge 2 commits into
JSONbored:mainfrom
rust-toml:feat/policy-doc-conditional-get

Conversation

@rust-toml

Copy link
Copy Markdown
Contributor

Summary

Closes #4842

Discovery refetched every target repo's policy docs (AI-USAGE.md / CONTRIBUTING.md) from the GitHub Contents API on every discover run, spending rate-limit budget on content that rarely changes. This adds a small local ETag cache so those fetches become conditional GETs (If-None-Match): when GitHub answers 304 Not Modified, discovery reuses the cached body and GitHub charges no primary rate-limit budget for the
request.

The cache is the fifth local SQLite store (policy-doc-cache.sqlite3, table policy_doc_cache), built on the same local-store.js path/permission boilerplate as the existing four. It holds no miner state — deleting the file only forces the next run to refetch in full.

Stale-safe by construction: a conditional GET always revalidates against GitHub in the same run, so a 304 body is GitHub-confirmed-current, never served blindly. Any cache miss, absent/blank ETag, read/write error, or non-304 response falls back to a full fetch, so the feature can only ever make discovery cheaper — never let a stale policy wrongly permit autonomous work on an opted-out repo. It is inert unless a cache is supplied; discover wires the on-disk store in, and the fan-out library defaults to no cache (byte-identical prior behavior).

Scope

  • The PR title follows type(scope): short summary Conventional Commit format.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves — Closes #4842.

Validation

  • git diff --check
  • npm run typecheck
  • npm run test:coverage — new/changed lines and branches in policy-doc-cache.js, opportunity-fanout.js, and discover-cli.js are 100% covered on the diff (verified by intersecting the diff's added lines against the v8 uncovered-line set).
  • npm run build:miner (new lib/policy-doc-cache.js added to the package's node --check list)
  • npm run miner:env-reference:check (regenerated docs/env-reference.md for the new env var)
  • npm run db:migrations:check / npm run db:schema-drift:check (no schema change; the cache uses a raw local-store table)
  • Miner package pack allow-list validated (both policy-doc-cache files accepted)
  • New behavior has unit tests for every branch: cold-miss caching, 304 revalidation, absent/blank ETag, undecodable body, cache read-error and write-error fallbacks, thrown-fetch path, no-cache inert path, and cross-run on-disk persistence.

No secrets, wallets, hotkeys, trust scores, or private scoring are touched. Not applicable to this change:
actionlint (no workflow edits), test:workers / build:mcp / test:mcp-pack (no worker/MCP change), and the
ui:* checks + UI Evidence (no UI/frontend change). npm audit --audit-level=moderate reports 0 vulnerabilities
(no dependency change).

Safety

  • No secrets, wallet details, hotkeys, coldkeys, PATs, private keys, raw trust scores, private rankings, or private evidence are exposed.
  • Public GitHub text stays sanitized and low-noise (this change adds no public output).
  • Auth/cookie/CORS/GitHub App/session: n/a — the only network change is adding an If-None-Match request header to an existing unauthenticated-capable Contents GET; no auth surface changes.
  • API/OpenAPI/MCP behavior: n/a (no API/MCP surface change).
  • UI changes: n/a.
  • Public docs updated: miner README.md "Local storage" table + generated docs/env-reference.md.

Notes

The cache never weakens the AI-policy hard-skip: a 304 returns the exact previously-fetched body, and every non-304 path re-runs the full fetch + parse, so resolveAiPolicyVerdict sees the same input it would without the cache.

JSONbored#4842)

`discover` refetched each target repo's AI-USAGE.md/CONTRIBUTING.md from the
GitHub Contents API on every run, spending rate-limit budget on near-static
content. Add a local ETag cache (policy-doc-cache.sqlite3, the fifth local
SQLite store) so the fan-out revalidates those docs with an If-None-Match
conditional GET: a 304 reuses the cached body and costs no primary rate-limit
budget.

Stale-safe by construction -- a conditional GET always revalidates in the same
run, so a 304 body is GitHub-confirmed current, and every miss, absent/blank
ETag, read/write error, or non-304 response falls back to a full fetch. The
feature is inert unless a cache is supplied: discover-cli wires the on-disk
store in and owns its lifecycle (mirroring the portfolio queue), while the
fan-out library defaults to no cache, so prior behavior is byte-identical.

Closes JSONbored#4842.
@rust-toml
rust-toml requested a review from JSONbored as a code owner July 12, 2026 22:08
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

Signed-off-by: silver <168391793+rust-toml@users.noreply.github.com>
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.73%. Comparing base (29c18f2) to head (32c5b66).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5474      +/-   ##
==========================================
+ Coverage   94.72%   94.73%   +0.01%     
==========================================
  Files         559      560       +1     
  Lines       44664    44705      +41     
  Branches    14664    14664              
==========================================
+ Hits        42308    42353      +45     
+ Misses       1621     1617       -4     
  Partials      735      735              
Flag Coverage Δ
shard-1 43.87% <0.00%> (-0.18%) ⬇️
shard-2 35.27% <20.93%> (+0.06%) ⬆️
shard-3 32.08% <48.83%> (+0.08%) ⬆️
shard-4 31.29% <20.93%> (-0.76%) ⬇️
shard-5 33.13% <90.69%> (+0.45%) ⬆️
shard-6 43.95% <13.95%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/gittensory-miner/lib/discover-cli.js 100.00% <100.00%> (ø)
...ackages/gittensory-miner/lib/opportunity-fanout.js 97.97% <100.00%> (+2.32%) ⬆️
packages/gittensory-miner/lib/policy-doc-cache.js 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 12, 2026
@loopover-orb

loopover-orb Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review result - fixes required

Review updated: 2026-07-12 22:17:10 UTC

13 files · no blockers · readiness 100/100 · CI failing · dirty

🛑 Suggested Action - Fix Blockers

  • AI review already in progress for this PR head: Another Gittensory pass is already running the AI review for this exact PR head. This pass is skipping to avoid a duplicate LLM call.

Review summary
AI review is already running for this PR head in another Gittensory pass. Gittensory is holding this PR for manual review until that pass completes.

Nits — 1 non-blocking
  • AI review already in progress for this PR head — The gate is held for a human reviewer rather than passed automatically; it re-evaluates once the in-flight review completes or on the next update.

CI checks failing

  • validate
  • validate-code
Signal Result Evidence
Code review ✅ No blockers No AI review summary
Linked issue ✅ Linked #4842
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 17 registered-repo PR(s), 9 merged, 5 issue(s).
Contributor context ✅ Confirmed Gittensor contributor rust-toml; Gittensor profile; 17 PR(s), 5 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence.
Review context
  • Author: rust-toml
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 17 PR(s), 5 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
[BETA] Chat with Gittensory

Ask Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @gittensory ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @gittensory mention with a real question is routed to the closest matching read-only command automatically -- no exact syntax required.

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb

loopover-orb Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Gittensory is closing this pull request on the maintainer's behalf (CI is failing (validate, validate-code); conflicts with the base branch — resolve and open a fresh PR). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add conditional-GET caching for policy-doc fetches

1 participant