Skip to content

frame: diff the whole database, with a reviewed allow-list - #1582

Draft
abrichr wants to merge 4 commits into
fix/frame-linksfrom
feat/frame-whole-database
Draft

abrichr wants to merge 4 commits into
fix/frame-linksfrom
feat/frame-whole-database

Conversation

@abrichr

@abrichr abrichr commented Oct 25, 2026

Copy link
Copy Markdown
Member

The frame now diffs the whole database by default when a contract declares frame.database, not only the tables the contract reads.

Why: on #1580's blind held-out suite, the read-list frame passed three bot writes as verified. Each wrote somewhere the contract never read: a column on the new chart, a field on its history row, and a calendar row. Adding those reads one case at a time would only cover the cases already seen.

What it does:

  • Snapshot: reads every table and column before and after the save. It takes three statements however many tables there are (schema, row counts, then every row as JSON), so a slow channel such as docker exec stays fast. Tables over max_rows are fingerprinted instead (CHECKSUM TABLE on MySQL and MariaDB, a row hash on SQLite).
  • Judging: each table is one more slice for judge_frame. A row added, removed or changed is collateral unless a declared effect, a declared side record, or a concurrent writer the audit log names explains it.
  • New rows: a new declared or side row that sets a column the effects don't name is collateral, unless the column is in new_row_fields or holds its default. The primary key and database-computed defaults (CURRENT_TIMESTAMP) count as defaults.
  • Allow-list: allow_tables is the reviewed list of tables the app writes on its own (logs, sessions, id registries). It replaces the read-list.
  • Linking fields: attribution.record_keys lets a table name its record through another field (OpenEMR's contact.foreign_id).
  • Fail-closed: an unreadable snapshot, or a table created, dropped or altered in the window, leaves the frame not checked or collateral. It never holds.

Stacked on #1570 (side records and record keys).

Tests: tests/test_frame_database.py covers a clean save, five kinds of stray write, the allow-list, an unreadable database, the three-statement read and a table wider than SQLite's 127-argument limit. One more case is in test_frame_links.py. Locally, 110 tests pass across the frame, frame-links, verify-run and collateral-change suites.

Measured (#1580, stand-in): the whole-database candidate gets 17/17 on both the original suite and the first held-out suite. The first held-out set shaped this design, so its score doesn't count. A second blind held-out set will be the measurement.

🤖 Generated with Claude Code

abrichr and others added 4 commits October 25, 2026 11:02
frame.database snapshots every table and column before and after the save
(three statements, whatever the table count) and judges each table as a
slice. A row added, removed or changed is collateral unless a declared
effect, a side record or an attributed concurrent writer explains it. A new
declared or side row that sets a column nothing declares is collateral too.
Tables over max_rows are fingerprinted. allow_tables, reviewed per app,
replaces the read-list; an unreadable snapshot leaves the frame not checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SQLite caps a function at 127 arguments and OpenEMR's chart has more
columns, so the snapshot failed and the frame was not checked. Each row is
now read as JSON objects of at most 50 columns, merged in Python (a JSON
merge patch would drop null values).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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