Skip to content

fix: gate the auto-capture regex fallback behind smart extraction and admission#934

Open
gorkem2020 wants to merge 2 commits into
CortexReach:masterfrom
gorkem2020:fix/autocapture-fallback-gating
Open

fix: gate the auto-capture regex fallback behind smart extraction and admission#934
gorkem2020 wants to merge 2 commits into
CortexReach:masterfrom
gorkem2020:fix/autocapture-fallback-gating

Conversation

@gorkem2020

Copy link
Copy Markdown
Contributor

Problem

When the smart extractor does not handle a turn, the auto-capture hook falls through to the legacy regex capture, which stores matching texts verbatim via bulkStore, with no distillation, no admission, and none of the extraction pipeline's safeguards. Two trigger paths:

  1. cumulativeCount < extractMinMessages: every content-rich first message of a session is eligible for raw capture before the extractor ever gets to judge it.
  2. The boundary-skip continuation after an extraction that persisted nothing.

Observed live: the first message of a fresh session (a roleplay opener) was stored verbatim as a confirmed fact row within seconds, bypassing the grounding and admission stack entirely. Sessions that open with a short greeting never hit this, which is why it stayed hidden; sessions that open with a rich message (how real users start conversations) hit it immediately.

Fix

  1. Below-threshold turns with smart extraction enabled: skip the regex fallback and defer. The cursor is rolled back for history-carrying sessions so the deferred text re-enters the next turn's extraction input (proven by regression test); ingress-fed sessions keep their accumulator semantics, where a rollback would wedge the minMessages window.
  2. When the fallback legitimately runs (smart extraction disabled, or the boundary-skip continuation): captures are routed through admission control when it is enabled, after the cheap dedup checks, with the audit persisted under provenance: "auto-capture-regex-fallback". Admission disabled keeps the legacy passthrough.

Tests

9 cases, 3 red-proven against the previous behavior: the below-threshold skip, deferred-text re-inclusion in the next extraction, gated boundary-skip continuation, plus pins for legacy behavior with smart extraction disabled.

Verification on a live gateway

The identical rich first message that previously produced a verbatim fact row now produces nothing; the follow-up turn's extraction input contained the deferred first-message content, produced correctly grounded candidates, and logged "skipping regex fallback" on the empty-outcome path.

Copy link
Copy Markdown

After #919 was merged, this PR now has merge conflicts with the latest main. Please rebase the branch onto the current main, resolve all conflicts, and push the updated head. We will review the updated revision once it is clean and mergeable.

…d admission

The agent_end auto-capture hook fell back to legacy regex-triggered
capture (raw text bulkStored verbatim as l0/l1/l2) whenever the smart
extractor did not handle the turn, bypassing the grounding filter and
admission control entirely. Live evidence: the first message of a fresh
session was stored verbatim as a confirmed row because
cumulativeCount < extractMinMessages meant the extractor never ran.

Two trigger paths, two gates:

- Below-threshold turns (minMessages not met) with smart extraction
  enabled no longer reach the fallback at all; the turn is deferred and
  debug-logged. For history-carrying sessions the slice cursor is
  rolled back so the next turn's extraction input re-includes the
  deferred texts (verified by regression test). Ingress-fed sessions
  keep their accumulator advance: their per-turn text is not
  recoverable next turn by design, and a rollback would keep the count
  below the threshold forever.
- When the fallback does run (smart extraction disabled, or the
  boundary-skip continuation), each capture now routes through the same
  AdmissionController evaluation as extraction candidates, scored under
  the smart register its legacy category maps to. Rejected captures are
  skipped with the audit reason logged; admitted captures persist the
  audit (tagged provenance auto-capture-regex-fallback) in their row
  metadata when auditMetadata is on. With admission control disabled
  behavior is unchanged, and with smart extraction disabled there is no
  controller instance to borrow, so that configuration keeps the legacy
  passthrough (pinned by test).

Red-proved: the below-threshold skip, the deferred-text re-inclusion,
and the gated boundary-skip continuation all fail against the previous
code and pass after it. Wire the suite into the local npm test chain
and the core-regression CI group.
…arios

Two single-turn scenarios in the branch regression suite asserted that
the regex fallback ran for a below-threshold turn with smart extraction
enabled. That is exactly the path the fallback gating closes; their real
purpose (recall-block and inbound-metadata stripping with zero LLM
calls) is unchanged, so pin the new deferral log instead.
@gorkem2020 gorkem2020 force-pushed the fix/autocapture-fallback-gating branch from 537b662 to cd3c56f Compare July 13, 2026 17:08
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