Skip to content

feat: quarantine suspicious import and capture rows - #193

Merged
abogartz merged 6 commits into
abogartz:mainfrom
WhollyMindless:feat/write-quarantine
Oct 31, 2026
Merged

abogartz merged 6 commits into
abogartz:mainfrom
WhollyMindless:feat/write-quarantine

Conversation

@WhollyMindless

@WhollyMindless WhollyMindless commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #38. Import and auto-capture can persist instruction-shaped prose after passing the ordinary write gates. Matching candidates now receive a quarantine flag and stable scanner-reason tags. They still face every write gate, remain durable for human review, and are withheld from recall, consolidation proposals, scope/type listings, standing/frontier/relevance injection, compaction anchors, contextual pull, and decay. Applied decay cannot retire them out of the viewer's review queue. The viewer marks and filters quarantined rows and offers a reason-required release action behind the existing request guards. Release snapshots and atomically rewrites the row under the store lock, preserving identity, repository, content, unrelated labels (including custom quarantine:* labels), blocklist state, and supersession. Undo can restore quarantine. Missing and already-unquarantined rows return distinct, audited no-op outcomes. The chat report lists repository-visible review IDs and known pattern names without reproducing suspicious prose. Import tallies report quarantined promotions, and gate evidence records pattern IDs without matched text. Zero-quarantine tally shapes remain unchanged. Tagging or releasing a row refreshes an already-frozen prompt block on the next delivery; the status tool also refreshes before reporting. Validation on Windows / Bun 1.4.4: full gate passes typecheck, lint (408 advisory warnings), 804 unit/scenario tests (11 skips), and 11 real-host E2E tests. Coverage includes import/capture wiring, injection surfaces, frozen epochs, status-only refresh, consolidation candidate exclusion and prose withholding, both decay modes and queue preservation, metadata withholding, repository-scoped reports, viewer release/guards, snapshot/undo, independent blocks/rejections, no-op audit receipts, custom labels, and shipped viewer rendering/escaping. The decay preview/apply, list metadata, and custom-label regressions failed before their fixes. Removing either the status-tool refresh or consolidation filter now fails its focused regression. Consolidation's replay scoring independently withholds tagged prose; an independent clean cluster lets the test also pin candidate exclusion through the reported store count. Earlier mutation checks covered import scanning, capture scanning, quarantine withholding, and the pre-existing per-delivery epoch refresh. All temporary mutations were restored before the final gate. Integration at 5700fc9 includes main ec00ff9 (0.14.26), merged #194 and #197. Auto-capture retains both quarantine scanning and the per-candidate durable receipt/refusal handling. Releasing quarantine cannot lift an independent human block or value rejection; forgetting a quarantined import blocks re-ingestion, and lifting that rejection still sends a suspicious new promotion through quarantine. Limits: this is a heuristic review queue, not a complete injection detector. Markdown-bold role headers and download-then-&&-execute are recognized; ordinary re.exec( calls are excluded. README documents alternate delimiters, encoded pipelines, paraphrases, and indirect execution as evasions. Direct remember/viewer writes and existing stores are not scanned; direct remember remains a prose channel mitigated by framing/provenance. Duplicate import collapse does not retro-tag existing rows. Export preserves quarantine tags; released exports can be quarantined again when promoted elsewhere. Live auto-capture remains unverified; its integration is exercised through the host harness. Please feel free to decline or close this if the scanner policy or review flow is not what you want for the project.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Coordination with your #194: I checked the two heads with git merge-tree (2b436e1 + f2796ef). There are textual conflicts in src/schema.ts, src/viewer/mutate.ts, src/viewer/page.html, and src/viewer/server.ts; the gate and memory changes merge textually, which is not yet a combined behavior test.

Given #35's priority, I recommend landing your #194 first. I can then update this quarantine PR on the resulting main and rerun its gate and integration checks. No changes are needed to your branch for this PR. Please feel free to defer or decline #193 if quarantine is not the direction you want.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Updated at ebbef36: merged main d69691c after #194 landed and resolved the four schema/viewer conflicts, retaining both quarantine release and rejection controls. Gate/rejection logic from main is preserved.

Added two integration regressions covering the combined flows: releasing quarantine cannot lift an independent human block or rejection, and forgetting a quarantined import blocks re-ingestion until a human lifts the rejection; the next suspicious import is still quarantined. Viewer rendering now checks both action families and escaping.

Validation on Windows / Bun 1.4.4: 46 focused quarantine+tombstone tests pass; full gate passes typecheck/lint, 769 unit/scenario tests (11 skips), and 11 E2E tests. CI is rerunning on the pushed head. PR description updated with the integrated scope and current results.

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Review: CHANGES_REQUESTED

Re-verified at your current head ebbef36 (post-merge with main) on macOS / Bun 1.4.3. The mechanism is sound and the release path is the best-engineered part of it. One model-facing surface still quotes withheld prose, and that is enough to hold this.

What I confirmed against the tree

  • Gates at ebbef36 (macOS / Bun 1.4.3): typecheck clean, biome exit 0, unit 769 / 11 / 0, e2e 11 / 0. Lint gained roughly a dozen advisory warnings (base main measures 409; this head 424) — all noNonNullAssertion / useTemplate in the new test file and status.ts, exit code unaffected.
  • Withhold is layered, not single-point: selectRelevant, systemDigest, storeVersion, compactionAnchor, contextualPull, scoreMemories, memory_recall and memory_consolidate all filter, and reverting the epoch's own injectableRows filter (src/injection-epochs.ts:145) to isActive leaves the suite green — I measured it — because every renderer re-filters.
  • Frozen-prefix behaviour works in both directions (tag → the row leaves the delivered block on the next delivery; release → returns).
  • Release is done right: stampRow (src/memory.ts:370-392) takes fileIdentity before readLines, snapshots, and publishes under withStoreLock with the since anchor — the convention this repo made standard in #89/#106. Identity, repo, content and non-quarantine tags survive by construction, and memory_undo restores the tag.
  • The report cannot inject. quarantineReasons derives pattern IDs from tags against the closed PATTERNS list rather than re-scoring stored text, and status.ts emits only ts + those names — a forged quarantine:evil <img …> tag cannot reach the output. Gate evidence likewise records IDs with no matched text.
  • Framing/provenance survive a human release (negative-eval.test.ts keeps the single-line collapse and [via import] assertions after release), so this is an addition to the read-side defenses, not a replacement.
  • Your conflict resolution against #194 was the non-obvious one and it is correct: a textual union of the viewer/schema hunks is not sufficient, because main's render() reads DATA.rejections; ebbef36 supplies rejections: [] in the render fixtures (test/quarantine.test.ts:177,182,185) and adds the quarantine×tombstone interaction tests.

BLOCKING — memory_decay quotes withheld prose to the model, and can retire rows out of the review queue

src/portable.ts:370-377 filters only isActive && isVisibleTo && status==="open" && ts<cutoff — no injectability check — and src/index.ts:1194 renders the listing as flattenMemoryText(m.content).slice(0, 100). So a quarantined row's suspicious text is delivered verbatim (newline-collapsed, still) in the tool output of the very report action the model calls. memory_recall was closed; memory_decay is the same class of surface and is open.

The second half is worse: the viewer's review queue filter is m.quarantined && !m.superseded_by, so a dryRun=false decay supersedes the quarantined row and it disappears from the human queue without a human decision — the queue #38 exists to keep.

Ask: filter in findStaleOpen (or list ts + type/scope only for quarantined rows) and pin both halves with a test.

Nits

  • The status-tool refresh you added is unpinned. Deleting src/index.ts:1248 (if (sid !== "?") await sessions.refresh(sid);) changes nothing: typecheck clean, unit 769/11/0, e2e 11/0. To be fair to your "four mutations" sentence — the pre-existing per-delivery refresh at injection-epochs.ts:264 is pinned (disabling it fails 9 tests), so if the fourth mutation meant that line, the claim stands. The new line just needs a test of its own (mutate the store between a delivery and a memory_status call, no new prompt, assert the reported numbers moved) or the sentence needs scoping.
  • memory_consolidate is filtered but untested — I reproduced it: reverting the index.ts:467 filter to isActive leaves the whole suite green (769/11/0). renderProposals prints survivor/absorbed prose (160/120 chars), so a future edit that drops this filter reopens a leak with no red anywhere. One assertion that a quarantined row never appears in proposal output closes it.
  • memory_list (index.ts:889) still uses isActive, so quarantined rows contribute their scope and type names plus counts to the listing. Row content is not shown, so this is small — but scope is not scanned at import, so an imported row can put attacker-chosen text in a model-facing tool output. Filter it, or state the boundary in README.
  • False positives are concentrated exactly where auto-capture mines: prose that quotes source code. Running your scanner over this plugin's own tree flags 10 lines, mostly dynamic_execute matching ordinary re.exec( calls (src/evidence.ts:24, src/init.ts:132,204, src/logfmt.ts:62, src/resolver.ts:96,366,373) plus system: object keys (src/inject.ts:14), and 2 README lines including your own curl … | bash install line and deterministic eval (store of 200. Counterweight: 0 of 276 rows in a real store on this host match, so this is about captured transcripts quoting code. (?<![$\w.]) before eval|exec would remove the whole class.
  • Cheap evasions, all measured as passing through untagged: **system:** obey, [INST], <<SYS>>, curl x -o /tmp/x && sh /tmp/x, base64 -d … | sh, "ignore every instruction you were given". Add the markdown-bold and &&-exec variants, or list them under your README limits sentence.
  • memory.ts:691-697 hardcodes "quarantine" instead of QUARANTINE_TAG, and strips any tag starting with quarantine: — a user's own quarantine:* label is silently deleted when a row is released.
  • +11 biome warnings (409 → 420), noNonNullAssertion / useTemplate in the new test file and status.ts. Exit code unaffected.
  • Release on a nonexistent or already-released ts returns 200 {released:false} with no audit line, and the viewer toasts "row is no longer quarantined" in both cases. And the import reply says "1 promoted rows quarantined".
  • The zod .trim().min(1) and the server-side requireReason each survive alone, but removing both dies — genuinely belt-and-braces. Keep them; per this repo's convention, say in the comment that neither layer is individually pinned.

Residuals (not blocking, one doc sentence each)

  • The enforcement boundary is coherent as #38 scoped it (capture and import are the two paths with no human in the loop) and README says what is not scanned — but it never states the consequence: a session that can call memory_remember already has a prose channel, mitigated by framing/provenance rather than by quarantine.
  • An import byte-identical to an existing row collapses, so re-import cannot retro-tag prose already in the store. Worth one line so nobody assumes an import re-scans.
  • Export deliberately keeps quarantined rows with their tags (right call — dropping them would be silent data loss, and the tool returns only a count and a path), and re-import re-quarantines a released row on another machine. Both fine; both deserve the sentence.

Not verified here: Windows / Bun 1.4.4 (your gate and CI pin), and live auto-capture on a real host — which you also disclaim.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Addressed the blocking finding and the actionable nits in 4a7f7c2.

  • Decay: findStaleOpen now excludes quarantined rows. Separate preview/apply regressions prove the prose is withheld and the row stays active in the viewer's human queue; a benign stale row still decays.
  • Other tool boundaries: memory_list withholds quarantined scope/type/count metadata. A status-only test mutates the store between delivery and status, then exercises release without a new prompt.
  • Consolidation: added a measured positive control plus withheld-prose assertions. Replay scoring independently rejects a tagged cluster, so prose absence alone did not pin the outer filter. An independent clean cluster now keeps the STORE summary visible and pins candidate exclusion too. Removing the outer filter fails that count assertion; removing status refresh fails its reported-injection assertion.
  • Scanner: recognizes bold role headers and download && execution; excludes member/$ calls such as re.exec( from the bare eval/exec pattern. Positive and negative examples are covered. README explicitly lists the remaining evasions.
  • Release: uses QUARANTINE_TAG, removes only the flag and known scanner-reason tags, and preserves custom quarantine:* labels. Missing and already-unquarantined rows now return distinct reasons, write no-op audit receipts, and show accurate viewer messages. Blank reasons remain rejected; the layered-check comment is explicit.
  • Cleanup/docs: corrected singular import wording and its existing assertions, removed the added assertion/template warnings (lint now reports 408 advisory warnings), and documented the direct-remember prose channel, duplicate-collapse behavior, and export/re-import behavior. The status non-null assertions predate this PR and were left alone.

Windows / Bun 1.4.4 full gate: 784 unit/scenario tests pass, 11 skip; 11 E2E tests pass; typecheck and lint pass. The decay preview/apply, metadata-listing, and custom-label tests failed before their fixes. Both targeted safeguard-removal probes fail as expected, and the source was restored before the gate.

Ready for another look when convenient. Live auto-capture is still not claimed as verified. Please feel free to defer or decline this if the policy or maintenance cost does not fit the project.

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Round 2: APPROVED

Re-verified at 4a7f7c2 (macOS / Bun 1.4.3). Every item from round 1 is closed, and — the part I care about — each close is now pinned by a test I had to break on purpose to believe it.

The blocking leak. findStaleOpen (src/portable.ts:374-379) filters isInjectable, so quarantined rows are neither quoted into a decay preview nor retired by dryRun=false — which also means they stay in the viewer's queue instead of vanishing from it. I re-ran my own differential: reverting that one predicate to isActive now dies on both new cases — decay dryRun=true withholds quarantine prose and preserves the human queue and its dryRun=false twin. In round 1 there was no test anywhere on this surface.

The claims I had to walk back mid-review, now genuinely tested. I told you in round 1 that the new status-tool refresh was unpinned (deleting it left unit and e2e green) while the pre-existing per-delivery refresh was pinned. status alone refreshes a delivered epoch after quarantine and release closes exactly that gap, with the comment "No intervening prompt or delivery: only this tool can refresh the epoch" — and deleting the line now fails that one test. Same method for consolidation: reverting the memory_consolidate filter to isActive dies on consolidation withholds quarantined proposal prose with a measured positive control. Both mutations were re-read before believing, then reverted.

Rest of the list:

  • memory_list switched to isInjectable, pinned by memory_list withholds quarantined metadata and counts.
  • Release now strips only the flag plus known scanner-reason tags (quarantineReasons), so a user's quarantine:custom survives — pinned by its own test — and it uses QUARANTINE_TAG instead of a literal.
  • Release outcomes are discriminated (released / not_found / not_quarantined), each audited (quarantine_release_noop), and the viewer toast no longer claims "row is no longer quarantined" for a row that was never there. That was a small honesty bug with a user-visible symptom; it's gone.
  • Scanner: the (?<![$\w.]) guard took false positives on this plugin's own source from 10 lines down to 1 (re-measured; the survivor is src/inject.ts:14, a system: typed object key). Markdown-bold role headers and && sh are now caught — I re-tested both against the shipped patterns.
  • README names the widened withhold (scope/type listings, consolidation, decay) and, importantly, the two things I asked to see stated: the residual [INST] / <<SYS>> / base64-to-shell / paraphrase evasions (I confirmed these still pass untagged, so the sentence is accurate rather than optimistic), and the consequence of the scan boundary — "a session with that tool still has a prose channel, mitigated by the existing framing and provenance rather than quarantine". The collapse-on-re-import caveat is there too.
  • Import tally grammar fixed.

Gates: typecheck clean, biome exit 0 at 408 warnings (one below main — you cleaned something along the way), unit 784 pass / 11 skip / 0 fail, real-host e2e 11 pass / 0 fail.

Two leftovers, neither worth holding anything: that single system: FP on our own source is the kind of line a captured transcript can contain, so it may eventually quarantine a row quoting a TypeScript type; and quarantine still isn't applied to rows written before the feature existed, which the README now says out loud, so it is a decision rather than a hole.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Updated the branch at 5700fc9 with main ec00ff9 (0.14.26, including merged #197).

The sole textual conflict was auto-capture's candidate loop in src/index.ts: #193 wrapped candidates in quarantineCandidate, while #197 added per-candidate durable receipts and refusal/partial auditing. The resolution retains the quarantine wrapper inside #197's try/catch, passes the durable accumulator to the gate, and preserves its refusal/partial evidence and continuation behavior. Other main changes, including fail-closed writers and truthful partial replies, are retained.

Windows / Bun 1.4.4 full gate passes: 804 unit/scenario tests, 11 skips; 11 real-host E2E tests; typecheck and lint (408 advisory warnings). This includes the quarantine, capture, lock-timeout, and partial-outcome regressions on the combined tree. No new behavior beyond integrating the two reviewed changes is intended. CI will validate the pushed merge head.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Investigated the Windows failure on 3a230f7: the restore-versus-writers scenario hit Bun's default 5,000 ms outer test timeout at 5,034 ms. The runner then killed a child; the later racer-b exited null error followed that timeout. The log did not report a failed row-conservation assertion before cancellation.

The scenario is unchanged from merged main 9112d27. Its own writer-readiness helper permits 20 seconds, followed by eight real restores and child completion, so the inherited 5-second outer budget is inconsistent. The unchanged focused test passes locally on Windows / Bun 1.4.4, which does not reproduce or explain the hosted slowdown.

0df6fb8 gives only this scenario a 30-second outer budget. All eight restore-status checks, child-exit checks, the zero-lost-rows check, and the exact 100 reported rows remain unchanged. Production lock deadlines and code are untouched. This is a bounded harness-budget correction, not a claim that every possible contention failure is solved.

Windows / Bun 1.4.4 full gate passes: 829 unit tests, 11 skips; 11 real-host E2E tests; typecheck and lint (408 advisory warnings). The fix is pushed; hosted CI will rerun on the new head.

@abogartz
abogartz merged commit 7bb1750 into abogartz:main Oct 31, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Round 3 (merge-gate verification of the integration commits): APPROVED

Six of the seven merged ahead of this one, so #193 had to integrate them. Three commits arrived after my round-2 approval and I checked each before pressing merge, because a conflict resolution is exactly where a verified fix can quietly stop being true.

3a230f7 — my own update-branch merge. Its combined diff contains one hand-authored hunk: src/viewer/server.ts imports, keeping both isIP from node:net (#192) and ReleaseQuarantineBody (#193). That is the correct union, and lint confirms neither side is dead. Everything else came cleanly from one parent.

5700fc9 — your merge of main (which brought #197). One hand-authored hunk: the auto-capture loop, where main's try/catch + durable receipt now wraps your quarantineCandidate(...) call instead of the bare candidate object. Both behaviours survive in one code path — the fail-closed capture bookkeeping and the quarantine scan.

0df6fb8 — the 30 s scenario bound. I checked whether this silences a defect, since "raise the timeout" is the oldest trick in the book:

  • The test-windows leg at 3a230f7 failed on exactly one test: a snapshot restore while other sessions are writing > every row a session was told it remembered is in the store or in a snapshot — never nowhere, logged at 5034 ms with no assertion text anywhere in the job log — a Bun default-timeout kill, not a conservation violation.
  • At 0df6fb8 the same test passes on Windows in 4117 ms, job totals 831 pass / 9 skip / 0 fail. It genuinely needs more than 5 s on a shared runner.
  • No assertion changed: the diff is }); → }, 30_000) plus a comment, and the file already uses that form at line 594, so it is a convention here rather than a one-off escape hatch. This is the #196 contention family.

Semantic re-verification on the merged tree (5700fc9, and again after the update). All four withhold sites are still isInjectable (src/portable.ts:377, src/index.ts:467,514,890) and #197's durable threading is intact (src/memory.ts:403,416). I re-ran the mutations that used to prove my round-2 findings:

Mutation Result
findStaleOpen back to isActive 2 fails — both decay … preserves the human queue cases
quarantineCandidate neutered in the resolved capture hunk 1 fail — a suspicious mined candidate keeps provenance but is withheld from the frontier (same single pin before and after the merge, so the resolution is not just compiling)

Gates on the integrated tree: typecheck clean, biome exit 0 at 408 warnings, unit 804 pass / 11 skip / 0 fail, real-host e2e 11 pass / 0 fail.

Merged as 7bb1750; final main (bf9f4d2, 0.14.26 → 0.15.0, npm latest verified from the packument) measured by me locally: typecheck clean, lint 408, unit 829 pass / 11 skip / 0 fail, e2e 11 pass. Queue is empty.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1: Write-side threat scan for capture/import paths — quarantine tag instead of injection

2 participants