Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(quarantine): read the stored override only when the gate would hide a remote write, keeping put_page prepare inside its statement budget (#6259, #6007)
time-attack9c70e462a2fe
diff --git a/docs/architecture/key-files/commands-4-continued.md b/docs/architecture/key-files/commands-4-continued.mdindex a5f0026a33..22d7f57058 100644--- a/docs/architecture/key-files/commands-4-continued.md+++ b/docs/architecture/key-files/commands-4-continued.md@@ -9,7 +9,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/commands/publish.ts` — Deterministic brain page publisher (code+skill pair, zero LLM calls)-- `src/core/quarantine-override.ts` — #6259 (fix wave 12): the `quarantine_override` frontmatter key `gbrain quarantine clear --force` records: `{ binding, cleared_at }`, where `binding` is a sha256 over the classifier's inputs (title, type, body) as the gate canonicalizes them (`quarantineOverrideFor`). `assessImportSanity` (`import-screen.ts`) wraps its verdict in `withQuarantineOverride`, which removes the junk-pattern, literal and markup-flag outcomes while the binding is current (size outcomes stay). `importFromContent` calls `settleGateOwnedMarkers` (which also owns the #1699 remote strip of `quarantine`, `content_flag`, `embed_skip` and `atoms_scan_hash`): remote input loses any override and keeps the stored one only while the binding still holds (so a remote tag edit does not re-hide the page); trusted input keeps its own only while current; a current override also drops classifier markers the content still carries. Company-brain inspection refuses files carrying it (`hidden_input`). Doctor's quarantine row names `clear <slug> --force` and `content_sanity.disabled_patterns`.+- `src/core/quarantine-override.ts` — #6259 (fix wave 12): the `quarantine_override` frontmatter key `gbrain quarantine clear --force` records: `{ binding, cleared_at }`, where `binding` is a sha256 over the classifier's inputs (title, type, body) as the gate canonicalizes them (`quarantineOverrideFor`). `assessImportSanity` (`import-screen.ts`) wraps its verdict in `withQuarantineOverride`, which removes the junk-pattern, literal and markup-flag outcomes while the binding is current (size outcomes stay). `importFromContent` calls `settleGateOwnedMarkers` (which also owns the #1699 remote strip of `quarantine`, `content_flag`, `embed_skip` and `atoms_scan_hash`): remote input loses any override; trusted input keeps its own only while current, and a current override drops classifier markers the content still carries. For a remote write the classifier would hide or markup-flag, `carryStoredQuarantineOverride` reads the stored override and keeps it when it still binds (so a remote tag edit does not re-hide the page); a clean remote write reads nothing extra (#6007 statement budget). Company-brain inspection refuses files carrying it (`hidden_input`). Doctor's quarantine row names `clear <slug> --force` and `content_sanity.disabled_patterns`.- `src/commands/quarantine.ts` — `gbrain quarantine <list|clear|scan>` operator surface for the content-quality gate. `list [--json] [--include-flagged]` paginates `listPages` and reports quarantined (HIDDEN) pages, optionally also `content_flag` (FLAGGED, searchable) pages. `clear <slug> [--force] [--no-embed] [--json]` drops both markers and re-imports through the normal pipeline so the page re-chunks + re-embeds and becomes searchable; the gate re-runs on import so genuinely-junk pages re-quarantine (exit 1) unless `--force` sets `GBRAIN_NO_SANITY=1` for that one import. `scan [--limit N] [--apply] [--no-embed] [--json]` re-assesses already-ingested pages so junk predating the gate gets marked (unchanged content short-circuits normal sync, so it never re-assesses otherwise); dry-run uses the SAME effective `content_sanity` config thresholds `--apply` will use, idempotent (skips already-marked pages), `--apply` re-imports with `forceRechunk` to set markers + (for quarantine) drop chunks. Dispatched in `cli.ts`. Pinned by `test/quarantine-cli.test.ts`. #6259: `clear` reads one snapshot (page, tags, revision) and, on a managed brain, publishes through `submitPageMutation` with that `expected_revision` (a concurrent edit is a `revision_conflict`, a pending receipt is reported as pending); `--force` writes a `quarantine_override` (see `src/core/quarantine-override.ts`) instead of disabling the gate, never mutation `force`. `scan --apply` refuses `writer_coordinator_required` on a managed brain. It is a router (`QUARANTINE_SUBCOMMANDS`, `printUsage`). Tests: `test/quarantine-override.serial.test.ts`, `test/quarantine-cli.test.ts`.- `src/commands/recall.ts` — the `gbrain recall` CLI (facts-first by default; local engine or thin-client). A malformed `--limit` (not a positive safe integer, or missing) throws `invalid_params` from `parseFlags`, so the CLI exits 2 through `renderCliError`: the v1 envelope under `--json` with `why` and a `fix` that reruns the same argv with `--limit 50`, and the Error/Fix/Why lines otherwise (`test/recall-limit-envelope.test.ts`). Optional `--budget-policy facts_first|query_first` routes a one-shot read through the shared operation, forwarding fact filters and using remote recall on thin clients. Enum validation uses the shared operation definition; option order does not affect budget parsing. Only query-first with a nonblank query preserves numeric fractions until server packing; omitted/explicit facts-first keeps legacy integer parsing. The new option rejects watch/cursor/rollup/as-context combinations rather than silently ignoring them. Opt-in selector failures use stamped v1 errors; JSON mode emits structured local and remote errors on stdout with a nonzero exit, preserving remote read-error details without requiring a mutation receipt. Omitted-policy validation and fallback remain unchanged. Entity→text fallback: a bare positional without verb options is entity-first, but when the entity arm matches ZERO facts (and no `--grep`/`--supersessions`/`--session-id` narrows the read), the query retries as SQL-level fact-text grep with a stderr note. One predicate and note formatter are shared by the local path and thin-client mirror; explicit grep callers keep exact semantics. `--since` composes with entity and session in one query before LIMIT, on event time unless `--since-last-run`. Local `--grep` is passed to every engine arm (ILIKE with escaped metacharacters, before LIMIT); only `--supersessions` keeps the client-side filter. Pinned by `test/recall-grep-local-cli.test.ts`. Pinned by `test/facts-recall-since-composition.test.ts`, `test/recall-budget-policy-transports.test.ts`, `test/recall-budget-policy-thin-cli.test.ts`, and `test/recall-budget-policy-thin.serial.test.ts`.diff --git a/src/core/import-file.ts b/src/core/import-file.tsindex eac0ec739b..120670006c 100644--- a/src/core/import-file.ts+++ b/src/core/import-file.ts@@ -3,7 +3,7 @@ import { suffixedFrontmatterSlugHold } from './persistence/suffixed-slug.ts';import { maintenanceTransaction } from './persistence/attribution.ts';import { assertImportBase, sameCanonicalImport, sameContentAnyKeyOrder } from './page-state/import-guard.ts';import { stabilizeSafetyAssessments } from './persistence/reconcile-safety.ts';-import { settleGateOwnedMarkers } from './quarantine-override.ts';+import { carryStoredQuarantineOverride, settleGateOwnedMarkers } from './quarantine-override.ts';import { decideImportIdentity, collidingSlugOwner, fileOriginUri } from './import-identity.ts';import { readSourceFileSync } from './minions/source-filesystem.ts';import { readFileSync, statSync, lstatSync } from 'fs';@@ -354,7 +354,7 @@ export async function importFromContent(parsed.timeline = sanitizeText(parsed.timeline);// #1699 trust boundary: only the gate and trusted local callers set gate-owned markers (quarantine-override.ts).- await settleGateOwnedMarkers(engine, parsed, slug, sourceId, opts.remote === true);+ settleGateOwnedMarkers(parsed, opts.remote === true);// Vendor-neutral guardrail seam (observe-only, fail-open). Runs AFTER// parseMarkdown and the size guard, BEFORE content-sanity, hash compute,@@ -414,7 +414,7 @@ export async function importFromContent(// Disposition for the high-confidence junk path: quarantine (hide) by// default, or reject (throw → sync-failure) when the operator opts in.const junkDisposition = sanityCfg.junkDisposition;- const sanityResult = assessImportSanity(parsed, sanityCfg);+ const sanityResult = await carryStoredQuarantineOverride(engine, parsed, assessImportSanity(parsed, sanityCfg), { slug, sourceId, remote: opts.remote === true });if (!sanityDisabled && !sanityResult.shouldQuarantine && sanityResult.flag_reason !== 'oversized' && (parsed.frontmatter[EMBED_SKIP_KEY] as { reason?: unknown } | undefined)?.reason === 'oversized') {delete parsed.frontmatter[EMBED_SKIP_KEY];if ((parsed.frontmatter[CONTENT_FLAG_KEY] as { reason?: unknown } | undefined)?.reason === 'oversized') delete parsed.frontmatter[CONTENT_FLAG_KEY];diff --git a/src/core/quarantine-override.ts b/src/core/quarantine-override.tsindex 276438e41d..8348837d51 100644--- a/src/core/quarantine-override.ts+++ b/src/core/quarantine-override.ts@@ -71,28 +71,48 @@ export function hasCurrentQuarantineOverride(page: Bound & { frontmatter?: Recor* Trusted local sync/export round-trips keep them. Fail-closed: strip* whenever `remote` is true.*- * #6259: remote input also loses any `quarantine_override`, then keeps the- * stored one only when it still binds this content; trusted input keeps its- * own override only while it binds. A stale or malformed override is dropped,- * and a current one drops classifier markers the content still carries.+ * #6259: remote input also loses any `quarantine_override` (the gate may+ * carry the stored one forward, `carryStoredQuarantineOverride`); trusted+ * input keeps its own override only while it binds. A stale or malformed+ * override is dropped, and a current one drops classifier markers the content+ * still carries.*/-export async function settleGateOwnedMarkers(engine: Pick<BrainEngine, 'executeRaw'>, parsed: ParsedMarkdown,- slug: string, sourceId: string | undefined, remote: boolean): Promise<void> {+export function settleGateOwnedMarkers(parsed: ParsedMarkdown, remote: boolean): void {if (remote) {for (const key of [QUARANTINE_KEY, CONTENT_FLAG_KEY, EMBED_SKIP_KEY, ATOMS_SCAN_HASH_KEY, QUARANTINE_OVERRIDE_KEY]) delete parsed.frontmatter[key];- const [stored] = await engine.executeRaw<{ override: unknown }>(- `SELECT frontmatter->'${QUARANTINE_OVERRIDE_KEY}' AS override FROM pages WHERE source_id=$1 AND slug=$2 AND deleted_at IS NULL`, [sourceId ?? 'default', slug]);- const carried = overrideOf(stored?.override);- if (carried && carried.binding === quarantineOverrideBinding(parsed)) parsed.frontmatter[QUARANTINE_OVERRIDE_KEY] = carried;- } else if (Object.hasOwn(parsed.frontmatter, QUARANTINE_OVERRIDE_KEY) && !hasCurrentQuarantineOverride(parsed)) {- delete parsed.frontmatter[QUARANTINE_OVERRIDE_KEY];+ return;}- // A classifier marker the content still carries (a file written before the clear) goes with a current override.+ if (Object.hasOwn(parsed.frontmatter, QUARANTINE_OVERRIDE_KEY) && !hasCurrentQuarantineOverride(parsed)) delete parsed.frontmatter[QUARANTINE_OVERRIDE_KEY];+ dropClassifierMarkers(parsed);+}++/** A classifier marker the content still carries (a file written before the clear) goes with a current override. */+function dropClassifierMarkers(parsed: ParsedMarkdown): void {if (!hasCurrentQuarantineOverride(parsed)) return;delete parsed.frontmatter[QUARANTINE_KEY];if ((parsed.frontmatter[CONTENT_FLAG_KEY] as { reason?: unknown } | undefined)?.reason !== 'oversized') delete parsed.frontmatter[CONTENT_FLAG_KEY];}+/**+ * The gate verdict for a remote write: when the classifier would hide or+ * markup-flag the page, the stored override is carried forward if it still+ * binds this exact title, type and body, so a remote edit that leaves them+ * unchanged (a tag edit) does not re-hide a cleared page. The stored row is+ * read only on that path, so a clean remote write costs no extra statement+ * (#6007 statement budget).+ */+export async function carryStoredQuarantineOverride(engine: Pick<BrainEngine, 'executeRaw'>, parsed: ParsedMarkdown, result: ContentSanityResult,+ page: { slug: string; sourceId: string | undefined; remote: boolean }): Promise<ContentSanityResult> {+ if (!page.remote || !(result.shouldQuarantine || result.flag_reason === 'markup_heavy')) return result;+ const [stored] = await engine.executeRaw<{ override: unknown }>(+ `SELECT frontmatter->'${QUARANTINE_OVERRIDE_KEY}' AS override FROM pages WHERE source_id=$1 AND slug=$2 AND deleted_at IS NULL`, [page.sourceId ?? 'default', page.slug]);+ const carried = overrideOf(stored?.override);+ if (!carried || carried.binding !== quarantineOverrideBinding(parsed)) return result;+ parsed.frontmatter[QUARANTINE_OVERRIDE_KEY] = carried;+ dropClassifierMarkers(parsed);+ return withQuarantineOverride(result, parsed);+}+/** The gate verdict with the classifier's hide and markup-flag outcomes removed for an overridden page; size outcomes stay. */export function withQuarantineOverride(result: ContentSanityResult, page: Bound & { frontmatter?: Record<string, unknown> | null }): ContentSanityResult {if (!hasCurrentQuarantineOverride(page)) return result;