Skip to content

Encrypt recordings, bundles and runs at rest by default (key hierarchy) - #2423

Open
abrichr wants to merge 46 commits into
mainfrom
feat/encrypt-at-rest-default
Open

abrichr wants to merge 46 commits into
mainfrom
feat/encrypt-at-rest-default

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

The founder approved encryption by default. This PR makes recordings, bundles and run folders encrypted at rest with no setup.

Key hierarchy (sealed-set version 3)

  • Data key. Each recording, bundle and run folder gets its own random data key. Files are written as Tink AES256_GCM_HKDF_1MB streams. tests/test_stream_aead.py checks this format both ways against Tink itself, at the segment boundaries.
  • Bucket key. The data key is wrapped with HPKE (RFC 9180: DHKEM P-256, HKDF-SHA256, AES-256-GCM) to a per-set bucket key.
  • Bucket record. The bucket key's private half is wrapped in a bucket record to these recipients:
    • the device runtime key, only while the set is being written (a bundle keeps it, so programs still replay unattended);
    • the device viewer key;
    • organization keys (P-256 HPKE or RSA-OAEP-3072);
    • a solo recovery key (RFC 9180 DeriveKeyPair, checked against the A.3.1 vector).
  • Where the record lives:
    • Solo mode (records: inline): inside the header, so a backup still opens with the recovery key.
    • Organization mode (records: archive): in ~/.openadapt/keys/buckets/ plus a copy in the organization's key archive. It is never in the header.
  • Header MACs. The header carries two HMAC-SHA-256 MACs, one under the data key and one under the bucket key. The bucket public key is not secret, so the second MAC is what stops a forged header that rewraps a new data key.
  • Primitives and dependencies. Every primitive comes from cryptography 50 or later. Flow's new core floor is cryptography>=50, for HPKE. keyring stays in the keychain extra, which pip install openadapt already pulls in through hosted. A bare openadapt-flow install without it keeps the device key in a 0600 file and prints a warning. tink is a dev dependency, used only for the interop test.

Policy and organization mode

  • Where the policy comes from. The first match wins:

    1. the MDM managed-preferences profile ai.openadapt.policy;
    2. the registry key HKLM\SOFTWARE\Policies\OpenAdapt;
    3. a root-owned /etc/openadapt/policy.json;
    4. OPENADAPT_POLICY.

    A user-owned file can't set organization mode.

  • Fail closed. Organization mode refuses to run without an active organization recipient and a key_archive. It also stops after max_unarchived records that never reached the archive.

  • No Cloud keys. Cloud never distributes the organization key and holds no key.

Device keys

  • Hardware providers. Secure Enclave, TPM, Touch ID and Windows Hello are interfaces with test doubles. They report themselves unavailable.
  • Software fallback. Until those exist, the device key is a software P-256 key, and at-rest status labels it that way. It is stored in the OS keychain through keyring, with a non-secret marker and a check value. Where no keychain works, it goes in a 0600 file and Flow prints a warning.
  • Fail closed. A keychain entry that is missing, locked or replaced fails closed. Flow never makes a new key over it.
  • Policy switch. require_hardware_device_key refuses the software key.

Defaults, opt-out, legacy

  • What is encrypted by default:
    • web recordings, including the quickstart and tutorial;
    • desktop recordings once converted (the raw capture and the converted plaintext are then deleted);
    • compiled bundles;
    • every run folder, including undo's prior record values and narration.
  • Sealed in, sealed out. A sealed bundle never yields a plaintext run.
  • Opting out. OPENADAPT_ENCRYPT_AT_REST=0, or --no-encrypt on record, compile, run and replay, prints one warning line and adds a ledger line. Strict mode ignores both.
  • Legacy keys and folders:
    • Outside organization mode, OPENADAPT_BUNDLE_KEY and OPENADAPT_RECORDING_KEY still win and keep the v1 header (deprecated).
    • ~/.openadapt/keys/at-rest.key still works.
    • v1 and v2 sets and plaintext folders still read.
    • A plaintext run folder from before this release continues in plaintext, and that is logged.
  • Shredding. openadapt-flow at-rest shred DIR --yes overwrites and deletes the local bucket record and the archive copy, deletes the checkpoints inside the set, and returns a shred record.

Readers

  • These read encrypted and plaintext folders alike: replay, run, resume, compile, inspect report-run, seal verify, teach branch, undo, the receipt page, the quickstart and the agent's bundle discovery.
  • If no key on the computer opens a run, seal verify reports report_locked.

Receipts

  • What stays plaintext. seal.json, receipt.* and public-seal.json. They are listed as structural run files.
  • What they digest. The plaintext report.json, decrypted in memory. Third parties still verify against the plaintext.
  • Coming later. An evidence_set subject carrying the sealed-set digest, once Receipts: counterparty confirmations in record/run/v1 #2410 adds that subject kind.
  • Encrypted runs. Receipts are now written for encrypted runs too. Before this change, the offline receipt skipped them.
  • Receipt page. seal.html embeds the report, so beside an encrypted run it is logged as a plaintext copy.

Not covered yet (documented in phi_at_rest.md)

  • Hardware and KMS:
    • real Secure Enclave, TPM, Touch ID and Windows Hello providers;
    • unwrapping with a KMS (a reviewer uses OPENADAPT_ORG_KEY_FILE);
    • s3:// and smb:// key archives.
  • Records and exports:
    • signing the shred record;
    • export with age;
    • moving the salts file into the set;
    • excluding the bucket directory from backups.
  • Recorders:
    • desktop recorders encrypting before their first write;
    • cross-window record --surface (logged).
  • Runs:
    • attended continuation of an encrypted run;
    • repair on sealed input (it refuses clearly);
    • approval gates, attended drafts and business-decision states on a sealed bundle (refused).
  • Receipts: the evidence_set subject.
  • Quickstart wording. The finale still says "one REPORT.md per run", but the file is now REPORT.md.enc. index.html no longer embeds screenshots.
  • Release decision. The released launcher (openadapt-flow>=3.3.0,<4.0.0) reads run files with pathlib. Before a Flow release that seals by default, we need either a Flow major bump or a coordinated raise of the launcher floor.

Tests

  • Added:
    • tests/test_key_hierarchy.py (35 tests) and tests/test_stream_aead.py (Tink interop);
    • a desktop encryption case;
    • a Windows binary-descriptor fix.
  • Updated: the default-mode cases in test_at_rest_default.py and test_attended_at_rest.py.
  • Real quickstart test. The extended test checks that the disk holds no plaintext PNG or JPEG and no plaintext copy of the typed value.
  • Default-sealing switch. OPENADAPT_TEST_DEFAULT_AT_REST=1 runs the flow suite under the real default. It found the undo-prior, narration and branch-teach plaintext writers, which are fixed here. What still fails under it is tests that assert plaintext paths.
  • Keychain isolation:
    • Every conftest forces the file store.
    • The tests inject an in-memory keychain and hardware doubles.
    • A pytest safety belt keeps any test from reaching the real keychain.
    • No test touches the login keychain, the Secure Enclave or a TPM, and none raises an OS dialog.

Timing

Headless MockMed quickstart, before and after runs alternating on one loaded laptop (load 25 to 37):

Median of 3 warm runs
Before (4d9dc90c6) 90.6 s
After 94.5 s

The gap is within run-to-run noise at that load. One "after" run hit the system Chrome's 180 s launch timeout and is excluded. Data: packages/flow/benchmark/at_rest/quickstart_default_2026-11-21.json.

Real-app check

One headless quickstart run, plus the opt-in test_real_quickstart (which passes):

  • Recording, bundle, run-1 and run-broken are all sealed-set v3.
  • The only PNG on disk is the allow-listed receipt.png.
  • The typed note appears in no file.
  • openadapt seal verify reports both runs valid. Checked with another computer's key, it reports report_locked.

Size budget

__main__.py goes from 14331 to 14326 lines, and its budget is lowered. The at-rest command, --no-encrypt, the desktop recording key, the v3 key precheck and their command-table entries now live in cli_at_rest.py.

Envelope encryption: each sealed set has its own data key, wrapped with age
(X25519, pyrage) for this computer's device key (OS keychain through keyring,
0600 file fallback with a warning), optional organization recipients and
shares. Configured passphrase keys keep the v1 header. at-rest status, share
and shred. Receipts read encrypted runs and stay over the plaintext report
digest.
Sealed-set v3 now wraps each set's data key with HPKE (P-256, HKDF-SHA256,
AES-256-GCM) to a per-set bucket key, whose record is wrapped to the device
runtime key (only while written), the device viewer key, organization keys
(P-256 or RSA-OAEP-3072) and a solo recovery key. Files are Tink
AES256_GCM_HKDF_1MB streams, checked against Tink. Organization mode comes
from a machine policy and fails closed without its recipient and archive.
Hardware providers are interfaces with test doubles. Shred destroys the
tracked bucket-key copies. age and the share verb are gone.
seal verify says report_locked, not subject_mismatch, when no key here opens
an encrypted run. The quickstart makes the device key before its workers
start. Tink interop and hierarchy tests; default-mode tests now expect sealed
output.
…s continue plaintext; desktop encryption test
…ch teach reads encrypted runs

Found by running the reader suites under the real default
(OPENADAPT_TEST_DEFAULT_AT_REST=1).
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Claude encrypt-at-rest agent (author)
Reviewed-Head: 0b04985

Author declaration for the protected-path check. This is not a review.

…wide

Module-scoped fixtures (an e2e recording compiled once per module) ran before
the per-test isolation and now sealed their output by default, under a key
the per-test home could not open.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 1ee0bea

  1. An organization shred can report completion while its archive still holds the key. If the archive is offline or read-only, key_hierarchy.shred deletes the local record first and suppresses the archive failure. The caller marks the header shredded, and the CLI exits 0. A retention job takes that as completion. A backup can still be opened using the archive after it returns, and repeating the command skips that bucket. Preserve enough state to retry the outstanding archive deletion, and report incomplete until every tracked copy is accounted for. Archive deletion · Header update · CLI exit

  2. The writer accepts configurations that lose organization recovery. If an explicitly configured policy file is missing, load_policy returns solo defaults. In an organization policy, records: inline also passes validation with no archive and puts the key record into every header. Both conflict with the documented organization guarantees. Refuse a missing explicit policy and require the archive for organization mode before creating a set. The external-file ownership check is also POSIX-only. On Windows, use machine policy or verify that an administrator controls the file before accepting organization recipients. Policy loader and validation · Header writer

  3. Restoring the archive does not clear the pending-record limit. The writer checks max_unarchived before opening the next set. The only archive calls act on the bucket currently being created or finalized. After the limit is reached, reconnecting leaves every new recording blocked and the existing records local. Add an idempotent way to archive those pending records and exercise one outage followed by recovery. Limit · Finalization

  4. Direct desktop recording still writes plaintext by default. The CLI resolves the key and applies strict policy. The callable record_desktop_capture defaults its key to None and goes straight to capture and conversion without the same policy check. Even when given a key, an explicit capture_dir puts the raw session outside the directory that gets cleaned up. Resolve policy at the capture entry point, and reject an incompatible raw capture destination before recording or manage an owned private staging directory there. Existing callers' directories must remain intact. Desktop entry point · CLI policy

Evidence and scope. I ran three normal-path tests at this head. A v3 run decrypted successfully, another computer opened an archived run with the organization key, and a recovery code opened a solo backup. I traced the incomplete operations above in source. The PR records a headless quickstart measurement. Hardware-backed keys and real keychains were outside my test scope.

Generality. The hierarchy is application-independent. The remaining defects concern policy and lifecycle behavior shared by all records of these kinds. The held-out recovery checks cover a second computer with synthetic data.

- An organization shred reports incomplete, exits non-zero and keeps a
  pending marker until the archive copy is deleted; shred again or
  at-rest archive finishes it.
- A named policy file that is missing refuses; on Windows an organization
  policy comes only from a machine source.
- at-rest archive sends pending key records after an outage, and the next
  set tries it before refusing at max_unarchived.
- record_desktop_capture follows the at-rest policy by default and refuses a
  capture_dir outside its private staging folder when encrypting.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 74f523b

Round 2 covered the four findings from the first review. I ran all six new synthetic tests. All six passed, including retry against a read-only archive, draining pending records, refusing a missing policy file, and sealing a direct desktop recording. Three items remain.

  1. A disconnected or replaced archive can still yield a completed shred. The deletion helper treats an absent file as success even when the mount itself is absent. The retry marker stores the original archive path, but the retry checks the current policy's path. If the organization changes its archive between attempts, absence at the new destination can clear the marker while the original archive retains the key. The backlog now drains after an ordinary outage. Its writer can also create a local directory at a missing mount path and mark the copy archived there. Record the intended archive when the bucket is archived, use it on retry, and require evidence that the intended archive is reachable before recording deletion or delivery. The read-only test covers a reachable archive. Deletion and retry · Archive write

  2. Organization mode still has two incompatible retention guarantees. Missing explicit policies now refuse, and the Windows environment-file check now requires a machine source outside the documented development override. The validator still accepts organization mode with inline records and no archive. The new paragraph documents that choice, but the table and the PR still promise archive storage and deletion of every tracked copy for organization mode. The CLI calls every inline set “solo mode” and only mentions the recovery key, even when an organization recipient can open backups. Enforce archive-only organization mode, or make the explicit inline option consistent in the PR, table, CLI and a test of what an organization key can open after local shredding. Policy validation · Retention table · Inline option · CLI message

  3. Strict desktop capture depends on whether the caller supplied a key argument. The no-argument case now seals by default, and encrypted recordings refuse an external raw directory. But the strict check only runs through the default sentinel. A caller passing an explicit key still starts a raw plaintext capture under strict mode; passing explicit None also skips the check. Apply the strict raw-capture refusal before selecting an explicit or default key and before starting the recorder. Direct entry point · Strict policy

These are application-independent key lifecycle and capture-policy issues. The six checks used synthetic files and a test recorder. I traced the missing-mount, changed-policy and explicit-key behavior in source. This review adds no lab or hardware qualification.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 74f523b

  1. An organization shred can still report success while the archive key survives. An unmounted archive makes the record appear absent, which counts as successful deletion. Shred also consults the current policy, and retry ignores the archive location saved in its pending marker. After an archive move or a switch to solo mode, backups can remain decryptable after the CLI reports completion. Track the archive used for each bucket and require confirmation from that archive. Archive deletion · Shred policy · Retry

  2. Shred trusts the header to identify what to destroy and whether destruction finished. The public library operation uses the header’s bucket ID before authenticating it, so a changed header can direct deletion at another set’s key. The CLI also skips authentication for a claimed shred. A genuine interruption has a similar consequence: Flow writes the completion record before deleting external checkpoints, then returns that record on retry without finishing cleanup. Authenticate the target under the mutation lock and keep durable progress through the last deletion. Target selection · CLI precheck · Completion ordering

  3. Archiving can undo a shred or lose the recovery copy. A pending archive worker can retain a record in memory while shred deletes it, then write both the archive and local copies back. Finalizing a run also rewrites an already archived record in place. A partial write can leave that archive record truncated while the local archived flag stays true, excluding it from retries. Serialize archive and shred per bucket and publish archive records atomically. Pending worker · Archive write · Finalization

  4. The header MACs do not establish who created an inline bucket. The reader accepts a bucket record supplied by the header in preference to a local record. Both MACs can therefore validate under keys selected by the sender of a replacement set. Knowledge of an organization recipient’s public key is sufficient to produce such a set for its reviewer. The forged-header test retains the original bucket, so it misses whole-bucket substitution. Bind the bucket to a trusted writer or authenticated archive record. Record selection · Header verification

  5. Durable checkpoints escape the run’s key lifecycle. A v3 run encrypts checkpoints under a long-lived passphrase. A backup containing those checkpoints remains decryptable with that passphrase after an organization shred. In the opposite direction, downgrading a plaintext-bundle run skips checkpoint-key initialization entirely. A durable library caller with the default checkpoint_key=None can then write parameter bindings in plaintext. Checkpoint key selection · Sealed-run key assignment · Plaintext write

  6. Machine-policy discovery still fails open. Windows registry access denial is treated as an absent policy, permitting solo fallback. Windows also tries the macOS plist path before HKLM, and accepts it without an ownership check. On POSIX, an explicit root-owned org policy passes even when group- or world-writable, allowing its recipients to be changed. Restrict discovery to the platform’s trusted sources and validate permissions on the file actually read. Source order · Registry errors · Explicit-file trust

  7. The archive backlog limit fails at zero and under concurrency. With max_unarchived=0, even a healthy archive and zero pending records refuse every new set. With a positive limit, concurrent writers can each observe the same free slot before either stores its record. A zero-backlog policy needs synchronous archival, and a bounded backlog needs an atomic reservation. Limit check · Record creation

  8. Explicit-key checks accept a wrong passphrase on v3. The v3 derivation discards the supplied passphrase and uses ambient recipient credentials. This breaks callers such as retention planning, which explicitly requires a decryption key and treats a successful open as proof. Give those callers an explicit recipient credential or refuse the unsupported passphrase check. V3 derivation · Retention check

  9. A lost device key can block valid recovery credentials. Recipient discovery reads the device key before trying the recovery code or organization key. Restoring a home directory with its keychain marker, but without the original keychain entry, raises immediately. The valid recovery recipient is never tried. Candidate discovery · Missing-entry failure

  10. Desktop capture can still succeed with plaintext left on disk. An explicit encryption_key=None bypasses strict mode, the ledger, and the capture_dir restriction. Even on the default encrypted path, cleanup suppresses every deletion error, so a locked raw database or video can survive a successful return. The organization policy is also first validated during sealing, after capture has occurred. Enforce policy before starting the recorder and surface cleanup failures. Policy dispatch · Post-capture sealing · Suppressed cleanup errors

  11. Other recording entry points silently write plaintext. The public Recorder still defaults to an unsealed writer. The authoring session and live desktop-demo adapter both construct it without a key. These paths persist screenshots and typed values without consulting the at-rest policy or recording an opt-out. Recorder default · Authoring session · Desktop adapter

  12. Exporting a receipt can silently export raw field values. For a verified run with READ steps, report-run --receipt DIR --production also writes records.json into DIR. When the destination is a new directory outside the sealed run, the path helper writes plaintext. Strict mode’s directory precheck skips a destination that does not yet exist. Keep the field values inside the sealed run or require a separate, policy-checked export. Receipt export · Field-value write · Destination check

  13. --no-encrypt persists into later commands. The flag changes two process environment variables and never restores them, including when the command fails. An application invoking Flow in-process can consequently write later recordings or bundles in plaintext after opting out for one invocation. Environment mutation · Command dispatch

  14. Single-run receipt verification is blocked. openadapt seal verify RUN delegates to local-seal verify, whose handler is absent from the sealed-input allowlist. Its own input check also requires a physical plaintext report.json. The CLI therefore cannot verify the receipt it just produced for a default encrypted run. Launcher delegation · Allowlist · Verifier precheck

  15. The public Python replay API reports failure after execution. In the headless MockMed test, replay finished its steps, wrote the encrypted report and signed it. api.replay() then raised FlowCommandFailed because it checked for plaintext report.json. A caller could retry work that already ran. Read the report through the artifact reader. Replay result handling

  16. Hosted reporting either rejects or invalidates an encrypted run. Success reporting decrypts the report, then discards those bytes and reopens the missing plaintext path. Break reporting goes further and writes .report_run_id directly into the run. That plaintext UUID is outside the sealed inventory, so subsequent report reads and receipt verification refuse the directory. Success-report parse · Break-report ID · Inventory refusal

Evidence and scope. I verified the exact head. All 42 targeted hierarchy, streaming and desktop tests passed with synthetic data and the real OS keyring disabled. They confirm read-only archive retry, refusal of a missing explicit policy, recovery at a positive backlog limit, and the default direct-capture capture_dir guard. The separate MockMed Python API test failed with default encryption enabled. I also checked the verifier’s registered handler against the allowlist. The remaining findings are from source inspection, including Windows and concurrency behavior. I made no repository changes.

# Conflicts:
#	CAPABILITIES.md
#	llms-full.txt
#	packages/desktop/tests/conftest.py
#	packages/flow/docs/design/DECOMPOSITION.md
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 2e4776b

  1. Prior security & functional blockers from Codex's 74f523b8 review remain unaddressed. The only commit since 74f523b8 is a merge of origin/main (2e4776bf). All 16 blockers still apply at 2e4776bf — in particular: organization shred reporting success when an archive is unmounted, unauthenticated header bucket selection in shred, archive/shred concurrency races, inline-bucket substitution, checkpoint keys escaping the shred lifecycle, --no-encrypt mutating process env persistently, openadapt seal verify failing on default encrypted runs, api.replay() raising on encrypted runs, and hosted break reporting writing plaintext .report_run_id into sealed runs.
  2. CI failures at 2e4776bf:
    • packages / flow core unit (shard 1/4): tests/test_cli_surface.py fails on test_every_command_and_flag_is_unchanged (new at-rest* / encrypt commands unregistered) and test_help_text_is_byte_identical.
    • packages / eligibility connector (py3.12): uv export --locked exited 1.
    • launcher / run-ci (ubuntu-latest, 3.12): tests/test_cli_surface.py failure.
    • Evaluate protected-path evidence: missing exact-head author declaration (branch feat/encrypt-at-rest-default has no vendor prefix).

Scope & evidence: Verified exact head 2e4776bf, commit history since 74f523b8, and failing CI job logs (137293786126, 137293786170, 137290742803, 137290730846). No repository changes made.

…ze bucket changes

- An archive counts as reachable only with its .openadapt-key-archive marker;
  Flow never creates the folder, writes records atomically, and records the
  archive each bucket went to (header and record). Shred and retry use that
  archive, never the current policy, and a missing marker is never deletion.
- Shred authenticates the header with a recipient key before choosing what to
  destroy, keeps progress in the header and a local pending marker, and says
  complete only after the store files and the archive copy are gone.
- One bucket lock serializes create, archive, close and shred, so a shredded
  record is never written back. max_unarchived is checked after the new
  record's own archive attempt (0 means synchronous), and a refused set
  leaves no record.
- Organization mode requires records: archive. A record that arrives in a
  header opens only with this computer's device keys or a recovery key.
- A lost device key no longer hides a valid recovery or organization key.
- Machine policy: each platform reads only its own sources, HKLM access
  denied is an error, and every policy file is checked root-owned and
  root-writable-only on the descriptor actually read.
- Refresh the eligibility connector lock.
- Durable checkpoints (and rollback state) in a version 3 run use a key
  derived from the run's data key, whoever constructs the store, so a shred
  reaches them in backups too. A store without a key encrypts by default,
  and a downgraded run still sets its checkpoint key.
- --no-encrypt lasts for one command: the environment is restored however
  the command ends.
- Recorder and InteractiveRecorder default to the at-rest policy; an
  explicit encryption_key=None is refused in strict mode and ledgered
  otherwise. Direct desktop capture applies strict mode, the ledger and the
  organization policy before the recorder starts, and a plaintext staging
  folder that survives cleanup is an error, not a success.
- report-run --receipt writes records.json only inside an encrypted run (or
  under the recorded opt-out).
- local-seal verify reads an encrypted run's report in memory and is
  sealed-ready (and strict-safe on plaintext runs).
- api.replay reads the report through the sealed set.
- Hosted success reporting parses the bytes it decrypted; the client run id
  of an encrypted run is a structural file in its sealed index.
- Retention planning refuses a passphrase check on a version 3 run, where
  the passphrase plays no part.
…ation and run-keyed checkpoints

Move the encryption-at-rest changelog section to Unreleased: v3.4.0 shipped
without it.
@abrichr

abrichr commented Nov 22, 2026 •

Copy link
Copy Markdown
Member Author

Response to the Codex review at 74f523b (16 findings)

All 16 are fixed at d2cbdf21c9cc528b83f15305e7b134908aa3a03d (updated from 44f7d75 and ea48b25). None were rejected. Main is merged in (no force-push). Encryption now fails closed on each path below: a missing key, a failed decryption or an unreachable archive stops the operation, and nothing is read or written in plaintext in its place.

# Finding Fix Test
1 An unmounted or replaced archive could yield a completed shred An archive counts as reachable only when its root holds an administrator-created .openadapt-key-archive file. Flow never creates the archive folder. Each record and each v3 header (under the MACs) names the archive the record went to. Shred and retry use that archive, never the current policy. A missing marker is never read as "deleted" or "delivered". Archive writes are atomic. (5cd564b) test_an_unmounted_archive_is_never_the_archive, test_shred_uses_the_archive_the_set_was_written_to (share drops, policy moves, then switches to solo; only the original archive completes the shred)
2 Shred trusted the header's bucket id and its completion record sealed_set.shred authenticates the header with _open_v3 (both MACs) under the set lock before it chooses a bucket. If no key here authenticates it, shred refuses and destroys nothing. Progress is durable: complete is set only after the store files and the archive copy are gone. A retry repeats the cleanup and acts only on this computer's own pending marker, never on header fields. (5cd564b) test_shred_refuses_a_header_pointed_at_another_sets_key, test_an_interrupted_shred_finishes_its_cleanup_on_retry
3 Archiving could undo a shred; a partial archive write could leave a truncated record One bucket_lock (thread and process) serializes create, archive, close and shred. Archive and close re-read the local record under the lock and never write back a record that is gone. If one was shredded while its set was still being written, finalizing refuses. Archive records are written via temp file and os.replace. (5cd564b) test_a_shredded_record_is_never_written_back
4 Header MACs did not establish who created an inline bucket Organization mode now requires records: archive (this also settles round 2's item 2). The local record is used ahead of a header-supplied one, and a header-supplied record never opens with an organization or break-glass key. Solo mode (2321f4b): a header record opens silently only through this computer's device key, whose public key is never written out. A set that only the recovery code opens could have been made by anyone who read recovery.pub.json, so it is refused (SealedSetRestoreRequired) until the person restores it on purpose. openadapt-flow at-rest restore DIR --yes rewraps the bucket to this device and re-stamps the header; OPENADAPT_RECOVERY_RESTORE=1 reads backups in place where no device key can be made. test_a_whole_replacement_set_does_not_open_with_the_org_key, test_a_set_forged_to_the_recovery_public_key_is_refused, test_a_recovery_code_opens_a_backup_on_a_new_computer (restore), test_the_cli_restores_a_backup_with_the_recovery_code, test_organization_mode_requires_the_archive
5 Durable checkpoints escaped the run's key lifecycle In a v3 run, the checkpoint and rollback-state passphrase is derived from the run's DEK (V3Key.store_passphrase). CheckpointStore and SealedRollback bind to it whoever constructs them, so resume, the business-decision supervisor and the campaign readers all resolve the same key, and a shred reaches those files in backups too. A store with no key now encrypts with the local key, and plaintext happens only under the recorded opt-out. A downgraded run sets its checkpoint key again. (f4b25e3) test_a_v3_runs_checkpoints_are_keyed_to_the_run_and_die_with_it, test_a_checkpoint_store_without_a_key_encrypts_by_default
6 Machine-policy discovery failed open Sources are per platform: macOS reads the plist and /etc, Windows reads HKLM only, Linux reads /etc only. An HKLM access denial is an error; only a key that does not exist counts as "no policy". Every policy file, plist and explicit OPENADAPT_POLICY alike, must be root-owned and root-writable only, checked by fstat on the descriptor actually read. (5cd564b) test_a_registry_policy_the_account_cannot_read_is_an_error (fake winreg), test_each_platform_reads_only_its_own_policy_sources, test_a_root_owned_policy_others_can_write_is_not_trusted, test_a_machine_policy_wins_over_the_user_one
7 max_unarchived failed at 0 and under concurrency The new record is stored and archived under the bucket lock. Only if the archive fails is the waiting count compared with the limit (> max). When it is over, the record is destroyed and the set refused. With a limit of 0, every set waits for its own archive write. (5cd564b) test_a_zero_backlog_needs_the_archive_for_every_set, test_concurrent_writers_cannot_share_the_last_backlog_slot (4 threads, 1 slot)
8 Explicit-key checks accepted a wrong passphrase on v3 plan_retention now refuses a v3 run (explicit_key_does_not_open_version_3_run) instead of treating an open as proof. key_rotation already refused v3. (f4b25e3) test_retention_refuses_a_passphrase_check_on_a_version_3_run
9 A lost device key blocked valid recovery credentials The device-key error is deferred. The recovery code and organization key are still tried, and the device error is raised only if nothing opens the record. Writing still fails closed. (5cd564b) test_a_lost_keychain_entry_does_not_hide_the_recovery_code (the code reads only with OPENADAPT_RECOVERY_RESTORE=1; never silently)
10 Desktop capture could succeed with plaintext left on disk Policy is applied before the recorder starts, for every key value: strict mode refuses; an explicit None is refused in strict mode and ledgered otherwise; the organization policy is checked via preflight, which makes no record. Staging cleanup reports every path it could not delete. Plaintext that survives is an error, not a success. (f4b25e3) test_strict_mode_refuses_direct_capture_whatever_key_is_passed, test_an_explicit_none_key_is_recorded_in_the_ledger, test_organization_policy_is_checked_before_capture_starts, test_a_capture_staging_that_survives_is_not_a_success
11 Other recording entry points silently wrote plaintext Recorder and InteractiveRecorder now default to POLICY. Authoring, the desktop-demo adapter and demo_driver construct them without a key, so they get the policy too. An explicit None is refused in strict mode and ledgered otherwise. (f4b25e3) test_the_library_recorder_seals_by_default, test_an_explicit_none_recorder_is_refused_in_strict_and_ledgered_otherwise
12 report-run --receipt could export raw field values in plaintext write_sealed_reads writes records.json only inside an encrypted run directory or under the recorded opt-out. Otherwise it raises AtRestRefused, which is checked before the write and so also covers a destination that does not exist yet. (f4b25e3) test_records_json_outside_an_encrypted_run_is_refused
13 --no-encrypt persisted into later commands at_rest.opted_out() is a context manager around the whole command in main(), and it restores both environment variables however the command ends. (f4b25e3) test_no_encrypt_lasts_for_one_command (failing command), test_opted_out_restores_the_environment_on_error
14 Single-run receipt verification was blocked cli_local_seal:_cmd_verify is sealed-ready. It is also read-only, so strict mode still verifies plaintext runs. Its input check reads the report through the sealed set in memory. (f4b25e3) test_local_seal_verify_reads_an_encrypted_runs_report (input check and allowlist; not an end-to-end signed verify)
15 api.replay() reported failure after execution It reads report.json through sealed_set. (f4b25e3) test_the_python_replay_api_reads_an_encrypted_report (stubbed main)
16 Hosted reporting rejected or invalidated an encrypted run Success reporting parses the bytes it already decrypted. In an encrypted run, .report_run_id is a structural file written through the sealed writer, so it is indexed rather than merely adopted on read. It is created once under its own private lock, and a retry keeps the same id. (f4b25e3) test_cloud_report_ids_live_in_the_sealed_index (the success-parse change has no separate test)

Also in this push.

  • Merged origin/main. The only conflict was the size-ratchet table; budgets use main's values, and __main__.py is at its budget.
  • Regenerated packages/flow/tests/fixtures/cli_surface.json on Python 3.12.13 with Click 8.4.2 from the flow lock. The diff contains only the at-rest commands and --no-encrypt.
  • The launcher snapshot needed no change under Click 8.5.0 from the root lock.
  • Refreshed the eligibility connector's uv.lock, which was the uv export --locked failure.
  • Rebuilt llms-full.txt.
  • Updated phi_at_rest.md, CAPABILITIES.md and the changelog. The encryption section moved to Unreleased, because v3.4.0 shipped without it.

Rollback in the default mode (2321f4b). rollback.py wrote rollback/compensated (and its difference files) in plaintext inside an encrypted run, which the reader refused, so rollback proof broke once encryption became the default. These writes now go through the run's sealed set. was_compensated reads the marker there, and treats a run whose state can't be read as not resumable. Test: test_a_rollback_in_an_encrypted_run_keeps_its_marker_sealed. CI now runs test_rollback.py, test_rollback_qualify.py, test_checkpoint_key_derivations.py, test_key_hierarchy.py and test_at_rest_review_round3.py with OPENADAPT_TEST_DEFAULT_AT_REST=1, as a step on flow core unit shard 1 (170 passed locally).

Durable resume and authority in the default mode (7f4f5b5, 8e6bb2d, d2cbdf2). With encryption on by default, a durable resume could not prove its executor outcome. Five things in this area assumed plaintext:

  • DurableAuthority.prove_executor_outcome and the terminal check hashed the physical report.json, which an encrypted run doesn't have. Both now hash the plaintext read through the sealed set, the same bytes the continuation fenced, and an unreadable report gives no proof.
  • A durable leg cut off before its writer finalized left an encrypted run that no later writer could reopen. A resuming writer now authenticates the header, then adopts each earlier file only if it authenticates under the set's key at its own path; anything else is refused.
  • CheckpointStore fixed its key when constructed, so a store made before its run became an encrypted set used the wrong key. It now looks up the run's key when used.
  • My previous push made was_compensated treat an unfinalized run as compensated, which refused legitimate resumes. It now checks for the marker in either form without opening the set.
  • The attended reject path rewrites the report through the sealed set.

New test: test_a_run_cut_off_before_finalizing_resumes_into_the_same_set. The CI step on shard 1 now also runs, under OPENADAPT_TEST_DEFAULT_AT_REST=1: test_api_step_durable, attended_executor_fence_v13, authoring_authority, continuation_receiver_clock, default_ledger_authority, durable_authority_create, durable_authority_edges_v13, durable_authority_isolation_policy, durable_first_local_delivery, durable_first_local_program_delivery, durable_pipelined_readback, durable_resume_state_binding, durable_runtime, module_durable_authority, realism_durable_resume and tx_atomic_authority. Shard 1 passed at this head.

Still failing in default mode (25 tests in 7 files, not in the CI step). Each one reads or edits a run file directly as plaintext: attended_capability*.json, attended_decisions.json, checkpoints/*.json, pending_escalation.json, steps/*.png, report.json or .attended_program_receipts/*, which are now ciphertext. Or the test plants a plaintext tamper inside an encrypted run. In every case the product refuses: either the file isn't there in plaintext, or the set refuses the plaintext stand-in. Three tests get a different refusal than they expect:

  • test_durable_program::test_program_resume_refuses_a_noncontiguous_checkpoint_history gets first_local_delivery_held.
  • test_attended_source_identity_v13::test_pre_v3_capability_only_supports_non_identity_required_resume gets "capability missing".
  • test_durable_program_history_v13 tamper cases get "plaintext outside its sealed index".

The files: test_attended_actions (7), test_attended_at_rest (1), test_attended_qualification_environment (4), test_attended_source_identity_v13 (3), test_durable_authority_v13 (3), test_durable_program (3), test_durable_program_history_v13 (4).

Full-suite sweep in default mode: not completed. One run with 4 workers reached 72% and then hung in browser tests; I stopped it. A rerun with a per-test timeout never started, because the machine load stayed between 90 and 158 against the limit of 15.

Unrelated CI failure. test_second_factor_terminal.py::test_a_timeout_restores_echo_and_the_next_prompt_gets_its_answer (from #2368) fails on shard 3 on a thread-count assertion (1 == 2). That code doesn't touch encryption at rest.

Testing. Single-process, load under 15. Normal mode: 563 passed before this update, then 260 passed and 2 skipped across the touched suites after it. Default mode: the 170 tests in the new CI step pass. Separately, test_durable_runtime.py::test_durable_resume_projection_failure_keeps_fail_closed_terminal_evidence fails under OPENADAPT_TEST_DEFAULT_AT_REST=1: prove_executor_outcome returns no proof, so it fails closed. That is outside rollback and checkpoints, and I have not investigated it. It passes in normal mode.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 44f7d75

…r device

- rollback writes its compensated marker and difference files through the
  run's sealed set when the run is encrypted (the default), and
  was_compensated reads the marker there; a run whose state can't be read is
  never treated as resumable.
- A key record carried in a header opens silently only with this computer's
  device key. A set that only the recovery code opens (which anyone who read
  recovery.pub.json could make) is refused until the person restores it:
  `openadapt-flow at-rest restore DIR --yes` rewraps it to this device and
  re-stamps the header, or OPENADAPT_RECOVERY_RESTORE=1 reads backups in place.
- CI: flow core unit shard 1 also runs the rollback, checkpoint and key
  suites with OPENADAPT_TEST_DEFAULT_AT_REST=1.
- Regenerate the CLI surface snapshot (at-rest restore) and llms-full.txt.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: ea48b25

- DurableAuthority digests report.json through the run's sealed set (the
  bytes the continuation fenced), so prove_executor_outcome and the terminal
  check no longer fail on every encrypted run.
- A run cut off before its writer finalized (a crash or a killed leg) can be
  carried on: the next writer authenticates the header and adopts each file
  only if it authenticates under the set's key at its own path.
- CheckpointStore resolves the run's key when it is used, so a store made
  before its run became an encrypted set uses the run's key.
- was_compensated checks the marker's presence in either form without
  opening the set (the previous push treated an unfinalized run as
  compensated and refused its resume).
- The attended reject path rewrites the report through the sealed set.
- CI: the default-mode step also runs the durable and authority suites that
  pass in that mode.
…urces

- new_artifact_key moves to sealed_set (at_rest must not import upward).
- A type ignore for the unfinished-run resume key, as on the creation path.
- The checkpoint lifecycle test checks the refusal when the key is used.
- CAPABILITIES.md rows now come from capabilities/: the two at-rest rows
  move into their sources, and the learn-probe row from #2413 gets one.
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: d2cbdf2

…the intended refusal is checked in either mode
…crypted recordings and runs

- AuthoringSession reads and stamps the recording's events.jsonl and
  meta.json, and writes admit.json, through the sealed set (the recorder
  seals by default).
- Runtime validation reads the run report in memory.
- Agent-teach evidence reads the sealed report and frames; writing that
  plaintext evidence folder is logged by default and refused in strict mode.
- Tests: under OPENADAPT_TEST_DEFAULT_AT_REST=1, one at-rest home per
  session (per worker), outside the tests' own directories.
… test isolation

- distill_recording reads an encrypted recording in memory and writes the
  distilled recording encrypted (authoring compile distills by default).
- The agent-teach repair candidate is written through the sealed set.
- Tests: the default-mode skip list (tests/default_at_rest_skips.txt), and
  the sealed lock directory outside the tests' own directories.
# Conflicts:
#	capabilities/CAPABILITIES.md.sha256
…plaintext by design, ledgered

- Run receipts are written for encrypted runs (the default): receipt.json
  stays a structural file of the set, the private openings, card and
  follow-ups are sealed in it, and receipts and follow-ups serialize on a
  lock of their own (sealed_set.side_lock). Verification and the handoff
  list read them through the set.
- The JIT compile agent's capture (recording, draft bundle, signed records)
  is plaintext by design: named on stderr and in the ledger, refused in
  strict mode before recording, with the opt-out held for that capture only.
- distill: a type fix for mypy.
- Tests: the default-mode session home resolves symlinks.
- The JIT capture's plaintext opt-out stack exists from construction, so a
  capture closed without entering still cleans up.
- verify_integrity hashes an encrypted bundle's assets in memory.
- The variant router reads the child run's report through the sealed set.
- The console shows an encrypted run's pending escalation.
- The approver-root pin (a key fingerprint, key directory and roster head,
  written before the run) is a structural file of a run set.
…triaged skips

- tests/default_at_rest_skips.txt: each test skipped under
  OPENADAPT_TEST_DEFAULT_AT_REST=1, with its reason (group a: the test reads
  or plants plaintext and the product correctly refuses; group b, open:
  attended approvals, drafts, business decisions and teach on encrypted
  input). The matcher takes a test, its class or its file.
- flow default at rest joins packages-gate (pull requests only).
- Merge origin/main and regenerate CAPABILITIES.md and llms-full.txt.

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