feat(7730): prior art and preferences speak only past a cue-swap gate, at most two lines
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / Python tests (push) Failing after 1m35s
CI & Build / integration (push) Successful in 2m1s
CI & Build / Build & push image (push) Skipped

A record or preference found by resemblance alone is shown only when the
message's score beats all but a set share (default 10%) of the user's own
recent cues on that surface and project. The comparison set is the
best_available_score already logged per call, so the bar rises with the
store by construction and a fixed floor no longer decides. Too few cues to
judge by is silence; the searches still run and calibrate the gate.

- cue_gate: conformal bar, per (user, surface, project) with a user-wide
  fallback, cached five minutes; readout for Settings.
- Notes arms (auto_inject, write_path) abstain unless the top line passes,
  show at most two lines, and hold slots to the same bar and cap.
- Rule arms hold preference lines to the gate; rules are not gated.
- retrieval_logs gains gate_bar and gate_kept (migration 0131).
- Turns the harness wrote are refused server-side as well as in the plugin.
- Settings: the rate field and a per-surface readout of bar and how often
  each surface spoke; GET /api/retrieval/gate.
- Replay test: on unrelated cues a fixed bar tuned to 5% on a 32-record
  store fires ~97% on 2,048 records; the gate stays near 10% at both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 21:05:02 -05:00
co-authored by Claude Opus 5.5
parent 05831149b8
commit 4a65f5ddfd
13 changed files with 771 additions and 19 deletions
@@ -152,6 +152,8 @@ def _build_payload(
suppressed: int | None = None,
best_available: float | None = None,
best_available_id: int | None = None,
gate_bar: float | None = None,
gate_kept: int | None = None,
) -> dict:
"""Reduce a retrieval call to a flat, JSON-safe RetrievalLog payload.
@@ -200,6 +202,14 @@ def _build_payload(
),
"result_ids": items,
"duration_ms": (round(duration_ms, 2) if duration_ms is not None else None),
# The cue-swap gate, on a gated surface: the bar a line had to reach
# and how many did. Null bar with a count means the gate could not
# judge yet and nothing spoke; both null means the surface is ungated.
"gate_bar": (
None if gate_bar is None or gate_bar == float("-inf")
else round(float(gate_bar), 5)
),
"gate_kept": None if gate_kept is None else int(gate_kept),
}
@@ -239,6 +249,8 @@ def record_retrieval(
best_available: float | None = None,
best_available_id: int | None = None,
searched: bool = True,
gate_bar: float | None = None,
gate_kept: int | None = None,
) -> None:
"""Fire-and-forget: record one retrieval call.
@@ -292,6 +304,8 @@ def record_retrieval(
suppressed=suppressed,
best_available=best_available,
best_available_id=best_available_id,
gate_bar=gate_bar,
gate_kept=gate_kept,
)
except Exception:
logger.debug("retrieval telemetry payload build failed", exc_info=True)