Skip to content

perf(security): fetch once per run instead of once per item - #1443

Merged
potiuk merged 2 commits into
mainfrom
perf/security-batch-fetches
Sep 28, 2026
Merged

potiuk merged 2 commits into
mainfrom
perf/security-batch-fetches

Conversation

@potiuk

@potiuk potiuk commented Sep 28, 2026

Copy link
Copy Markdown
Member

Seventh PR in the security family stack (#1344): the optimize-skill fetch-upfront pass.

Summary

The security skills re-ran the same reads per candidate, per tracker or per finding. They now fetch each shared set once per run and reuse it. The set of items processed and the per-item decisions are unchanged. Every batched list keeps an explicit --limit and says what to do when the cap is hit.

skill before → after
issue-import mail-thread reads per candidate 4 → 2. Step 7 keeps one fresh read, because a draft or reporter reply can land between scan and apply. Semantic-sweep list, collaborator list and rejections-ledger lookup once per run. Thread-id dedup: 6 ids per search.
issue-import-from-md labels set at creation: 2 calls per finding → 1
issue-import-from-pr two duplicate-guard searches → one
issue-import-from-scan open-tracker list once for all findings
issue-triage per-tracker gh issue view → one GraphQL query per 20 trackers (body, comments, linked PRs)
issue-invalidate proposed reactions call + issue view per tracker → one GraphQL query per 20. Limit aligned with triage: 1000, stop when capped.
issue-sync linked PRs in one query; PR authors reused; hand-off comment 3 calls → 1; milestone bullet 4 calls → 0; advisory probe doubles as the fetch
issue-fix collaborator check: one list per run instead of one call per author
issue-deduplicate / cve-allocate redundant existence probes and title re-fetch removed
model-verify AGENTS.md + SECURITY.md for every repository in one query
workflow-security-audit zizmor over ≤ 50 repositories per run. A failed batch is re-run per repository, so a failure is never reported as clean.
tracker-stats-dashboard bodies and linked PRs from the list call: one gh issue view per issue → 0. Warns at the list cap.

Deliberately kept per item:

  • import Step 2b's closed-invalid search and from-md's duplicate guard. Both match keywords server-side in issue bodies; a local title-only match would miss duplicates.
  • triage's cross-repo PR search, because an OR'd search cannot attribute hits to a tracker.
  • freshness reads right before a draft is created.

Along the way:

  • Several gh calls wrapped in $(…), piped into jq, or redirected are now plain commands. Under the secure setup a wrapped gh stays sandboxed and fails.
  • import Step 2c asked gh search prs for a mergedAt field it does not have, and computed its date with GNU-only date -d.

Test plan

  • prek run --all-files, including lychee; skill-and-tool-validate (--limit rule); check-placeholders
  • tools/security-tracker-stats-dashboard: 142 tests
  • Every eval whose extracted section changed, run before (this PR's base) and after, outside the sandbox:
eval step before after
cve-allocate step-2 4/4 4/4
issue-deduplicate step-1 4/4 4/4
issue-fix step-3 5/5 5/5
issue-import step-0 / 2 / 4 / 7 3/3, 3/3, 5/5, 3/3 3/3, 3/3, 5/5, 3/3
issue-import step-2a 6/6 6/6
issue-import step-2b 2/4 2/4 (same two cases)
issue-import step-3 9/9 9/9

step-2a/case-3-same-reporter flipped to failing on the first after-run. Its output spec said a reporter-identity hit needs the address to match, while the skill matches on the local-part. The fixture's addresses share a local-part across different domains, so small wording changes flipped the verdict. The spec now states the skill's local-part rule, and the case passes 3/3.

step-3/case-2 flipped once and passed 3/3 on re-run: noise.

Part of #1344.

Generated-by: Claude Code (Opus 5.5)

🤖 Generated with Claude Code

@potiuk potiuk added the family:security security-* skills label Sep 28, 2026
@potiuk
potiuk added this pull request to stack #1445 September 28, 2026 07:54
@github-actions github-actions Bot added the substrate:analytics Tool substrate: read-only metrics / dashboards / renderers label Sep 28, 2026
Base automatically changed from fix/security-behaviour-fixes to main September 28, 2026 08:56
potiuk and others added 2 commits September 28, 2026 10:56
The security skills re-ran the same reads per candidate, per tracker or
per finding. They now fetch each shared set once and reuse it, without
changing which items are processed or how each one is decided. Every
batched list call keeps an explicit --limit and says what to do when
the cap is hit.

- security-issue-import: each mail thread is read in full once
  (Step 2a) and reused by Steps 3-4. Step 7 keeps one fresh read,
  because a draft or reporter reply can land between scan and apply
  (4 reads per candidate -> 2). The semantic-sweep list, the
  collaborator list and the rejections-ledger number are fetched once
  per run. Thread-id dedup searches run 6 ids per query.
- security-issue-import-from-md sets labels at creation (one call per
  finding instead of two). security-issue-import-from-pr's two
  duplicate searches are one. security-issue-import-from-scan fetches
  the open-tracker list once for all findings.
- security-issue-triage gathers body, comments and linked PRs for up to
  20 trackers per GraphQL query instead of one `gh issue view` each.
- security-issue-invalidate `invalidate proposed`: one GraphQL query per
  20 matches replaces a reactions call plus an issue view per tracker.
  The list limit is aligned with triage (1000, stop when capped).
- security-issue-sync reads each surface once per run: linked PRs in one
  query, PR authors from that result, and the hand-off comment and
  milestone bullet from the first issue read (3 calls -> 1 and
  4 calls -> 0).
- security-issue-fix: one collaborator list per run.
  security-issue-deduplicate: no redundant existence probes.
  security-cve-allocate: no title re-fetch.
  security-model-verify: one query for every repository's AGENTS.md and
  SECURITY.md.
  workflow-security-audit: zizmor runs over up to 50 repositories per
  invocation, and a failed batch is re-run per repository so a failure
  is never reported as clean.
- security-tracker-stats-dashboard takes issue bodies and linked PRs
  from the one list call instead of one `gh issue view` per issue, and
  warns when the list hits its cap.

Along the way, several `gh` calls wrapped in `$(…)` or piped were made
plain commands, which the secure setup needs. import Step 2c also asked
`gh search prs` for a `mergedAt` field that does not exist, and used
GNU-only `date -d`.

Generated-by: Claude Code (Opus 5.5)
…on budget (#1447)

Eight security skills spent 203-291 tokens on `description` +
`when_to_use`, which load in every session whether the skill runs or
not. Each now states its purpose, its main trigger phrases and where to
route instead, in about 100-130 tokens, leaving the procedure and the
rationale to the body.

security-issue-fix no longer says public PR content must not link back
to the tracker, in its description or its golden rules: tracker
identifiers are public-safe per AGENTS.md, as long as no security
framing surrounds them, and the skill's own 5c rule already says so.

The family's always-on total drops from ~1.6k to ~1.1k tokens
(docs/setup/marketplace.md updated).

Generated-by: Claude Code (Opus 5.5)
@potiuk
potiuk force-pushed the perf/security-batch-fetches branch from 2e29d5b to 0866825 Compare September 28, 2026 08:56
@potiuk
potiuk merged commit bce7505 into main Sep 28, 2026
10 checks passed
@potiuk
potiuk deleted the perf/security-batch-fetches branch September 28, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

family:security security-* skills substrate:analytics Tool substrate: read-only metrics / dashboards / renderers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant