Skip to content

feat(quarantine): rescan automatically after a tool definition change (Spec 118) - #1689

Merged
Dumbris merged 2 commits into
mainfrom
claude/zen-grothendieck-51c909
Oct 20, 2026
Merged

Dumbris merged 2 commits into
mainfrom
claude/zen-grothendieck-51c909

Conversation

@Dumbris

@Dumbris Dumbris commented Oct 20, 2026

Copy link
Copy Markdown
Member

What

After a tool definition changes, the review screen no longer says "Scan out of date … Rescan" with an unscanned held tool. In manual and scan trust modes (not auto):

  • Per-tool evidence. A changed tool, a still-changed tool whose definition moves again, a newly pending tool, and a pending tool whose definition moves are scanned in-process, and the result is recorded via recordScanHold. A clean verdict is stored as held_reason: awaiting_review, held_verdict: clean, so it is distinct from scan_findings (threat) and scan_coverage (precaution). Web UI shows "Scan clean, awaiting your review"; tools list HELD shows clean.
  • Fresh server scan. A debounced (5 s, coalesced per server) informational rescan, fed by a new Runtime.AddToolDefinitionsChangedObserver, brings the review scan line back to "current". It reuses the claim, the run mutex and the maxInformationalScanAttempts cap; a busy slot re-arms instead of failing. Skips disabled, auto, and quarantined scan-mode servers.
  • Switches. security.auto_baseline_scan AND the new security.auto_rescan_on_change (*bool, default on, env MCPPROXY_AUTO_RESCAN_ON_CHANGE, env wins). Wired through loader, env, hot-reload, /config/apply, swagger, docs.

RT-02 invariant is untouched

No approval decision, status transition or gate changed. A clean verdict never approves a changed or new tool in manual or scan mode (tests assert status stays changed/pending and ApprovedHash does not move). awaiting_review also does not widen the review screens' default selection (reviewDefaultAllowed still requires an empty held_reason).

Notes: the trust_mode: scan gate's own scan of new tools is not switched off by either setting. A pending tool whose definition moves is now rescanned, which replaces stale evidence of the old definition (one legacy-adoption test now pins its carry-over with the switch off). Spec: specs/118-auto-rescan-on-change/spec.md.

Verification

  • go test -race ./internal/runtime/... ok; config, storage, httpapi, cmd/mcpproxy ok; CI-style -tags server race run (serveredition, config, oauth, server, httpapi, storage) ok
  • ./scripts/test-api-e2e.sh: 69 passed, 0 failed
  • Both golangci-lint runs: no findings in touched files (remaining findings are pre-existing, in untouched files)
  • vitest hold-evidence suites (60 tests), vue-tsc clean

🤖 Generated with Claude Code

… (Spec 118)

In manual and scan trust modes, a changed or newly pending tool now gets the
in-process TPA scan of its current definition recorded as hold evidence
(held_reason awaiting_review + held_verdict clean for a clean verdict), and a
debounced informational server rescan brings the review scan line back to
current. Gated by security.auto_baseline_scan and the new
security.auto_rescan_on_change (env MCPPROXY_AUTO_RESCAN_ON_CHANGE).

RT-02 is untouched: a clean verdict never approves a changed contract.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 85.93750% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/server/scan_informational.go 91.26% 5 Missing and 4 partials ⚠️
internal/runtime/tool_quarantine.go 84.09% 6 Missing and 1 partial ⚠️
internal/runtime/tool_definitions_observer.go 62.50% 5 Missing and 1 partial ⚠️
internal/config/loader.go 66.66% 3 Missing ⚠️
internal/config/process_overrides.go 66.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris enabled auto-merge (squash) October 20, 2026 16:17
@Dumbris
Dumbris merged commit e22ed67 into main Oct 20, 2026
53 checks passed
Dumbris added a commit that referenced this pull request Oct 22, 2026
## Description

`TestInformationalRescan_BusyServerIsRetriedNotDropped` (Spec 118,
#1689) failed on `main` in 4 of the last 8 unit-test runs and was the
only red check on contributor PRs #1727, #1725 and #1715.

**Cause.** `fireInformationalRescan` deletes the server's entry from
`infoRescanTimers` when the debounce timer fires and re-creates it only
after the gates and the claim ran. On every busy fire there is a short
window in which "is a timer armed" is false. The test sampled the map at
one fixed instant (`time.Sleep(4 * debounce)`), which under CI load
lands in that window. Reproduced locally: 1 failure in 150 runs with
`GOMAXPROCS=1` under 2×ncpu CPU burners.

**Fix (test only).** Read `infoRescanSeq` under the mutex before
scheduling; the change itself takes `before+1`, so
`require.Eventually(rescanSeq("srv") > before+1)` is a timing-free proof
that a busy fire re-armed the timer. The "no scan attempted on top of a
claimed slot" and "a busy slot is not a failed attempt" assertions are
unchanged.

**Verification.** 400 runs of the fixed test under the same CPU
contention: 0 failures. `go test -race -count=3 -run
TestInformationalRescan ./internal/server/` green. `golangci-lint` with
the CI v2 config clean. Cross-reviewed with opencode (gpt-6.1-sol), two
rounds: round 1 found the baseline read could hit the same gap (fixed by
reading the counter before scheduling), round 2 CLEAN.

No production code changes.

## Second flake, same PR

`TestRefreshConcurrency_ScansDuringASlowSelfCheckSeeOldOrNew` (from
#1720) failed the darwin-amd64 Build Binaries job on this PR: `119.6ms
is not less than 109.7ms (baseline median 1.19ms)`. Both
refresh-concurrency guards compared the single worst of 300 scans
against `50*median+50ms`, which one GC pause on a macOS runner exceeds.
They now bound p90 relative to the baseline and keep an absolute 2 s
ceiling on the worst scan (no scheduler stall reaches it, any wait
behind the gate or a fetch deadline does). 30 runs under CPU contention:
0 failures. opencode Sol 6.1 round 1 flagged that p90 alone could hide
one scan absorbing a timed-out wait; the absolute ceiling is the answer
to that.
Dumbris added a commit that referenced this pull request Oct 30, 2026
…line, diacritics, tr/el corpus, name squat (R2-1..R2-5) (#1714)

## Summary

Round-2 TPA red team (2026-10-20) against the hardened detect engine and
tool-level quarantine: every finding was reproduced on this machine
first, then closed with one commit-sized change per component, each
verified end to end on the local instance and cross-reviewed. Report:
`docs/research/2026-10-11-tpa-attack-lab/round2-2026-10-20.md` (spec,
evidence, post-fix results, review rounds).

| Finding | Before | Protection | After |
|---|---|---|---|
| **R2-1 (HIGH)** auto-baseline poisoning: an unquarantined first-seen
server auto-approved its whole toolset with no scan; an 18-vector
poisoned catalog was live, indexed and callable | `R2-1 HOLE` (22
approved rows, poisoned tool called) | **P1**
`internal/runtime/tool_quarantine.go`: the first-seen toolset is scanned
once with `scanner.ScanToolMetadataVerdict` (peers included, the same
fail-closed seam `trust_mode: scan` uses); verdict read per tool — clean
→ `auto-baseline`, hard/soft finding → **pending** with hold evidence,
degraded scan → every tool pending. Follow-ups: the stranded-pending
promotion (MCP-2931 #4) is gated on the same scan (an all-held toolset
writes no marker, so the next identical list used to promote it); a
clean verdict never erases existing hold evidence | `R2-1 HOLDS` (both
poisoned vectors pending, benign controls still auto-baseline, call
BLOCKED) |
| **R2-3** Turkish/Greek overrides scan clean | 4 BYPASS rows | **P3**
`phrase_injection_i18n.go`: `el` verb-first family
(final-sigma-insensitive); `tr` SOV override + verb-first +
system-prompt disclosure families, imperative suffixes only, consumed
trailing boundary (`phraseFamily.trailingBoundary`) so suffix negation
stays clean; corpus now de fr es it pt nl pl ru uk el tr zh ja ko |
DOWNGRADED (soft, like every non-English family) |
| **R2-4** combining diacritics defeat de-obfuscation | 2 BYPASS rows |
**P2** `deobfuscate.go`: NFD → homoglyph fold → strip Mn on Latin bases
→ NFC, on the phrase view and the mixed-script view; other scripts'
marks untouched | BLOCKED (hard) |
| **R2-5** name squat with rewritten description (round-1 survivor) | 1
BYPASS | **P4** `shadowing.go`: SOFT shape 1b — distinctive shared name,
genuinely different description, no own-server provenance in the text;
MCP-3520 pair unchanged | DOWNGRADED (soft) |
| **R2-2** unquarantine race (control) | HOLDS | — | HOLDS |

Offline harness: **79 blocked / 40 downgraded / 8 BYPASS → 83 / 44 / 0
BYPASS**, every class change upward.

## Verification (all on this machine)

- `go build ./...`, `go vet`, `go test ./internal/runtime
./internal/qapilot/... ./internal/security/... ./internal/storage/...
./tests/tpa-attack-lab` green; CI-config `golangci-lint` (bare and
`-tags server`) clean except the pre-existing `event_bus.go:1020`
reflect.Ptr nit (untouched).
- `scripts/tpa-lab-redteam-experiments.sh` (fresh state, full rebuild):
`suite result: PASS (every experiment holds)` — EXP-4 (TOCTOU) now holds
at discovery and was re-premised accordingly (an approved poisoned
first-seen contract is scored HOLE).
- `SKIP_BUILD=1 scripts/tpa-lab-redteam-round2.sh`: `R2-1 HOLDS`, `R2-2
HOLDS`, `round-2 result: PASS`.
- `go run ./cmd/tpa-redteam`: `0 BYPASS, 0 baseline-miss`.

## Review

- Multi-lens adversarial review (5 lenses × 3 skeptics per finding): 20
confirmed findings, all fixed or documented in the report (incl. the
repeat-pass gap it found independently of the EXP-4 lab run).
- opencode `gpt-6.1-sol` read-only cross-review, 3 rounds:
`REQUEST_CHANGES` (7, 6 fixed + 1 refuted with a pinning test) →
`REQUEST_CHANGES` (1, fixed) → **`VERDICT: SHIP`**. Verbatim in the
report.

## Documented, not implemented (maintainer decisions)

- `llm_judge` backstop for languages the corpus does not cover (own
spec).
- P4's provenance exemption is text-based and therefore gameable, the
squat finding is symmetric/order-dependent, and the live
ElevenLabs/Kaggle `list_models` descriptions name no server (both would
be soft-flagged once). Keep the exemption, drop it, or demote the shape
to `info` is a product call; the shape is a review hint, not a boundary.
- The plain server-unquarantine door still promotes pending tools
without a scan (R2-1's second reach); the informed review path shows
findings first.

Rebased onto current `main` (Spec 118 auto-rescan, #1689): the only
conflict was an adjacent insertion in `tool_quarantine.go` (kept both);
one TOCTOU test assertion now pins Spec 118's evidence semantics (a
moved pending definition is re-described as `awaiting_review`), and the
lab's `scan_gate_logged` probe accepts #1689's reworded scan-hold log
line (EXP-6b/6c were INCONCLUSIVE on current `main` for that reason
alone). The dockerized suites were re-run on this branch after the
rebase.

Lab/tests: new unit tests per protection, EXP-4 `held`/`yes`/`no`
precondition tables, round-2 runner guard tests (env scrub, pinned dirs,
image, fresh run dir, fail-closed exit).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Dumbris added a commit that referenced this pull request Nov 20, 2026
`roadmap.yaml` had no epics after Spec 117. This PR adds them and
regenerates `ROADMAP.md`.

- **Shipped:** 118 auto-rescan (#1689), 118 pin visibility boundary
(#1684, #1688, #1821), 119 (#1740), 120 (#1781), 122 (#1818) and 123
(#1886, #1887, #1888, #1891).
- **In review:** 121 install surfaces (#1711). There is no `spec:` link
yet because its folder exists only on the PR branch.
- **In progress:** 124 (PR-1 #1918 done; PR-2 CLI and PR-3 Web UI to do)
and 125 (spec plus PR-1..3 done; PR-4 Web UI to do). Merged PRs are
listed as done child tasks, so `--check-github` doesn't flag a merged PR
under an in-progress epic.
- **Spec-only PRs:** 127 (#1943), 128 (#1944) and 129 (#1945).

Merge this after #1943, #1944 and #1945. Until then, `--check-github`
reports their `spec:` links as unresolved; `--check`, the pre-commit
hook, passes.

Not covered: Spec 126 (#1940, open) and the unsynced tasks.md checkboxes
for 123 and 124.
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.

2 participants