feat(miner): cache policy docs with conditional-GET ETags in discovery (#4842) - #5478
feat(miner): cache policy docs with conditional-GET ETags in discovery (#4842)#5478rust-toml wants to merge 1 commit into
Conversation
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
16580ef to
4240722
Compare
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.
4240722 to
acfe2a3
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5478 +/- ##
==========================================
+ Coverage 94.73% 94.75% +0.01%
==========================================
Files 561 562 +1
Lines 44794 44834 +40
Branches 14667 14667
==========================================
+ Hits 42437 42481 +44
+ Misses 1622 1618 -4
Partials 735 735
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Caution 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥 🛑 Gittensory review result - reject/close recommendedReview updated: 2026-07-12 22:52:47 UTC
🛑 Suggested Action - Reject/Close Review summary Blockers
Nits — 5 non-blocking
Why this is blocked
📋 Copy for AI agents — paste into your coding agent
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
[BETA] Chat with GittensoryAsk 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.
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.
|
|
Gittensory is closing this pull request on the maintainer's behalf (AI reviewers agree on a likely critical defect: packages/gittensory-miner/lib/discover-cli.js:158 opens the optional policy-doc cache outside the try/fallback path, so a corrupt or unwritable policy-doc cache DB rejects `runDiscover` before discovery can proceed; change it to fall back to `null` for the fan-out cache on open failure, e.g. `let policyDocCache = null; let ownsPolicyDocCache = false; try { ownsPolicyDocCache = options.initPolicyDocCache === undefined; policyDocCache = (options.initPolicyDocCache ?? initPolicyDocCacheStore)(); } catch { policyDocCache = null; ownsPolicyDocCache = false; }` and close only when a store was actually opened.). 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. |
Summary
Discovery refetched every target repo's policy docs (
AI-USAGE.md/CONTRIBUTING.md) from the GitHubContents API on every
discoverrun, spending rate-limit budget on content that rarely changes. This addsa small local ETag cache so those fetches become conditional GETs (
If-None-Match): when GitHub answers304 Not Modified, discovery reuses the cached body and GitHub charges no primary rate-limit budget for therequest.
The cache is the fifth local SQLite store (
policy-doc-cache.sqlite3, tablepolicy_doc_cache), built on thesame
local-store.jspath/permission boilerplate as the existing four. It holds no miner state — deleting thefile 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
304body 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;
discoverwires the on-disk store in, and the fan-out library defaults to no cache (byte-identical priorbehavior).
Closes #4842
Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #4842.Validation
Branch is rebased on current
main(0 commits behind, no conflicts); all checks below were run against themerged tree, including its interaction with the fan-out rate-limit throttling already on
main.git diff --checknpm run typechecknpm run test:coverage— new/changed lines and branches inpolicy-doc-cache.js,opportunity-fanout.js, anddiscover-cli.jsare 100% covered on the diff (verified by intersecting the diff's added lines against the v8 uncovered-line set). The broader fan-out suite (105 tests) also passes with the change applied.npm run build:miner(newlib/policy-doc-cache.jsadded to the package'snode --checklist)npm run miner:env-reference:check(regenerateddocs/env-reference.mdfor 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)policy-doc-cachefiles accepted)304revalidation, 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 theui:*checks (no UI/frontend change).npm audit --audit-level=moderatereports 0 vulnerabilities (nodependency change).
Safety
If-None-Matchrequest header to an existing unauthenticated-capable Contents GET; no auth surface changes.README.md"Local storage" table + generateddocs/env-reference.md.Notes
The cache never weakens the AI-policy hard-skip: a
304returns the exact previously-fetched body, and everynon-304 path re-runs the full fetch + parse, so
resolveAiPolicyVerdictsees the same input it would without thecache.