Skip to content

feat(verify): recheck an API read-back and the system's log after a window - #2472

Merged
abrichr merged 12 commits into
mainfrom
claude/nodb-recheck
Nov 22, 2026
Merged

abrichr merged 12 commits into
mainfrom
claude/nodb-recheck

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

What this does

Most customers give no database access, so the whole-database recheck in late_write.py can't run for them. This PR adds runtime/effects/api_recheck.py, a sibling module. It checks an API read-back and the system's own activity log again after a window the caller sets.

  • begin runs right after a verified first check. It takes the log checkpoint first and then reads the record, so an entry between the two reads lands in the window, not the baseline. The private state holds a salt and keyed MACs of the declared fields, the record's version and the write's own log entries. It never holds values. The receipt carries only state_sha256 and due_at (schedule).
  • recheck runs at or after the due time. It reads the record, then the log from the checkpoint. The local clock decides only when the recheck is due. Entry ids decide what is in the window, so a server clock that is off (Medplum ran about 1.5 s off) can't hide an entry.
  • Outcomes:
    • VERIFIED means only that, as of the recheck time, the read-back showed the same values and the log showed no unexplained change. It never means "persisted".
    • REFUTED: the record's values changed, the record is gone, or this caller's own log entry shows a change nothing declared accounts for.
    • NOT_CHECKED: another actor changed the record; a log entry has an unknown author or kind; the version moved while the values stayed the same (A to B to A); the log read didn't reach the checkpoint or hid entries; a read failed; the state doesn't match its receipt; the recheck ran early. A first result that wasn't VERIFIED also stays NOT_CHECKED, because a recheck can't raise a result.
  • RecheckResult.scope() gives plain evidence-scope fields: check level, basis (system_api, plus activity_log when a log was read), read-back time, recheck time, window, and a not-covered list. That list always includes "server-side async and outbound effects not observed".
  • VerifierReadback wraps a REST, FHIR or GraphQL verifier on main. It refuses a verifier that isn't an independent system-of-record read (screen read-backs, SQL), and a named version_path that resolves to nothing fails the read. The log half is the ActivityLog protocol, because main has no audit-log reader yet. The reader in feat(tx): verify API and SaaS writes by resource read-back and the system's own log #2437 (txplan/audit.py) fits it with a thin wrapper.

The module imports nothing from tx or txplan. No existing file changed except CAPABILITIES.md and llms-full.txt.

Tests

  • tests/test_api_recheck.py: 43 tests. Scripted record and log cases: an early recheck, a changed value, a deleted record, a change by another actor, A to B to A with and without a version, an extra write by this caller, late collateral and excused later writes, a log entry that lags, an entry stamped 1.5 s before the checkpoint, out-of-order stamps, an unreached checkpoint, hidden entries, read failures, a tampered state, an attempt to raise a non-verified first result, a JSON round trip of the state, refusal of screen-tier and non-API verifiers, a missing named version. Two tests run over real HTTP against MockMed's REST server through RestRecordVerifier: a late note edit is refuted, and a change to an undeclared field is not checked.
  • Import-layer, import-direction, import-surface, frame-read-budget and verifier-recheck suites pass.

…indow

A write checked against an API and an activity log is checked again after
a window the caller sets. The log checkpoint is taken before the first read,
the state keeps only keyed MACs, and entry ids, not clocks, place the window.
A change since the first read gives REFUTED or NOT_CHECKED, never VERIFIED;
a first result that wasn't VERIFIED is never raised.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: e74e09a

  1. Two unsuccessful reads can produce VERIFIED. The supplied adapter converts every REFUTED verdict to found=False, including a duplicate match. begin accepts that result as the baseline of an earlier verified write. If the recheck also observes found=False, the field and version checks agree and the recheck verifies. Require a positive, unambiguous observation to begin rechecking a create or update. Keep “record absent” distinct from “effect refuted for another reason.” If verified absence is a supported intent, bind it explicitly. Adapter · Baseline · Decision · Duplicate verdict with existing records

  2. The equality check can compare placeholders instead of observed values. A missing declared path becomes None just like an actual JSON null. A configured version that the response omits silently disables the version check. GraphQL also returns policy-redacted matched records, which can hold the same opaque marker for two different field values. Require evidence that each declared field and configured version was actually observed. For masked values, compute the comparison inside the trusted adapter before redaction or return NOT_CHECKED. Field projection · Version and field extraction · GraphQL evidence · Redaction policy

  3. The checked record is identified by the caller’s label, not by the API response. The state binds the target argument, but the adapter returns only selected fields and a version. When version_path is used, different resources with the same selected fields and per-resource version can compare equal. Bind the observed stable record ID to the original target and require that ID at recheck. Target binding · Returned evidence

  4. The evidence scope can claim an API check that never took place. VerifierReadback accepts any verifier with a confirmed verdict and one matched record. It does not inspect the adapter’s substrate or independence, and the result always labels the read system_api and a verified result system_of_record. A supported SQL verifier is already a concrete mismatch. Validate the adapter’s assurance and report its actual basis, or restrict the wrapper to independent API adapters. Adapter entry · Basis · Scope

  5. A configured activity log can silently disappear. If since() returns no result, the recheck takes the intentional API-only path and can verify. The code validates the record adapter's result but relies on the log adapter honoring its return annotation. When a log checkpoint was scheduled, require a valid LogRead or return NOT_CHECKED. Keep the API-only outcome for runs explicitly scheduled without a log. Log read and fallback

I reviewed all four changed files and the API adapter paths above. The independent focused test run was waiting for a shared CPU slot at posting. The conclusions above come from tracing the committed source.

These findings concern evidence shared by all adapters. The PR’s HTTP tests exercise MockMed REST; the activity-log cases use a scripted source. I found no held-out application or real activity-log adapter qualification in this PR.

…ad-back

A screen read-back or a database verifier can't carry the system_api basis,
and a named version path that resolves to nothing now fails the read instead
of silently dropping the A to B to A check.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 46b9274

The delta fixes the API adapter assurance check and the missing configured version. Four findings from the previous review remain open in whole or in part.

Earlier finding Disposition at this head
1. Two unsuccessful record reads can verify Open. All REFUTED verdicts still become found=False, and begin still accepts that as the baseline. If the second read returns the same result, both hashes agree and the result can be VERIFIED. The changed message only runs when the hashes differ. Require a positive, unambiguous baseline for a verified create or update. Baseline · Decision · Adapter
2. Missing or redacted observations can compare equal Partly fixed. A missing named version raises ReadFailed. Missing declared field paths still resolve to None, and redacted values from a verifier still enter the comparison. Require an observed value for each declared field and preserve the distinction between an observed null, an omitted field and masked evidence. Version check · Field lookup · Projection
3. The observed record ID is unbound Open. The target MAC still authenticates the caller’s label. The adapter returns selected fields and a version. If those fields omit the ID, two different records with matching values and the same per-record version remain indistinguishable. Bind the stable identity observed on both reads. State · Returned observation
4. Unsupported evidence can receive the API label Fixed in the adapter. It now requires REST, FHIR or GraphQL, an independent system of record, and tier 1 for the effect. The two public capability descriptions still say “any verifier adapter”; update them to the supported set. Guard · Capability table · Generated reference
5. A scheduled log can silently disappear Open. The supplied log can return None from since() and enter the same branch as an explicitly API-only schedule. Require a valid log result whenever the bound state includes a checkpoint; an unavailable result should yield NOT_CHECKED. Scheduled log and fallback

I reviewed the two changed files and the new test assertions. The new tests cover adapter eligibility, a missing configured version, and JSON round-tripping. I did not run another suite or use a live system.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 46b9274

Codex run on 46b9274 (read-only sandbox, blockers only). Codex found 13 blockers. Its findings follow verbatim:

  1. A missing record can be VERIFIED. If the record disappears after the first verified check but before begin() reads it, begin() saves found=False as the baseline. A second absent read and a quiet log then produce VERIFIED. Require a successful read of the identified record before scheduling, and bind the baseline to the evidence from the first verified check. api_recheck.py:311

  2. The recheck can verify the wrong record or log. I reproduced VERIFIED when a selector initially returned record 7 and later returned record 8 with the same declared fields and per-record version "1". The target MAC checks only the string the caller repeats. Likewise, substituting a quiet log stream with overlapping checkpoint IDs hid a caller mutation in the original stream. Bind and validate the observed record identity, source, log stream, and actor at both reads. api_recheck.py:403 · api_recheck.py:413

  3. VERIFIED does not require log evidence. Both log=None and an empty LogRead with logs=() produce VERIFIED. An unexplained caller deletion on another record leaves the target read-back unchanged in either case. Require a valid, checkpoint-complete log covering the relevant mutations before returning VERIFIED. Update the test that explicitly requires verification without a log. api_recheck.py:435 · test_api_recheck.py:278

  4. The adapter compares redacted or projected evidence as though it were the record. With the real GraphQL verifier, a declared note changed from A to B. Both verdicts exposed [redacted], and the recheck returned VERIFIED. With the real FHIR verifier, advancing meta.versionId from "1" to "3" also returned VERIFIED when its projection omitted meta. Compute comparison MACs inside the adapter before redaction, and require an observed server version or a demonstrably complete record for the version comparison. api_recheck.py:625 · graphql.py:298 · fhir.py:365

  5. Distinct observations can compare equal. A declared field omitted from both responses becomes None twice and verifies even though neither read showed it. A JSON version changing from integer 1 to string "1" also verifies because str(raw) erases the type. default=str creates the same collision for a Decimal field replaced by text. Distinguish missing fields from explicit nulls, preserve supported value types, and reject unsupported values. api_recheck.py:195 · api_recheck.py:555 · api_recheck.py:632

  6. An ambiguous selector is reported as a missing record. The shared FIELD_EQUALS judge returns REFUTED with both matched records when two rows satisfy the selector. VerifierReadback discards those rows and returns found=False, so an unchanged target can receive a deletion-style REFUTED. Preserve the distinction between confirmed absence, a changed value on the identified target, and an ambiguous match. Return NOT_CHECKED for the ambiguous match. api_recheck.py:618 · _common.py:707

  7. Event exemptions can conceal contradictory attribution. An on-target event with unknown author and kind returns VERIFIED if its ID appears in excused_event_ids. An ID in own_events even suppresses an entry explicitly attributed to another actor. A single string such as "12" also exempts the individual IDs "1" and "2". Require a collection of complete IDs and apply an exemption only when the observed attribution and operation agree with the write that accounts for it. api_recheck.py:461

  8. Mixed evidence gets the wrong verdict in both directions. I reproduced NOT_CHECKED when another actor edited the target and the caller independently deleted an unrelated record. The proven caller deletion requires REFUTED. Conversely, changed fields plus an on-target update by an unknown actor produced REFUTED despite unresolved attribution. Judge independently proven caller mutations first, then resolve whether the target change can be attributed from a complete log. api_recheck.py:488

  9. The private state contains the entire MAC key. For a single declared Boolean field, anyone who obtains the state can determine its value by comparing the two possible MACs. The same issue applies to enumerable target IDs and versions. Derive the MAC key from the per-state salt and a separately protected secret, as the existing database snapshot implementation does. api_recheck.py:201 · db_snapshot.py:160

  10. Checkpoint and failure paths disclose plaintext identifiers. A valid stream cursor containing Patient/7/_history/2 is copied verbatim into state["log"]. Separately, a REST failure includes the requested URL in its reason, which recheck() copies into the serializable result. Keep sensitive cursor material behind an opaque handle and emit value-free error codes for read failures. api_recheck.py:327 · api_recheck.py:425 · rest.py:255

  11. Malformed state can escape validation or leak into the schedule. A persisted window_s of 1e300 raises OverflowError before the receipt comparison can return NOT_CHECKED. schedule() also copies read_at without validation, so a damaged state with the salt in that slot publishes the salt. Validate types, bounds, digest formats, and timestamps before scheduling or date arithmetic. Reject invalid schedules and return NOT_CHECKED for invalid recheck state. api_recheck.py:336 · api_recheck.py:362

  12. The reported “as of” time precedes the observation. rechecked_at is captured before either source is read. A verifier that polls for several seconds can return evidence first observed after the time printed in the verdict. Record the actual record observation time and log boundary, or report the interval over which the two observations were made. api_recheck.py:395

  13. The privacy test can fail on a correct implementation. It searches serialized random hexadecimal salts and digests for the four-character substring "1815". That substring can occur by chance. Use a synthetic value containing non-hex characters and assert that the actual salt value appears nowhere in the schedule. test_api_recheck.py:137

VERDICT: REQUEST CHANGES

- begin refuses an absent record or one with no identity; the state binds
  a MAC of the record's identity, so a selector that moves to another
  record is NOT_CHECKED.
- MACs are keyed by the salt and the host frame secret (db_snapshot
  mac_key), with a key check, so the state alone can't be tested against
  guessed values.
- Values are compared as exact JSON: a missing field fails the read, 1 and
  "1" differ, and a type with no JSON form fails the read.
- VerifierReadback refuses redacting verifiers and FHIR/GraphQL without a
  named version; an ambiguous or record-naming refutation fails the read;
  read-failure reasons are fixed sentences.
- Exemptions are {id: operation} maps and apply only to entries the log
  attributes to this caller with that operation; a contradiction is
  NOT_CHECKED.
- Proven caller mutations are judged first; a changed value with an
  unknown, hidden or other actor on the record is NOT_CHECKED.
- A log that records nothing gives no activity_log basis; without a log the
  result lists this caller's other changes as not covered.
- state_problem validates types, bounds and digests; schedule refuses a
  malformed state; the result reports the observation interval.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 5cd4111

The corrective commit closes the absent-record baseline, ambiguous matches with returned records, changes to the observed local record ID, and a configured log that returns no result. The named-version requirement, host-keyed MACs and fixed read-failure messages are in place. Four evidence gaps from the two prior reviews remain.

  1. FHIR can still verify a field the server omitted. The FHIR projection inserts a key for every configured field. Its extractor returns None for a missing path or a non-unique filtered match. By the time VerifierReadback checks for its missing sentinel, the key exists. Two such reads with the same observed ID and version can verify without either read showing the declared field. Preserve field presence through projection, or refuse projection values whose presence the adapter cannot establish. The current missing-field test supplies a dictionary without the key. FHIR extraction · Projection · Field check · Test

  2. A whole-record REST comparison can still hash masked evidence. The deployment wrapper RedactingVerifier keeps its policy in _policy and delegates other attributes to the inner verifier. The new guard checks only verifier.redaction. In the REST path with no named version, an undeclared field can consequently be masked before the record digest is computed. The subsequent marker check receives the digest and selected fields and cannot see the masked input. Refuse masked inputs before computing the whole-record digest, including through the deployment wrapper. Wrapper · Applied policy · Guard · Digest and marker check

  3. Locally identical IDs still do not establish that the same source, actor and stream were rechecked. The baseline now binds the ID from its own read. The preceding verified write still contributes only an outcome string and a caller-supplied target label. The state carries no source or actor identity, and the log guard checks only whether a log was supplied. A restarted caller can select a different account or stream with overlapping record and checkpoint IDs and receive a positive verdict for the wrong evidence. Bind the original observed record and its source scope, plus the configured stream and actor, and refuse a mismatch or unavailable binding. The added identity test changes the ID within one source. Baseline · State · Recheck · Test

  4. An incomplete configured log can still produce a definitive refutation. When the fields changed or the record disappeared, the decision returns REFUTED before checking window.reached. If the available page contains no attribution, the unread portion could still attribute the change to another actor. Preserve immediate refutation for a proven unrelated caller mutation, then return NOT_CHECKED for incomplete attribution before judging changed fields. The incomplete-window test leaves the fields unchanged. Decision order · Test

I traced the corrected paths and read the committed assertions. I did not run a new suite. The evidence is synthetic, including MockMed REST and a scripted activity log. The delta adds no application-specific engine branch.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 5cd4111

Codex run on 5cd4111 (read-only sandbox, blockers only, round 2 after the fixes for the 13 round-1 blockers). The prompt stated two design decisions: VERIFIED without a log stays allowed on the system_api basis with the gaps listed as not covered, and adapters must return log positions only. Codex found 16 blockers. Its findings follow verbatim:

Record evidence

  1. The wrong record can produce VERIFIED. begin() MACs the supplied target and the observed identity separately. A check for Patient/7 can therefore baseline patient 8 and verify it on the second read. I also reproduced a switch after a correct baseline with the real FHIR verifier: an included Organization/7 replaced Patient/7 in the match, and the same local ID, fields and version passed. Bind the fully qualified identity from the first verified result and require both reads to return it. api_recheck.py:444 · fhir.py:584

  2. The adapter misclassifies both changed and unchanged declared fields. For FIELD_EQUALS, changing the target’s note yields a real verifier refutation containing exactly that record. The adapter discards it and returns NOT_CHECKED. Conversely, when only note is declared for recheck, changing a separate type used in the original selector yields zero matches and REFUTED, although the target and note remain present. Read by bound identity, distinguish absence from selector failure, and include effect.field in the default comparison for FIELD_EQUALS. api_recheck.py:835 · api_recheck.py:877

  3. One visible GraphQL match is accepted as unique on an incomplete page. I supplied a connection with one matching node and hasNextPage=true. The real GraphQL verifier discarded the pagination metadata and the recheck returned VERIFIED. A second matching node can be on the next page. Require an identity-unique lookup or establish complete pagination before accepting a single match or declaring absence. api_recheck.py:879 · graphql.py:265

  4. A missing FHIR field can verify as a value. With a valid meta.versionId and a declared note absent from the resource, FHIR flattening creates {"note": None}. Both reads pass the adapter’s presence check and the result is VERIFIED. A filtered path with multiple matches can also flatten to None. Preserve missing and ambiguous extraction results through the projection and reject them before hashing. The missing-versus-null test only changes a present string to None. api_recheck.py:885 · fhir.py:373 · test_api_recheck.py:541

  5. An empty version path bypasses the projected-record safeguard. version_path="" passes the constructor’s is None check, then selects the digest fallback in read(). FHIR or GraphQL can consequently return VERIFIED after an unprojected field changes. Validate a nonempty path at construction and use the same condition when reading it. api_recheck.py:852 · api_recheck.py:888

  6. Hashing hides redaction markers from the redaction check. A REST record with [redacted] in an undeclared field gets hashed first. The subsequent check sees the digest, so changes concealed by that marker can yield VERIFIED on the claimed whole-record comparison. Check the digest input for markers before hashing. The capability table also promises that a redacting verifier is refused, while the constructor accepts a GraphQL policy that redacts an unrelated field. Align that claim with the enforced policy. api_recheck.py:906 · CAPABILITIES.md:185

Log evidence

  1. The recheck can read a different log and report a clean window. I took a checkpoint in log A, added an unaccounted caller deletion there, and supplied a quiet log B with the same checkpoint ID. The result was VERIFIED with an activity_log basis. The guard checks only whether a log was supplied. Bind the stream, tenant and acting principal to the state using a MAC, and verify that binding before accepting since(). api_recheck.py:586

  2. A checkpoint can advance after it was taken. dict(log.checkpoint()) shares nested lists with the adapter. When an adapter appended a new event ID to its live cursor list during the baseline record read, the state absorbed that ID. The caller’s late mutation disappeared from the window and the result was VERIFIED with zero entries. Deep-copy the JSON checkpoint immediately. At recheck, verify and use one detached state snapshot and pass the adapter its own checkpoint copy. api_recheck.py:432 · api_recheck.py:616

  3. Contradictory exemptions can yield VERIFIED. An ID exempted as this caller’s create is silently skipped when the log reports it as another caller’s read. A second case also passes when own_events declares create and excused_events declares update for the same ID. Check exempt IDs before ignoring reads, and reject conflicting operations for one ID before applying exemptions. api_recheck.py:658

  4. An incomplete log can turn an ambiguous change into REFUTED. With a changed field, reached=False, and no visible explaining entry, the field comparison returns REFUTED before checking reached. The missing page could contain another actor’s edit. Check completeness before attributing a changed or deleted record from the absence of an entry. api_recheck.py:709

  5. An unknown operation can fall through to VERIFIED. A single entry with kind="unknown", by="other" and on_target=False sets no uncertainty flag. This contradicts the stated unknown-kind rule. Handle unknown operations explicitly before ignoring known mutations by other actors on other records. api_recheck.py:682

  6. Malformed adapter evidence can verify or leak into the result. LogRead(entries=[], reached="false") yields VERIFIED because the string is truthy. hidden=None is treated as zero, while a text-valued hidden is interpolated verbatim into the serialized reason. Validate the exact boolean, nonnegative count and entry shapes before judging. Return a fixed NOT_CHECKED reason for invalid evidence or a failed adapter call. api_recheck.py:617 · api_recheck.py:739

State, scope and tests

  1. The private state retains arbitrary first-result text and mishandles the repository’s verified enum. Passing an outcome explanation containing a record identifier stores it verbatim. Passing TransactionOutcome.VERIFIED stores "TransactionOutcome.VERIFIED", which later yields NOT_CHECKED. Store a closed outcome or a first_verified boolean derived from the enum value, and validate that representation when loading state. api_recheck.py:454

  2. Malformed state or receipt data can escape without a verdict. A JSON integer of 10**400 for window_s raises OverflowError in math.isfinite(). A non-ASCII expected digest raises TypeError in compare_digest(). Check numeric bounds before float conversion and validate the digest’s ASCII format before comparison. Both cases should yield NOT_CHECKED. api_recheck.py:394 · api_recheck.py:562

  3. The serialized scope can claim observations that never occurred. An early recheck with a checkpoint reports both system_api and activity_log and supplies an observation interval before either source runs. On a successful read, flooring the end timestamp can also exclude the read itself: a read at 12:03:20.900Z can report both endpoints as 12:03:20Z. Build the scope from completed reads, leave unobserved intervals empty, and preserve fractional seconds or round the ending bound upward. api_recheck.py:374 · api_recheck.py:623

  4. The independence and tier tests can pass with their guards removed. The fixture is FHIR, and the tests omit version_path. Removing the independence or tier check still produces the expected ValueError from the missing-version guard. Supply a valid version path, establish that the unchanged fixture is accepted, and assert the specific rejection for each disallowed tier or independence setting. test_api_recheck.py:474 · test_api_recheck.py:482

VERDICT: REQUEST CHANGES

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 288685b

Three of the four previous findings are fixed. The remaining blocker is whether the recheck observes the same account, record and log actor as the original verified write.

  • Record source. VerifierReadback.source_scope() binds the endpoint, resource query and identity path. The actual FHIR reader can select its account through a token provider, and REST accepts request headers. An account change on a shared endpoint leaves the computed scope unchanged. Equal local IDs, fields and versions can then yield VERIFIED for a record in another account. Require a stable, non-secret tenant or principal identifier from the actual reader, and decline verification when the reader cannot establish its account scope. Computed scope · FHIR authentication · REST configuration
  • Original observation and log actor. begin() compares the first verified result’s record ID only when the caller supplies the optional first_identity. Without it, the caller's target label and the newly read ID are MACed independently. The log guard likewise accepts any non-null JSON scope, including one naming a stream with no actor. A later comparison proves only that the supplied values repeat. For a VERIFIED recheck, require the original observed identity in its source scope and a complete stream-and-actor identity whenever a log is scheduled. The added regression checks different complete mock scopes and None. It does not cover a shared endpoint with different accounts, a missing original identity, or a stream missing its actor. First-read inputs · Binding · Log comparison · Regression

The FHIR projection now refuses an omitted or ambiguous field flattened to null. A projected explicit null also receives that conservative result. REST checks the deployment wrapper’s policy and scans the retained record for redaction markers before hashing. An incomplete log now yields NOT_CHECKED for a changed or absent record, while an independently proven caller mutation can still refute. Field check · Wrapper policies · Digest input · Verdict order

The engine docstring no longer names a vendor. I traced the source and read the committed assertions. The author reports 70 passing tests. This review adds no new test run or held-out system evidence.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 3758185

One source-binding gap remains. For a SMART/FHIR reader, VerifierReadback.source_scope() accepts token_source.client_id as the account. The resource endpoint is bound, but the authorization server that registered the client is absent. The supported deployment configuration allows a separate token endpoint, and the actual SMART client uses that endpoint as the audience for its signed client assertion. If one FHIR endpoint serves two authorization authorities that use the same client ID, switching between those authorities leaves the recheck binding unchanged. The schedule binds the resulting state hash and supplies no additional authority identity. Source binding · Deployment wiring · SMART configuration · Client assertion · Schedule

Bind the SMART client ID to a stable identifier for its authorization server, or decline verification when the reader cannot establish that identifier. This permits ordinary token or signing-key renewal for the same principal. A focused regression can distinguish the same client ID at two authorities from renewal at one authority. The checked-in shared-endpoint test gives its synthetic readers different account labels. Regression

The other parts of the previous review are fixed. A verified first result requires its observed record ID to match the baseline. A scheduled log requires both a nonempty stream and actor, and recheck compares their bound values. Readers with no account identity now decline verification. Baseline · Recheck

The owner reports 71 local tests passed. I reviewed the exact source and committed assertions. The two-authority case follows from the supported configuration and was not tested against a live deployment. Hosted checks were still running at publication, and the protected-path evidence check had failed.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 853cc23

One comparison still merges distinct SMART token audiences. The new binding removes trailing slashes from the authorization-server identifier. For example, configured token endpoints ending in /token and /token/ produce the same source MAC for the same client and FHIR endpoint. The production token source preserves the configured string, signs it as the JWT audience, and sends the request to that exact URL. The two paths can identify different authorization endpoints. A recheck should decline when those audience identifiers differ. Preserve the exact issuer or token-endpoint identifier used by the reader and add that comparison to the existing regression. Source comparison · Stored endpoint · Assertion audience · Token request

The previous finding is otherwise addressed for the cases in the new test. A missing authority declines verification. Distinct authorization hosts produce distinct bindings. Renewal with the same client and authority keeps its binding because the bearer token and signing-key ID are excluded. The private state stores the keyed source MAC. The earlier original-record, stream and actor checks are unchanged. Regression · State · Stored MAC

I reviewed the source and checked-in assertions without running a new suite. The regression uses synthetic token-source objects. The remaining case follows from the lookup and request code. I did not exercise a live authorization server.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 76638f3

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 3224fdf

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 76638f3

Gemini run on 76638f3 (gemini-3.1-pro-preview; Codex is at its usage limit until Nov 27). Gemini got every earlier Codex finding, the full diff against the merge base, and the complete post-change text of api_recheck.py, test_api_recheck.py and smart_auth.py, and was asked to confirm each finding one by one. Its answer follows verbatim.

R1-1: FIXED. api_recheck.py:479-480 raises ReadFailed if the record is absent (if not seen.found).
R1-2: FIXED. api_recheck.py:1101-1104 checks for _MISSING or None for projected records.
R1-3: FIXED. api_recheck.py:490-495 compares seen.identity with first_identity.
R1-4: FIXED. api_recheck.py:954-964 checks substrate in API_SUBSTRATES and independent_system_of_record.
R1-5: FIXED. api_recheck.py:730-734 checks window.logs and raises ReadFailed if empty.

R2-1: FIXED. api_recheck.py:479-480 raises ReadFailed if not seen.found.
R2-2: FIXED. api_recheck.py:490-495 checks first_identity and api_recheck.py:682-704 checks log_scope_mac.
R2-3: FIXED. api_recheck.py:738-742 sets basis and not_covered based on log_covers.
R2-4: FIXED. api_recheck.py:976-981 checks _redaction_policies and api_recheck.py:1123-1127 checks _redacted.
R2-5: FIXED. api_recheck.py:262-269 (_canonical) enforces exact JSON types.
R2-6: FIXED. api_recheck.py:1094-1095 raises ReadFailed if len(records) != 1.
R2-7: FIXED. api_recheck.py:779-785 checks if an exempted id has contradictory author or operation.
R2-8: FIXED. api_recheck.py:805-816 checks self_on_target and self_elsewhere first.
R2-9: FIXED. api_recheck.py:272-277 (_key(salt)) uses mac_key(salt).
R2-10: FIXED. api_recheck.py:147-151 uses fixed sentences for ReadFailed and api_recheck.py:1088-1089 raises a safe message.
R2-11: FIXED. api_recheck.py:541-597 (state_problem) validates types, bounds, and formats.
R2-12: FIXED. api_recheck.py:627-628, 736, and 761 capture and report the exact observation interval.
R2-13: FIXED. test_api_recheck.py:147-164 uses synthetic values to avoid chance collisions.

R3-1: FIXED. api_recheck.py:1101-1104 checks v is _MISSING or (self._projected and v is None).
R3-2: FIXED. api_recheck.py:983-1001 traverses _inner for policies and api_recheck.py:1123-1127 checks _redacted(trimmed) before hashing.
R3-3: FIXED. api_recheck.py:467-472 checks _valid_source_scope and api_recheck.py:662-680 compares source_mac.
R3-4: FIXED. api_recheck.py:822-823 checks window.reached before checking fields.

R4-1: FIXED. api_recheck.py:490-495 compares seen.identity with first_identity.
R4-2: FIXED. api_recheck.py:1092-1093 returns found=False if status == "refuted" and not records.
R4-3: FIXED. api_recheck.py:1094-1095 raises ReadFailed if len(records) != 1.
R4-4: FIXED. api_recheck.py:1101-1104 checks v is _MISSING or (self._projected and v is None).
R4-5: FIXED. api_recheck.py:967-972 checks version_path is None.
R4-6: FIXED. api_recheck.py:1123-1127 checks _redacted(trimmed) before hashing.
R4-7: FIXED. api_recheck.py:682-704 compares log_scope_mac.
R4-8: FIXED. api_recheck.py:475 deep-copies the checkpoint (dict(log.checkpoint())).
R4-9: FIXED. api_recheck.py:779-785 checks if an exempted id has contradictory author or operation.
R4-10: FIXED. api_recheck.py:822-823 checks window.reached before checking fields.
R4-11: FIXED. api_recheck.py:860-863 checks unknown_on_target or unknown_elsewhere.
R4-12: FIXED. api_recheck.py:730-733 checks isinstance(window, LogRead) and window.logs.
R4-13: FIXED. api_recheck.py:463-466 checks str(first_outcome) == "VERIFIED".
R4-14: FIXED. api_recheck.py:541-597 (state_problem) validates types, bounds, and formats.
R4-15: FIXED. api_recheck.py:761 sets observed_from=started.
R4-16: FIXED. test_api_recheck.py:497-518 uses valid version paths and asserts specific rejections.

R5-1: FIXED. api_recheck.py:1003-1083 (source_scope) extracts account, auth_server, etc., and returns None if missing.
R5-2: FIXED. api_recheck.py:463-466 requires first_identity for VERIFIED, and api_recheck.py:471-472 requires _valid_log_scope.

R6-1: FIXED. api_recheck.py:1045-1058 preserves the exact token_url (including trailing slashes) by assigning auth_server = srv without stripping.

NEW BLOCKER:
SMART discovery fails the recheck in a new process. When SMART Backend Services is configured to discover the token URL (i.e., token_url is omitted), SmartBackendTokenSource initializes _token_url as None and only populates it upon the first token request (_request()). In recheck(), source_scope() is called before record.read() (api_recheck.py:662-668). If recheck() runs in a fresh process (which is standard for a delayed recheck), _token_url is still None. source_scope() checks _token_url, finds it None, and returns None (api_recheck.py:1061-1062). recheck() then immediately returns NOT_CHECKED with "the record source carries no account/tenant source binding". This prevents any delayed recheck relying on SMART discovery from succeeding.

VERDICT: REQUEST CHANGES

The new blocker is fixed at 3224fdf: SmartBackendTokenSource.token_endpoint() discovers the endpoint once without requesting a token, and source_scope() uses it.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 3224fdf

Gemini run on 3224fdf (gemini-3.1-pro-preview; Codex is at its usage limit until Nov 27). Gemini got every earlier Codex finding, its own earlier blocker (G1), the full diff against the merge base, and the complete post-change text of api_recheck.py, test_api_recheck.py and smart_auth.py. It was asked to confirm each finding one by one. Its answer follows verbatim. Its round labels group the Codex comments as it read them.

R1-1: FIXED. api_recheck.py:479-480 raises ReadFailed if not seen.found.
R1-2: FIXED. api_recheck.py:1113-1116 checks v is _MISSING or (self._projected and v is None).
R1-3: FIXED. api_recheck.py:490-495 compares seen.identity with first_identity.
R1-4: FIXED. api_recheck.py:954-964 checks substrate in API_SUBSTRATES and independent_system_of_record.
R1-5: FIXED. api_recheck.py:730-733 checks isinstance(window, LogRead) and window.logs.

R2-1: FIXED. api_recheck.py:479-480 raises ReadFailed if not seen.found.
R2-2: FIXED. api_recheck.py:1113-1116 checks v is _MISSING or (self._projected and v is None).
R2-3: FIXED. api_recheck.py:490-495 compares seen.identity with first_identity.
R2-4: FIXED. api_recheck.py:954-964 checks substrate in API_SUBSTRATES and independent_system_of_record.
R2-5: FIXED. api_recheck.py:730-733 checks isinstance(window, LogRead) and window.logs.

R3-1: FIXED. api_recheck.py:479-480 raises ReadFailed if not seen.found.
R3-2: FIXED. api_recheck.py:490-495 checks first_identity and api_recheck.py:697-704 checks log_scope_mac.
R3-3: FIXED. api_recheck.py:738-742 sets basis and not_covered based on log_covers.
R3-4: FIXED. api_recheck.py:976-981 checks _redaction_policies and api_recheck.py:1135-1139 checks _redacted.
R3-5: FIXED. api_recheck.py:262-269 (_canonical) enforces exact JSON types.
R3-6: FIXED. api_recheck.py:1106-1107 raises ReadFailed if len(records) != 1.
R3-7: FIXED. api_recheck.py:779-785 checks if an exempted id has contradictory author or operation.
R3-8: FIXED. api_recheck.py:805-816 checks self_on_target and self_elsewhere first.
R3-9: FIXED. api_recheck.py:272-277 (_key(salt)) uses mac_key(salt).
R3-10: FIXED. api_recheck.py:147-151 uses fixed sentences for ReadFailed and api_recheck.py:1100-1101 raises a safe message.
R3-11: FIXED. api_recheck.py:541-597 (state_problem) validates types, bounds, and formats.
R3-12: FIXED. api_recheck.py:627-628, 736, and 761 capture and report the exact observation interval.
R3-13: FIXED. test_api_recheck.py:147-164 uses synthetic values to avoid chance collisions.

R4-1: FIXED. api_recheck.py:1113-1116 checks v is _MISSING or (self._projected and v is None).
R4-2: FIXED. api_recheck.py:983-1001 traverses _inner for policies and api_recheck.py:1135-1139 checks _redacted(trimmed) before hashing.
R4-3: FIXED. api_recheck.py:467-472 checks _valid_source_scope and api_recheck.py:662-680 compares source_mac.
R4-4: FIXED. api_recheck.py:822-823 checks window.reached before checking fields.

R5-1: FIXED. api_recheck.py:1003-1095 (source_scope) extracts account, auth_server, etc., and returns None if missing.
R5-2: FIXED. api_recheck.py:463-466 requires first_identity for VERIFIED, and api_recheck.py:471-472 requires _valid_log_scope.

R6-1: FIXED. api_recheck.py:1045-1072 preserves the exact token_url (including trailing slashes) by assigning auth_server = srv without stripping.

G1: FIXED. smart_auth.py:413-426 adds token_endpoint() which safely discovers the URL if needed. api_recheck.py:1052-1059 calls token_endpoint() inside a try...except Exception block, failing closed (setting srv = None and eventually returning None for the scope) if discovery fails. It never requests a token (only _discover() is called), and it does not store a token in the recheck state (only the MAC of the scope is stored). The exact URL string is preserved without stripping trailing slashes. test_api_recheck.py:1073-1140 thoroughly exercises this behavior in a fresh token source.

VERDICT: APPROVE

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: fb308a8

Delta versus Gemini APPROVE at 3224fdf1680cac70129278af053a7fa9623d12f5 (request 7082918631). No prior Grok verdict at this head. api_recheck.py, smart_auth.py, and test_api_recheck.py are byte-identical to that head. The only unique-file edits from the main merge are later rows in CAPABILITIES.md and llms-full.txt. I did not merge, tag, publish, or dispatch.

I re-read the recheck begin/recheck path and the tests that closed the earlier Codex findings. A recheck of anything but a VERIFIED first check stays NOT_CHECKED. begin fails closed on a bad window, a missing first_identity for a verified first check, an absent record, or a source that lacks account/tenant/principal (and a log that lacks stream and actor). Shared endpoints with a different account, redacted or projected verifiers, and a SMART token endpoint that is not the one actually used are refused. A discovered SMART token endpoint is rebound in a new process. Those cases are still pinned in test_api_recheck.py.

No package version, lock, or changelog change. This does not auto-publish. protected-safety-review is red pending a fresh unedited stamp; launcher CI is red on the known #2421 / #2546 help-text snapshot. I did not merge.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Gemini independent review: APPROVE

From: Gemini
Audited head: fb308a8f7b33493a05353617d59e0357f9e0339a

Independent diff audit of runtime/effects/api_recheck.py and runtime/effects/smart_auth.py:

  • begin takes the log checkpoint before reading the record and recheck reads the record before the log, closing both race windows; window membership is decided by log checkpoint/entry IDs rather than server wall clocks.
  • Private state stores only keyed HMAC-SHA256 digests (db_snapshot.mac_key(salt)) over strict canonical JSON (allow_nan=False, no NaN/Inf/coerced types); no record values or PII are persisted in state or receipt schedule.
  • first_identity is required for VERIFIED baselines and checked against seen.identity; source_scope and stream_scope (non-empty stream + actor) are MAC-bound and re-verified on recheck.
  • VerifierReadback refuses non-API substrates, non-tier-1 verifiers, projected (fhir/graphql) or drop_fields verifiers without version_path, and verifiers whose redaction policy covers compared fields. SmartTokenSource.token_endpoint() cleanly resolves/caches _token_url under lock without minting a token.
  • Generality & durability: generic RecordSource/ActivityLog protocols + VerifierReadback, zero tx/txplan imports, 43 unit tests + real HTTP MockMed tests, honest scope limits.

CI blocker (not merge-ready yet): CI is red on stale CLI help snapshots (packages / flow core unit (shard 2/4) and launcher / run-ci, fixed on main at 76a5a7cd / f3512f68). Needs merge/rebase with origin/main and green CI (and a fresh exact-head review once the head SHA changes). Note: formatted without Reviewed-Head: to preserve the existing protected-safety-review pass on this head.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 6e6f8f9

Delta review versus previously approved head fb308a8f7b33493a05353617d59e0357f9e0339a: clean, conflict-free merge of origin/main (24034b59d72ea4c05960b4e729d9aea72a771b06, including #2553's flow CLI surface snapshot fix). Zero code delta across all PR files. Cross-vendor (claude/... authored, Gemini reviewed). Approve for merge on green CI.

@abrichr
abrichr merged commit 26fedfb into main Nov 22, 2026
57 of 58 checks passed
@abrichr
abrichr deleted the claude/nodb-recheck branch November 22, 2026 23:24
abrichr added a commit that referenced this pull request Nov 23, 2026
#2518 split the page into capabilities/ row files from main as of 17:13 EST.
Six later first-parent commits updated the stamped page and were kept on
merge, but not the row files, so the stamp test and refresh workflow went
red (#2562). Fold those edits into the sources and regenerate the stamp.
CAPABILITIES.md is unchanged.

- #2471: VERIFIED-run prose; fault-test and openIMIS measured-results notes
- #2477: grade file/PDF/email checks by artifact provenance
- #2472: api_recheck row
- #2397: GraphQL / probe_read_routes text on the transaction-lens row
- #2363 / #2368: second-factor row, including terminal/Windows console

Fixes #2562
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