Skip to content
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
414 changes: 414 additions & 0 deletions BATCH-REPORT.md

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions adaptive_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
QueryViewIdentity,
QueryViewStore,
)
from .reasoning import temporal_trust_wire
from .tokens import count_tokens


Expand Down Expand Up @@ -1209,6 +1210,15 @@ def _persist_view(
)
if key in raw_trace
}
raw_trust = computation.get("temporal_trust")
if isinstance(raw_trust, Mapping):
raw_notes = raw_trust.get("notes")
trace["temporal_trust"] = temporal_trust_wire(
raw_trust.get("status"),
raw_trust.get("certified"),
raw_notes if isinstance(raw_notes, list) else (),
)
selected_refs = {item.citation for item in selected}
manifest = {
"closed_slots": sorted(state.slot_refs),
"open_slots": [],
Expand All @@ -1219,7 +1229,10 @@ def _persist_view(
"complete": True,
"requirements_digest": state.identity.requirements_digest,
"slot_refs": {
key: list(value) for key, value in sorted(state.slot_refs.items())
key: [
ref for ref in value if ref in selected_refs
]
for key, value in sorted(state.slot_refs.items())
},
"retrieval_rounds": len(state.rounds),
"candidate_refs": len(state.candidates),
Expand All @@ -1240,7 +1253,12 @@ def _persist_view(
return {"status": "building_elsewhere"}
except Exception as exc:
if token is not None:
self._query_views.mark_failed(token, str(exc))
try:
self._query_views.mark_failed(token, str(exc))
except Exception:
# Cleanup is best-effort and must never replace the build
# failure that selected this response contract.
pass
return {"status": "failed", "reason": str(exc)[:500]}

def finish(
Expand Down
4 changes: 3 additions & 1 deletion evidence_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,11 +1230,13 @@ def compile_evidence(
conflicted = len(validated) > 1

expected = request.get("expected_cardinality")
# Caller-evidence certification uses exact_ref uniqueness; engine finite-scan
# certification uses dedupe_key uniqueness. These are intentionally different surfaces.
finite_coverage = bool(
request["exhaustive"]
and isinstance(expected, int)
and expected > 0
and len(validated) == expected
and len({item["exact_ref"] for item in validated}) == expected
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
and not missing
and not rejections
)
Expand Down
60 changes: 54 additions & 6 deletions query_view_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"entities",
"evidence_dates",
"steps",
"temporal_trust",
})


Expand Down Expand Up @@ -1020,6 +1021,7 @@ def lookup(
if status == "failed":
return QueryViewLookup("failed", str(row["stale_reason"] or "build failed"))
version = int(row["current_version"])
generation = int(row["generation"])
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if version <= 0:
return QueryViewLookup("miss", "view has no published evidence version")
version_row = self._conn.execute(
Expand Down Expand Up @@ -1095,16 +1097,62 @@ def lookup(
)
if record_hit:
with self._write_transaction():
self._conn.execute(
"UPDATE lcm_query_views SET hit_count=hit_count+1, "
"promotion_status=CASE WHEN hit_count+1 >= 2 THEN 'promoted' "
"ELSE promotion_status END, updated_at=? "
"WHERE view_id=? AND status='ready' AND current_version=?",
(current_time, view_id, version),
confirmation_corpus = self.corpus_snapshot()
confirmation_stale = (
confirmation_corpus.generation != covered_generation
)
if confirmation_stale:
self._conn.execute(
"UPDATE lcm_query_views SET status='stale', "
"generation=generation+1, "
"stale_reason='corpus advanced during hit confirmation', "
"build_nonce='', lease_expires_at=NULL, updated_at=? "
"WHERE view_id=? AND status='ready' AND current_version=? "
"AND generation=?",
(current_time, view_id, version, generation),
)
hit_updated = False
else:
cur = self._conn.execute(
"UPDATE lcm_query_views SET hit_count=hit_count+1, "
"promotion_status=CASE WHEN hit_count+1 >= 2 THEN 'promoted' "
"ELSE promotion_status END, updated_at=? "
"WHERE view_id=? AND status='ready' AND current_version=? "
"AND generation=?",
(current_time, view_id, version, generation),
)
hit_updated = int(cur.rowcount or 0) == 1
row = self._conn.execute(
"SELECT * FROM lcm_query_views WHERE view_id=?", (view_id,)
).fetchone()
confirmed = (
hit_updated
and row is not None
and str(row["status"]) == "ready"
and int(row["current_version"]) == version
and int(row["generation"]) == generation
)
if not confirmed:
events, truncated = self.delta_events(
covered_generation, limit=delta_limit
)
current_view = (
self._shape_view(row, version_row, dependencies)
if row is not None and int(row["current_version"]) == version
else None
)
return QueryViewLookup(
"delta_required",
(
str(row["stale_reason"] or "")
if row is not None
else ""
)
or "view changed during hit confirmation",
current_view,
events,
truncated,
)
return QueryViewLookup(
"hit",
"exact typed intent and fresh positive/negative dependencies",
Expand Down
Loading