Skip to content

Decision backends: typed, calibrated judgments as an optional seam - #354

Merged
sathish-mg merged 2 commits into
mainfrom
feat/decision-backend
Sep 25, 2026
Merged

sathish-mg merged 2 commits into
mainfrom
feat/decision-backend

Conversation

@sathish-mg

Copy link
Copy Markdown
Contributor

Decision backends: typed, calibrated judgments as an optional seam

Contract: docs/decision-model-proposal.md. Named decision: ARCHITECTURE.md §10
"A decision model may score and order; only code omits, gates, approves or applies".

What a decision backend is. A System One model (TypeSafe Jev and the eleven
gateways/clones that speak its POST /v1/systemone shape) takes a state plus
named noul / choice / score questions and returns typed answers with
calibrated probabilities — no text, one parallel evaluation. That is the shape of
every judgment Areev used to make with a constant or a keyword list.

The four rules. (1) A model scores and orders; only code omits, gates,
approves or applies. (2) An uncalibrated backend (llm: emulation) may reorder,
never omit. (3) Fail open to the deterministic rule — except anonymization, which
fails safe (DEC-E008 stops a chain). (4) Every judgment is attributable
(provider, model, calibrated, latency) in the recall explanation, the run journal,
the loop's judged_by, areev decide output and GET /api/config.

Nothing is default-on. With no --decide / $AREEV_DECIDE, every path is
byte-identical to 1.9.5 (pinned by tests in every crate touched). The keyless
floor and the conformance suite do not move. No new dependency.

Measured (crates/areev-bench/RESULTS.md §9)

Full LoCoMo retrieval, 1,982 questions, lexical-floor recall, Jev via OpenRouter
(typesafe/jev-1.13-20260917, calibrated) installed as the reranker:

arm hit@1 hit@5 hit@10 MRR@10
baseline (fusion order) 18.6% 33.4% 40.7% 0.250
decision reranker 51.8% 63.5% 65.3% 0.567
oracle positive control 66.3% 66.3% 66.3% 0.663

1,972 requests, $0.61, 242 s wall at 4 workers. The oracle reaching the pool ceiling
exactly proves the rerank path reaches the metric before any real number is quoted.

Phases in this PR

  • 0 — plumbing: SearchHit.score is the real normalized fused score (was 1.0);
    MCP areev_search rows and binding search rows gain score; recall deadline
    threaded everywhere (--recall-deadline-ms); CommandRerank / --rerank-cmd.
  • 1 — the seam: areev_core::decide (pure types, DEC-E001…E008),
    areev_llm::decide adapters (typesafe: openrouter: vercel: cloudflare:
    openjev: systemone:<url> llm:<spec> --decide-cmd), the ordered chain,
    PseudonymizingDecider; surfaces: global --decide* flags, areev decide,
    MCP env, Python set_decider/decide, Node setDecider/decide,
    /api/config.
  • 2 — reranker + measurement: areev_store::DecisionRerank (one request per
    recall, content-hash LRU), conformance case on both backends,
    decide_calibrate bench, LoCoMo A/B with oracle control.
  • 3 — context assembly: intent choice replaces the keyword lists; per-candidate
    relevance score + verbatim noul feed the allocator (calibrated only may omit
    / prefer Full); ASSEMBLE tier drops warn CAL-W019; the Claude Code recall hook
    uses it under 1500 ms. Rendering unchanged (render_parity green).
  • 4 — the runtime: decision node (executor_uri: "areev://decide", journaled as
    a Tool execution, edges branch in the frozen grammar, RUN-E030 without a
    backend), decision-guided fold (index-layer prune before the summarizer),
    tool-offer narrowing; manifest pins decider; run start/resume and
    trigger run wired; packs may carry a decision node (no pin, no warning).
  • 5 — the loop: dependency-free areev_loop::DecideBackend + LoopDecider
    bridge; GROUND/VERIFY routing number from a calibrated noul; near-duplicate
    and non-seeded contradiction sweeps; tool-cause classification; drafts only,
    judged_by never auto-applies; LOP-E051.

Gate

cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings,
cargo doc, both binding suites, conformance on Turso + Postgres, perf gates,
repo_stats.py --check, check_versions.py. Docs moved with every surface
(cookbook §27, mcp-reference, cal-reference, run.md, loop.md, triggers.md,
pack.md, security-model, deployment-profile, ERROR_CODES, CHANGELOG Unreleased).

Follow-ups (deliberately not in this PR)

  • min_score in ASSEMBLE saved queries now really filters (scores were all 1.0
    before); the thresholds in queries.rs were never tuned against real scores.
  • Decision could carry the provider-reported usage.cost.
  • MCP areev_record_tool_call has no free-text failure_detail, so the loop's
    tool-cause classifier rarely fires from MCP.
  • Pre-existing: timeline mode does not filter retracted grains; census counts can
    disagree with the rendered text; a duplicated resolve_db block in the CLI runs
    before anonymize scan|test.
  • Node addon: on this laptop's toolchain the stripped release build fails to load
    (mis-aligned LINKEDIT string pool); build with
    CARGO_PROFILE_RELEASE_STRIP=none locally. CI's toolchain is unaffected so far.

Not a release: no version bump, no tag.

…tional seam)

The contract every phase of the decision-backend work implements against:
the areev_llm::decide seam, the provider chain and spec grammar, the DEC
error domain, the eighteen opt-in plug-in points, surfaces per crate, and
the phase/ownership plan.
A System One model (TypeSafe Jev and every gateway/clone that speaks its
POST /v1/systemone shape) takes a `state` plus named noul/choice/score
questions and returns typed answers with calibrated probabilities. That is
the shape of every judgment Areev used to make with a constant or a
keyword list. This adds one provider-agnostic seam and plugs it, opt-in,
into the recall reranker, the context allocator, the run scheduler and the
loop engine. Contract: docs/decision-model-proposal.md. Named decision in
ARCHITECTURE.md §10.

Rules: a model scores and orders, only code omits/gates/approves/applies;
an uncalibrated backend may reorder, never omit; fail open to the
deterministic rule, anonymization fails safe (DEC-E008 stops a chain);
every judgment is attributable. Nothing is default-on: with no --decide /
$AREEV_DECIDE every path is byte-identical (test-pinned per crate). The
keyless floor and the conformance suite do not move. No new dependency.

Measured (crates/areev-bench/RESULTS.md §9): full LoCoMo retrieval with
Jev via OpenRouter as the reranker, hit@1 18.6% -> 51.8%, MRR@10
0.250 -> 0.567, oracle ceiling 66.3%; $0.61 per run.

Phase 0  real recall scores in SearchHit.score / MCP / bindings, recall
         deadline, CommandRerank (--rerank-cmd)
Phase 1  areev_core::decide (types, DEC-E001..E008), areev_llm::decide
         adapters + chain + PseudonymizingDecider; --decide* flags,
         `areev decide`, MCP env, py/js set_decider/decide, /api/config
Phase 2  areev_store::DecisionRerank, conformance case on both backends,
         decide_calibrate bench, LoCoMo A/B with oracle control
Phase 3  intent + per-candidate disclosure questions in areev-context and
         ASSEMBLE (CAL-W019), recall-hook under 1500 ms
Phase 4  decision node (areev://decide, RUN-E030), decision-guided fold,
         tool-offer narrowing; run start/resume + trigger run wired;
         packs may carry a decision node
Phase 5  areev_loop::DecideBackend + LoopDecider; GROUND/VERIFY number,
         duplicate/contradiction sweeps, tool-cause classification;
         drafts only, judged_by never auto-applies (LOP-E051)

Gate: cargo test --workspace (3,361), clippy -D warnings, cargo doc,
pytest (174), node --test (106), conformance Turso+Postgres, perf gates,
repo_stats --check, coverage --check (83.6%), check_versions. Docs moved
with every surface. Not a release: no version bump.
@sathish-mg
sathish-mg requested a review from a team as a code owner September 25, 2026 13:29
@sathish-mg
sathish-mg merged commit 8dca6e0 into main Sep 25, 2026
21 of 22 checks passed
@sathish-mg
sathish-mg deleted the feat/decision-backend branch September 25, 2026 16:35
neoneye pushed a commit to agent-memory-atlas-archive/AreevAI--areev that referenced this pull request Sep 25, 2026
…ide test budget; doc follow-ups

Two CI failures on main after AreevAI#354/AreevAI#355, neither in the code those PRs
changed, plus the follow-ups noted on AreevAI#353.

The egress broker gave back the memory it was lent only when its detached
accept thread next polled the stop flag (every 5 ms), not when the Broker
was dropped. An embedded memory's file lock is a process-wide fcntl record
lock that lives as long as any handle does, so a host that closed its handle
and immediately handed the file to another process — the Node binding's
`close()` followed by a CLI run on the same file, which is exactly the
binding's egress parity test (AreevAI#201) — could find it still locked on a slow
macOS runner. `Broker::drop` now takes the store out of the shared slot
itself; `serve_one` clones the store out of that slot for the length of one
upload, so an in-flight artifact keeps its own reference and the drop never
blocks on it. Pinned by
`dropping_the_broker_releases_the_bound_store_synchronously`, which fails
without the fix (verified) and needs no sleep or join to pass with it.

The CLI decision smoke test drove its toy Python `--decide-cmd` under the
default 2 s decision deadline; a cold interpreter on a shared Windows runner
was killed before it printed anything (DEC-E004) and the failure read as a
backend bug. The test now sets a generous budget: it measures the answers,
not interpreter start-up, and the default's tightness is pinned by the
deadline tests beside it.

Also: every rustdoc warning in the workspace (16: private intra-doc links,
unresolved links, a macro example fenced as Rust, an unescaped `<tag>` and
`[:port]`) is fixed, so `cargo doc` is clean; `docs/security-model.md` no
longer claims the store pins `search_path` per session and that transaction
pooling is unsafe — AreevAI#181 made every statement schema-qualified and the chaos
runner proves transaction-mode PgBouncer, so it now states the one real
condition (prepared-statement tracking) and points at the deployment
profile; the Python and Node binding docs and the quickstart mention the
paired layout's `meta_schema=` (AreevAI#353).
sathish-mg added a commit that referenced this pull request Sep 26, 2026
@sathish-mg sathish-mg mentioned this pull request Sep 26, 2026
8 tasks done
neoneye pushed a commit to agent-memory-atlas-archive/AreevAI--areev that referenced this pull request Sep 28, 2026
- min_score: the builtin ASSEMBLE queries drop their 0.4-0.55 floors.
  Recall scores are relative (rank-normalized RRF, or reranker min-max),
  so a fixed floor is a leg-count-dependent rank cut. Measured on LoCoMo
  with the new `min_score_sweep` bench (RESULTS.md §10): no-op keyless,
  4-7 points of gold-evidence recall lost at 0.5+ with a vector leg.
- Decision carries the provider-reported cost (`usage.cost` -> usd_micros,
  rounded up); decision nodes now charge it to the run's USD budget, and
  the reranker stats / benches sum it.
- record_tool_call takes `failure_detail` on MCP, CLI, Python and Node, so
  the loop's tool-cause classifier can fire from those surfaces.
- areev-context: one shared selection for single-pass, census and
  timeline. Timeline no longer renders retracted grains; census renders
  exactly what it counts.
- CLI: remove the duplicated resolve_db block that ran before
  `anonymize scan|test`.
- areev-js / areev-py: strip = false in release. rustc's rust-objcopy
  strip over an Xcode 27 ld-linked dylib is refused by macOS 27 dyld
  ("mis-aligned LINKEDIT string pool").
neoneye pushed a commit to agent-memory-atlas-archive/AreevAI--areev that referenced this pull request Sep 28, 2026
Version bump across all six sites (workspace, areev-js package.json +
Cargo.toml + generated index.js, areev-py pyproject, areev-sandbox), the
three lockfiles, the repo-stats artifacts that embed the version, and the
changelog. Ships the AreevAI#354 follow-ups: builtin ASSEMBLE queries drop
min_score, Decision carries the provider-reported cost, failure_detail on
record_tool_call, and the timeline/census/anonymize/dylib-strip fixes.
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.

1 participant