Skip to content

CONTRACT: feat(ui-server,common): judge a tainted session's outgoing calls with extraction heuristics at admission (#4088) - #4095

Merged
schlessera merged 8 commits into
mainfrom
feat/4088-extraction-heuristics
Nov 16, 2026
Merged

schlessera merged 8 commits into
mainfrom
feat/4088-extraction-heuristics

Conversation

@schlessera

@schlessera schlessera commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Closes #4088

#4071 (the #3434 spike) has merged as 80e5d372f. This branch merged origin/main at c019c8fa5. The add/add conflict in docs/plans/extraction-classifier.md was resolved to main's version plus this PR's #4088 additions; main's copy is byte-identical to the spike tip, so nothing of the spike was lost. Every other spike file (evals/3434-extraction-classifier/*, experiments/3434-extraction-classifier.test.ts, docs/plans/README.md) is identical to main. The PR's diff against main is now only the 20 #4088 files.

What changed

A new governance policy setting, taint.classifier, is off by default. With heuristics, the host judges each outgoing call of a tainted session before it runs, using the deterministic #3434 heuristics. The seven signals are fingerprint overlap, taint host, encoded blob, volume, write-shaped destination, fan-out and method/tool class. The check sits on the bridge's per-call admission (inputSafety.begin), which every backend awaits with the call's full input. A block refuses the call, and its reason is the call's own tool result, for example "Refused: this Bash call contains text from health/checkup-log.md, and this session fetched a web page." An ask raises a per-use card that names the reason, for any call, including one to a host the session already contacted, which #3430 admits without a card today. Voice refuses instead of asking. An allow relaxes only the #3430 tainted-destination card. It covers only the hosts a readable call names (a WebFetch, or a visible curl/wget/gh read), and only while that call is in progress. An opaque or unattributable call in progress withholds it. The session state is bounded and in memory, keyed by session: shingle hashes of the files read, the hosts the tainting content named, and each site's stream of matched hashes. A session that this process did not observe from its first turn, or whose state outgrew a bound, never allows. It still asks and refuses.

Why this shape

  • Admission point. inputSafety.begin/result is the one place every backend (Claude hooks and canUseTool, Pi gate and worker RPC) hands the host the full input before the call runs, and the output after. turn-egress wraps the bridge it already owns, so the proxy (const narrowing), ui-sdk and the backends are unchanged. The relaxation goes through the existing taint.contacted predicate. The outward-host card (approveOutward) never consults the classifier.
  • Ask raises its own card at admission rather than at the proxy. A contacted host's connection may reuse a tunnel, and a taint.egress.allow host never reaches the ui-sdk: a tainted session's new destination is refused silently instead of asking the user #3430 card, so a proxy-side ask could be skipped. An approved card relaxes that readable call's hosts while it runs, so the user sees one card, not two. Cards are kind: "command", so they are never remembered or auto-allowed.
  • Tool class from the command policy. The labelled set authors it per case. In production it comes from prepareOutwardPlan(...).classification. A curl/wget write is scored as the set scores it (a writing method to a named host, so a strong copy is blocked), but it never relaxes. gh api -f is a GitHub write in production and keeps its outward card. This is noted in the plan doc.
  • Incomplete state never allows. This is the proportionate answer to a restart or the setting turned on mid-session: only the relaxation is withheld, only for that session.

Proof

bun run check:pr --base origin/main   # exit 0, receipt below

After merging main (c019c8fa5, base 80e5d372f): bun run typecheck with an 8 GiB heap, bun run build and bun run api-report are clean, with no report change. The admission, labelled-set, tainted-destination-ask, turn-egress, shell-taint-proxy, provider-relay-taint and ingestion-taint suites give 51 pass and 0 fail. The policy tests give 15 + 12 pass, and experiments/3434-extraction-classifier.test.ts gives 17 pass. check:pr exits 0 (receipt below, at the new head). The hosted heavy-feedback run below tested the pre-merge head 4995b6931; the merge brings in only main's commits, with the #4088 files unchanged.

Labelled set through the production classifier (packages/ui-server/tests/extraction-classifier-labelled.test.ts): all 86 calls match the recorded offline heuristics run (results-offline-2026-11-15.json) call by call. That gives held-out 1 leak and 11 benign cards, 0 benign refused, and the realistic session asks on 7 of 22. A ranking change fails LABELLED_SET_RANKING_CHANGED with the per-call diff.

Real turn proxy on loopback (packages/ui-server/tests/extraction-admission.test.ts, 9 tests). They cover the admit, ask and refuse paths, deny/allowlist, voice, the opaque withhold, the outward card, an incomplete state, and the no-conversation-output check.

Failing first. The new admission tests against the original turn-egress.ts (the classifier not wired in): 7 of 9 fail, each on its named assertion, including AC1:

error: CLASSIFIER_ALLOW_SKIPS_TAINT_CARD
(fail) with the setting on, a tainted session's clean WebFetch to a new host is admitted without the #3430 card; off, it still asks
error: CLASSIFIER_BLOCK_REFUSES
error: CLASSIFIER_CLEAN_FETCH_ADMITTED
error: CLASSIFIER_RELAXES_ONCE_OPAQUE_ENDS
error: CLASSIFIER_OUTWARD_CARD_IS_THE_HOSTS
error: CLASSIFIER_VOICE_REFUSES_WHERE_ASKED
 2 pass / 7 fail

Mutations. Each was restored afterwards; all 9 pass again.

  • Letting allow relax an outward card (approveOutward: if (calls.covers(host) || extraction?.relaxes(host))):
    error: CLASSIFIER_ALLOW_KEEPS_OUTWARD_CARD, 8 pass / 1 fail.
  • Dropping the opaque-call withhold (removing if (active.some(call => call.withholds)) return false; in relaxes):
    error: CLASSIFIER_OPAQUE_WITHHOLDS_RELAXATION, 8 pass / 1 fail. A first version of this test let the mutation survive, because its opaque call named the host itself. The test now uses a script file that names nothing, which only the withhold catches.
  • Relaxing non-readable calls (dropping readable && from relaxable):
    error: CLASSIFIER_CURL_WRITE_KEEPS_TAINT_CARD, 8 pass / 1 fail.

Neighbouring suites. The new tests, tainted-destination-ask, turn-egress, shell-taint-proxy, provider-relay-taint, reference-egress, session-taint, ingestion-taint and outward-governance give 46 pass and 2 fail. The 2 failures are turn-egress-composition's governed claude/pi turns, which need bubblewrap user namespaces (unshare: write failed /proc/self/uid_map) and are unavailable on this host. They are environment-only. The policy tests (core/governance-policy, core/policy-cli, common/taint-trust) pass. tsc --noEmit and bun run build are clean, and the API report has been regenerated.

Provider history. Nothing on the provider-facing path changed: no tool, system prompt, append or transcript change. The only verdict text is a refusal's tool result. CLASSIFIER_EMITS_NOTHING and CLASSIFIER_REPORTS_NO_ACTIVITY assert that judging and refusing emit no message or activity. The keyless provider-history guards cannot start a worker on this host, even outside the command sandbox (bwrap: No permissions to create a new namespace), so they ran in hosted draft heavy feedback instead.

Hosted draft heavy feedback, run 43882820934: success, jobs checked out head 4995b6931fcb415c458a7930e352a2d373366326. Every selected job passed (verify, runtime, runtime_host, pack, browser 1–3, unit 1–4, layout 1–2, endurance, captures); only supersede was skipped, as designed. The provider-history guard ran in unit (2) and unit (3), all passing: ui-backend-claude/tests/provider-history.test.ts (16 tests, e.g. Claude stable system stays byte-identical on resume, Claude tools stay identical typed -> voice -> typed (#2048)), ui-backend-pi/tests/provider-history.test.ts (13 tests), and both provider-history-apify.test.ts files. Both shards end with 0 fail; the only (fail) lines in their logs are the suite's intentional timeout controls. This is feedback, not merge proof.

{"version":1,"kind":"brain-check-pr-receipt","head":"963a721320b54990e4a02bf769e91e8c402c24e9","base":"origin/main","mode":"focused","startedAt":"2026-11-16T17:50:19.093Z","finishedAt":"2026-11-16T17:51:48.439Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12498.565969000001},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":105.43713900000148},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":67.51417500000025},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":22.629290000000765},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":76635.713487}]}

Collisions (bun scripts/collisions.ts --json --pr 4095, rerun at head c019c8fa5): no path collisions. textual: #3622 in docs/integration-contract/package-api.md (both add a section; whichever lands second merges). closure only (shared test/build closure, not shared files): #3054, #3056, #3059, #3069, #3581, #4002, #4036, #4060, #4068, #4070, #4074, #4075, #4080, #4096, #4099.

Proportionate containment (new guard)

  • Trigger, and what it does not cover: only with taint.classifier: heuristics, only on a tainted session, and only for calls admitted through inputSafety.begin. It does not cover the known evasions listed in the plan (paraphrase, opaque transformation, one-bit beacons, leaks to an approved host, unknown encodings, cross-site trickles, the relay), shell reads (cat) of brain files, which are not fingerprinted, or a backend bridge with no admission collector, where nothing is classified or relaxed.
  • What it restricts: one call, the narrowest scope. block refuses only that call; the turn and session continue. ask adds one per-use card.
  • Restricted mode before refusing: strong overlap on an outward action, or to a destination that is not new and not write-shaped, asks instead of blocking. Only a strong copy leaving for a new, write-shaped or writing destination is refused.
  • How it clears: per call. The next call is judged afresh. An incomplete state, from a restart or the setting turned on mid-session, only withholds allow, and a new session clears it. No owner action is needed.
  • Where the cause is recorded: the refusal text is the call's tool result, naming the evidence and the taint source, and the card names the reason. Classifier state is deliberately not recorded (provider-history and internal-state rules). The proxy's own records are unchanged.
  • Scope isolation test: CLASSIFIER_ALLOW_ONLY_NAMED_HOSTS, CLASSIFIER_ALLOW_ENDS_WITH_CALL, CLASSIFIER_INCOMPLETE_STATE_NEVER_ALLOWS, and the turn continuing after CLASSIFIER_BLOCK_REFUSES: the later WebFetch call in that test is judged normally.

Checklist

  • Focused local preflight/behavioral receipts passed; hosted draft heavy feedback (run 43882820934) passed on this head. Ready-candidate proof runs at confirmation.
  • Acceptance criteria are met, including the provider-history guard (hosted run 43882820934).
  • The PR and ui-server: classify a tainted session's outgoing calls with deterministic extraction heuristics at admission #4088 carry milestone 0.45.0.
  • Changeset: .changeset/extraction-heuristics-admission.md (common, brain, ui-server: minor).
  • No personal data (Odysseus fixtures; leakage gate passed).
  • The contract index, cli.md, package-api.md, supported-inputs.md and the API report are updated in the CONTRACT: commit.
  • Docs: the decision record governed-writable-workers.md#extraction-heuristics, hosting/agent-workers.md, the plan doc, and citations shifted by this change repaired.
  • Proportionate-containment checklist answered above.
  • Provider history stays append-only: the provider-history guard passed in hosted run 43882820934 (it cannot run on this host); nothing on the provider path changed.

Anything left open

🤖 Generated with Claude Code

schlessera and others added 6 commits November 15, 2026 22:08
)

Adds the #3434 measurement harness: the request schema the classifier
scores, seven deterministic signals scored alone and combined, the
policy combination that lets an allow relax only the #3430 card, the
Jev middle-band judge with its spend ledger, and a labelled set of 86
Odysseus calls over the fixture corpus, with adversarial cases per
heuristic. Keyless experiment-tier tests use a deterministic judge stub.

The plan records the schema, signals and the offline heuristics table:
fingerprint overlap alone reaches 0.54 held-out extraction recall, so
the early-stop condition is not met and the live Jev leg is required.

Refs #3434

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #3434

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #3434

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dation (#3434)

jev-1.13.0 answered all 52 ambiguous-band requests for $0.00152, p50
155 ms and p95 194 ms, with identical answers across three repetitions.
On held-out it cuts benign cards from 11 to 3 of 33 with no added leak,
but no held-out extraction call reached its band, and it labelled the
one tuning beacon benign below the 0.9 floor.

The plan now recommends heuristics first, then Jev for the band, each
off by default until the band is requalified, and links the
implementation tasks #4088, #4089 and #4090 under #3428. A replay test
pins the recorded run's table.

Closes #3434

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…calls with extraction heuristics at admission (#4088)

Add the `taint.classifier` governance policy setting, `off` by default.
With `heuristics`, the turn's egress wraps the bridge's per-call admission
(`inputSafety.begin`), which every backend awaits with the call's full input,
and runs the deterministic #3434 heuristics on each call a tainted session
makes:

- block refuses the call; the reason is its tool result, the only verdict
  text the model sees;
- ask raises a per-use card naming the reason, for any call, including one
  to a contacted host; voice refuses instead;
- allow relaxes only the #3430 tainted-destination card, only for the hosts
  a readable call names, and only while that call is in progress. An opaque
  or unattributable call in progress withholds it.

Session state (shingle hashes of the files read, the hosts the tainting
content named, each site's earlier payloads) is bounded in-memory host
state. A session not observed from its first turn, or that outgrew a bound,
never allows. Deny, allowlist mode, budgets and outward cards never consult
the classifier.

The labelled #3434 set run through the production classifier reproduces the
recorded heuristics run call by call: held-out 1 leak and 11 benign cards,
the realistic session 7 of 22.

Contract: additive `taint.classifier` in the policy schema, its resolved
value in `brain policy check --json` `effective.taint`, and the ui-server API
report; documented in the contract index, cli.md, package-api.md and
supported-inputs.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 16, 2026
@schlessera schlessera added type: feat A new capability or a change in user-visible behaviour. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. security Auth, isolation, egress, secrets, or anything in the threat model. labels Nov 16, 2026
…heuristics

# Conflicts:
#	docs/plans/extraction-classifier.md
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 17:54
@schlessera
schlessera merged commit a7169cb into main Nov 16, 2026
51 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. security Auth, isolation, egress, secrets, or anything in the threat model. type: feat A new capability or a change in user-visible behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: classify a tainted session's outgoing calls with deterministic extraction heuristics at admission

1 participant