Skip to content

feat(flow): verdict tiers, entity-scoped frames and shadow mode by default - #2425

Open
abrichr wants to merge 6 commits into
mainfrom
fix/verdict-tiers
Open

abrichr wants to merge 6 commits into
mainfrom
fix/verdict-tiers

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

What this changes

A whole-database frame stops a correct write when any row anywhere moves. In
the false-stop study (openadapt-internal evidence/false-stops-2026-11),
rows that move with no harm stopped correct writes on three apps: scheduler
and task-queue rows, totals the app recomputes after a save, and a
notification for each watcher of a record. This pull request separates those
from real harm, without letting a planted fault through.

It builds on #2413 (learn per-request bookkeeping from read-only requests)
and #2377 (two rechecks that held correct writes UNCERTAIN). Both are merged
into this branch, not rebased, so review the diff against them.

Three verdict tiers

  • Hard (REFUTED, blocks): the target missing, a wrong value, a
    duplicate, a row the write doesn't declare that changed or was removed in a
    business-entity table (another user's row and an unexcused column of the
    acting user's row included), a late revert, a lost update, any removed row,
    and anything no row comparison explains.
  • Logged (CONFIRMED): the write holds, and rows were added or changed
    only outside the entity tables. They are listed in the frame evidence as
    side_effects (table, change, row count, column names; no keys or
    values) and offered to openadapt-flow learn as candidate excuses.
  • Retry: before judging, the verifier waits for the declared records to
    become visible (0.5, 1, 2, 4 s; 8 s budget; OPENADAPT_VERIFY_RETRY_S).
    It reads only through database verifiers, decides nothing, and the full
    judge runs afterwards. Settling ignores motion outside the entity tables.

The outcome contract doesn't change. A logged pass is CONFIRMED, so a harm
that slips through it is counted as a silent pass by anything that grades
the outcome. WriteResult gains tier, side_effects, enforcement and
blocks.

Entity-scoped frames

frame.database.entity_tables is opt-in. Unset, every table is judged as
before. The tables the frame already names (views, judged_by,
new_row_fields, side records, learned excuses, owner tables, profile rules)
always count as entities. openadapt-flow learn entities derives the list
from the setup: each kind's main table, every table a contract's read
selects from, and the acting user's table (derived from the manifest's actor
parameters by foreign key; with none, no scope is proposed). No app is
named in engine code. On a frame that diffs the whole database, a generated
read's own check columns (pin__*, empty__*) are no longer compared on
undeclared rows. One flipped with the clock on rows nobody wrote.

The safety bar

runtime/effects/admission.py admits a relaxation only when, under it,
planted wrong-row, wrong-value, duplicate, sibling-edit, late-revert and
lost-update faults, plus the two actor-table attacks, all ran and were all
caught. It also requires that every case caught before still runs. learn entities apply writes a scope only with such results, run against the
staged scope (the proposal digest must match), and writes every contract or
none.

Shadow mode by default

A new contract is in shadow: its verdict is computed and recorded in full,
but WriteResult.blocks is false. After N clean checks in a row (20 to 50,
default 30, OPENADAPT_GATE_CLEAN_RUNS), gating is offered. A person turns
it on with openadapt-flow gate enable. gate label marks a stop as a real
catch, which keeps the run, or as a false stop. OPENADAPT_ENFORCEMENT=gating
restores the old behaviour everywhere. The ledger still holds refuted
attempts, so a retry is never sent silently.

Docs: packages/flow/docs/VERDICT_TIERS.md, the command map, a
CAPABILITIES row and llms-full.txt.

Not in this pull request

  • Callers that stop an agent on a verdict don't read blocks yet. Their
    stopping is unchanged. Wiring them is a separate change.
  • A null task value bound in a hand-written contract's query is still
    refused at begin_write. That refusal is right for an arbitrary SQL
    query, so the fix belongs in the generator's null-safe template.
  • Another user's unattributed edit to a record in an entity table still
    stops the write.
  • A harm confined to a non-entity table is logged, not stopped.

Tests

tests/test_verdict_tiers.py (SQLite, real reads) checks the following:

  • With no scope, background rows refute. With a scope, the write passes as
    logged, with names only.
  • Each safety-bar fault still refutes under a scope: a sibling record,
    another user's row, another column of the actor's row, a record read
    through, a removed side-table row, a duplicate and a wrong value.
  • A derived check column doesn't move the frame.
  • Settling holds under a queue that never stops.
  • The retry wait backs off and stays within its budget, and never reads
    through an API.
  • Shadow mode: N clean checks, labels, and enable refused until gating is
    offered.
  • Logged side effects reach the learner.
  • The admission refuses any missed or unrun class.
  • learn entities derives, stages and applies only on matching, all-caught
    results.

The existing frame, learned-excuse, verifier, verify-run, recheck, ledger,
receipt, shadow and CLI-census suites pass, with test_verifier_api
updated for the new WriteResult field.

Real-app replay on the false-stop harness is pending and will be reported on
this pull request.

A write begun with ledger=None was rechecked against the default ledger,
found no attempt there, and was held UNCERTAIN. A recheck that slept until
its due time could wake a few milliseconds before the wall clock reached
it, read the time as not yet due, and hold the write UNCERTAIN.
openadapt-flow learn probe reads the whole-database frame, sends only GET
and HEAD requests as the agent, and reads again. A changed row of the
acting user that moved (a last-login or token-use time) becomes a
frame.learned excuse with source read_only_probe, with no approval. Added
rows, rows of other users and rows no user owns are not admitted.
Rows that move with no harm (a scheduler, a task queue, totals the app
recomputes, notifications) stopped correct writes under the whole-database
frame. With frame.database.entity_tables, rows added or changed outside the
business-entity tables are logged side effects on a CONFIRMED result and
candidates for the learner; removed rows, entity-table rows the write
doesn't declare, another user's row and an unexcused column of the actor's
row still refute. learn entities derives the scope from the setup and
applies it only when planted faults are all still caught under it
(runtime/effects/admission.py). The verifier waits for declared records
with backoff before judging, settling ignores motion outside the scope, and
a generated read's check columns are not compared on undeclared rows. New
contracts start in shadow (WriteResult.blocks false) until N clean checks
in a row, then a person can turn gating on (openadapt-flow gate).
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 7c624aa

Protected-path review of the unique work versus 0fc06e298 (the merged #2413/#2377 stack). I did not merge. Neither this review nor CI is a measurement claim; the request says the paired replay is still running.

  1. Side-effect split. A collateral change becomes a logged side effect only when all of these hold: the surface is in the database hashers, the row was seen, the change is added or changed, it is not on_target / other_on_target / audit_only, and table_name(surface) is outside the entity scope. Removed rows, unread tables (not in hashers), entity-table rows, and on-target / other-on-target / audit-only changes stay in collateral and still refute. Tests cover a sibling entity edit, another user's actor-table row, an unexcused actor column, a location table, a duplicate, a wrong value, and a delete outside the scope.

  2. Entity scope. entity_scope always unions the frame's own named tables (views, judged_by, new_row_fields, side records, learned excuse tables, attribution owners, profile rules). learn entities will not propose a scope without the acting user's table, includes it in entity_tables, and binds proposal_sha256 over entity_tables and actor_table.

  3. Retry wait. await_effects only waits until declared record effects are visible, on database verifier kinds (surfaces, sql, sqlite); any other kind, or any failure, skips or ends the wait. The judge then reads the store again in full. Settling ignores motion outside the scope between post-save snapshots, but those tables are still diffed against the baseline (and logged, not stopped, when they pass the split).

  4. Shadow mode. enforcement.observe records the already-computed outcome and returns the mode. It does not change outcome. The ledger is still attached on WriteResult after observe. blocks is true only when the result is not CONFIRMED and enforcement == "gating". A new contract is shadow until N clean checks and a person enables gating.

  5. Admission. learn entities apply refuses a digest mismatch, then admit(..., required=SAFETY_BAR + ACTOR_ATTACKS) refuses a required class that was not run, a case that passed under the relaxation, and (when before is supplied) a case caught before that was not rerun.

Residual: at judge time, entity_scope does not itself re-derive the actor table. A later hand edit of entity_tables that drops it would let actor-table harms be logged as side effects. The propose/apply path does not allow that, and the CAPABILITIES row states the remaining product limits (an unattributed entity-table edit still stops; a harm confined to a non-entity table is logged, not stopped).

This branch has not been deployed

No deployments
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