Skip to content

feat: reproducible compile for the quickstart tutorial bundle - #2881

Merged
abrichr merged 4 commits into
mainfrom
feat/reproducible-tutorial-bundle
Dec 1, 2026
Merged

abrichr merged 4 commits into
mainfrom
feat/reproducible-tutorial-bundle

Conversation

@abrichr

@abrichr abrichr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What

openadapt quickstart now compiles its bundled synthetic MockMed tutorial to the same program bundle on every run, so OpenAdapt Cloud can pin its content digest in RECEIPT_GALLERY_SAMPLE_BUNDLE_DIGESTS.

Before this change, two runs of 1.26.0 gave different digests (07135270… and 310ba370…). The only differences were the workflow's created_at and recording_id, the identity-template salt and every hash derived from it, and the layout fingerprint's scale_landmarks.salt and its hashes.

How

  • compile_recording(..., reproducible_seed: bytes | None = None). This is an opt-in for synthetic recordings. With a seed, both per-bundle salts come from HMAC-SHA256(seed, domain + purpose), truncated to the same 16-byte hex format, and created_at is fixed to 1970-01-01T00:00:00+00:00. recording_id is derived from the seed in the recorder's 32-hex format.
  • Without a seed, salts stay fresh and random. OPENADAPT_FLOW_IDENTITY_SALT still takes precedence over a seed.
  • compute_content_digest and what it covers are unchanged.
  • recording_id is not a join key. Nothing looks a recording up by it: it is used for wf_<id> names in authoring and handoff, a teach prefix and a codegen constant. Deriving it in the compiler leaves the recorder and meta.json alone. As a result, every quickstart bundle of a release shares one recording_id, and so one wf_<id>.
  • The launcher passes a constant seed only for the bundled tutorial (TUTORIAL_REPRODUCIBLE_SEED). It first checks that the installed compiler accepts the keyword, so an older openadapt-flow compiles as before.
  • The engine stays generic: check_engine_generality.py passes.

Evidence

Headless openadapt quickstart runs from this branch on macOS:

Path Runs content_digest
Encrypted at rest (default) 2 runs with the machine key, 1 with a fresh OPENADAPT_BUNDLE_KEY 0415ae8cad2b953670f77c15e7cba42d556475af3f0c12ecf5fdcdf84a2a26b6
OPENADAPT_ENCRYPT_AT_REST=0 2 0b408250a5e5a95763323dc81563eda1c19ee06fc82321ac9dff3ab29e321a59

The two paths differ because encrypted is part of the program. The digest does not depend on the key.

In each run, every report carries the manifest digest as bundle_content_digest: run-1 (the checked run) and the three restart reports, including the run killed mid-batch. The public card (receipt.card.json) carries the same value as predicate.program.version_sha256 and as its bundle subject. program.id is prog-7f5b6f0dccd7811e in all runs.

Cloud note

The pinned digest belongs to a release. It changes whenever the tutorial app, the demonstration or the compiler output changes, so any release that changes it needs its new digest added. This is noted in packages/flow/docs/TUTORIAL.md.

Not covered

  • Only macOS headless runs were measured. A headed (--watch) run uses a different Chromium build, and another OS renders fonts differently. Either can change template PNG bytes and so the digest. Cloud may need one pinned digest per platform.
  • openadapt-flow tutorial and demo still use random salts. Induction (phi_free_program_identity) is not given the seed.
  • A launcher installed with an openadapt-flow release older than this change compiles as before, with random digests and no warning. Pinning needs the flow release that contains this change. Consider raising the launcher's openadapt-flow floor at that release.

Tests

  • New: packages/flow/tests/test_reproducible_compile.py and tests/test_quickstart_reproducible.py.
  • Flow tests: identity_template, layout_drift, render_scale, compiler, phi_governance and the new file. 193 pass. Manifest and digest tests (bundle_schema_v2, collateral hashes, job_authoring_schema3, program_sections, and the integrity, sealed_set and tutorial files): 176 passed. 1 fails: test_layout_drift.py::test_real_render[kw3-font_size_changed] fails the same way on origin/main on this machine, because it depends on local font rendering.
  • Launcher quickstart tests: 137 passed, 1 skipped.

compile_recording takes an opt-in reproducible_seed. With it, the
identity-template salt and the layout-fingerprint landmark salt are
derived from the seed (HMAC-SHA256, same 16-byte hex format), created_at
is fixed, and recording_id is derived from the seed. Without it, salts
stay fresh and random. OPENADAPT_FLOW_IDENTITY_SALT still wins.

openadapt quickstart passes a constant seed for its bundled synthetic
MockMed tutorial, so every run of a release compiles the same bundle and
OpenAdapt Cloud can pin its content digest. Older compilers without the
keyword compile as before.
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: a11466f

I reviewed this exact head. I am not merging or pushing.

The change is an opt-in reproducible_seed on compile_recording / _compile_recording, plus a launcher pass of a constant seed only for the bundled synthetic tutorial. I focused on the three questions in the review request.

No real recording gets a seeded, linkable salt on the default path

Without a seed, new_salt_hex still returns 16 fresh random bytes. The only production caller that passes a seed is openadapt/quickstart/engine.py, and only for the bundled tutorial (TUTORIAL_REPRODUCIBLE_SEED), after _compiler_accepts("reproducible_seed") checks the inner compiler. An older openadapt-flow without the keyword compiles as before, with random salts. Every other compile_recording caller I searched leaves the argument unset. An empty or non-bytes seed is refused. The seed is a public constant and is documented as safe only because the tutorial data is synthetic; anyone who knows it can test guesses against the salted hashes, so it must not be reused for a real recording.

There is no mechanical "synthetic recordings only" guard on the keyword itself. A later caller could pass a seed for a real recording. That is a footgun, not a default-path leak, and I am not treating it as a blocker.

OPENADAPT_FLOW_IDENTITY_SALT still wins over a seed

new_salt_hex checks the env var first and returns an empty in-bundle salt when it is set, before any seed is used. Both the identity-template salt (purpose="identity") and the layout-fingerprint landmark salt (purpose="scale-landmarks", via render_scale.new_salt_hex) go through that function. test_external_salt_still_wins_over_a_seed pins this.

Fixed recording_id and created_at are not used as unique lookup keys

A seeded compile sets Workflow.created_at to the fixed 1970-01-01T00:00:00+00:00 and derives recording_id as HMAC-SHA256(seed, "openadapt-flow/recording-id/v1") truncated to 32 hex characters, leaving the recording's meta.json unchanged. I could not find a Flow path that looks a recording up by this recording_id. It is used for wf_<id> names in authoring and handoff, a teach prefix, and a codegen constant. Sharing one wf_<id> across every quickstart bundle of a release is therefore a naming consequence, not a join-key collision. The recorder still writes a fresh id and time into meta.json. The 32-hex derived id is the same width as uuid4().hex, so a chance collision with an unrelated recording id is not a practical concern.

Generality gate

python packages/flow/scripts/check_engine_generality.py at this head reported "Engine generality OK (7 baseline hits left)". The compiler and salt helpers stay generic; only the launcher names the bundled tutorial.

Tests I ran

  • packages/flow/tests/test_reproducible_compile.py: 8 passed, including same-seed digest stability, unseeded fresh salts, env-salt precedence, domain-separated purposes, and bad-seed refusal.
  • tests/test_quickstart_reproducible.py: 2 passed (the tutorial compile passes the seed; an older compiler without the keyword does not).

CI at this head

GTK and freerdp checks are green. packages / verify clean install and quickstart is green. Still in progress when I reviewed: flow core unit and default-at-rest shards, flow core critical, verify facade, and Windows replay. review-verdict is red because this is the first review.

launcher / run-ci (ubuntu-latest, 3.12) is red on tests/test_flow_shards.py::test_the_durations_file_covers_most_unit_files (834 >= 0.8 * 1043). That is the inherited durations-file gap already noted on #2830; this PR does not touch flow_test_durations.json. I am not treating it as a regression from this change, and I am not merging.

Limitations, not blockers

  • compiler.induction.phi_free_program_identity and submit_binding.decide_form_identity still call new_salt_hex() without a seed. Those paths are not the single-recording compile_recording the quickstart uses; they are disclosed in the PR as not covered. If a later tutorial compile started emitting form-identity salts, the digest would stop being stable until those calls were seeded too.
  • A headed (--watch) run or another OS can still change screenshot bytes and therefore the digest, as the PR already says.
  • Pinning in Cloud needs the flow release that contains this change.

@abrichr
abrichr enabled auto-merge December 1, 2026 14:56
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 6dc460b

I re-reviewed this exact head (R2 after my APPROVE at a11466fcd21e). I am not approving, and I will not merge or push.

The only code change since that APPROVE is one line in scripts/ci/flow_test_durations.json: tests/test_reproducible_compile.py at 3.9 s. That line is correct, and tests/test_flow_shards.py passed (13). The product questions I already approved (no default-path seeded salt on a real recording, OPENADAPT_FLOW_IDENTITY_SALT still wins, fixed recording_id / created_at are not unique lookup keys) are unchanged.

Blocker: this PR's own compile tests fail under default at rest

packages / flow default at rest (shard 1/4) is red, and that is what turns packages-gate, ci and run-ci red:

  • test_same_seed_gives_the_same_digest — AssertionError: the fixture must exercise the layout-fingerprint salt (assert '')
  • test_no_seed_keeps_fresh_salts_and_the_recording_id — assert ('') at assert scale1 and scale1 != scale2

I reproduced both locally with OPENADAPT_TEST_DEFAULT_AT_REST=1. The same file is 8 passed when the suite's plaintext-at-rest opt-out is on.

This is not a missing fingerprint. _salts uses Path.is_file() and Path.read_text() on templates/layout_fingerprint.json. Under the product default the bundle is sealed, so that plaintext path is not a file. A probe at this head showed sealed_set.is_file(path) is true, sealed_set.read_text returns a 32-hex scale_landmarks.salt, and the in-memory identity-template salts are present. The helper still returns scale="". That is exactly the class of plaintext-assuming reader the default-at-rest suite exists to catch.

These tests already existed at a11466fc; default-at-rest on that head was cancelled when this commit was pushed, so the failure only became visible here. The durations line did not cause the bug, but this head is not green until the tests read the sealed asset the way the compiler writes it (openadapt_flow.sealed_set).

Generality gate

python packages/flow/scripts/check_engine_generality.py at this head reported "Engine generality OK (7 baseline hits left)".

Tests I ran

  • packages/flow/tests/test_reproducible_compile.py, tests/test_quickstart_reproducible.py, tests/test_flow_shards.py with the suite plaintext opt-out: 23 passed.
  • packages/flow/tests/test_reproducible_compile.py with OPENADAPT_TEST_DEFAULT_AT_REST=1: 2 failed, 6 passed, same two assertions as CI.

CI at this head

Green: GTK, freerdp, packages / verify clean install and quickstart, flow core unit and critical, and the other default-at-rest shards. Red: default-at-rest shard 1, then packages-gate, ci and run-ci. review-verdict is red because this head has no review yet. I am not merging.

@abrichr
abrichr added this pull request to the merge queue Dec 1, 2026
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 1fc0afb

I re-reviewed this exact head (R3 after REQUEST CHANGES at 6dc460baaf57). I am not merging or pushing.

The only code change since that REQUEST CHANGES is in packages/flow/tests/test_reproducible_compile.py: _salts now reads templates/layout_fingerprint.json through openadapt_flow.sealed_set (is_file / read_text), which decrypts the asset under the default at-rest policy and still reads plaintext when the suite opts out. No product code changed.

I ran tests/test_reproducible_compile.py at this head: 8 passed with OPENADAPT_TEST_DEFAULT_AT_REST=1, and 8 passed without it. The two assertions that failed at 6dc460ba (test_same_seed_gives_the_same_digest and test_no_seed_keeps_fresh_salts_and_the_recording_id) now both recover a 32-hex scale_landmarks.salt.

The product questions I already approved at a11466fcd21e (no default-path seeded salt on a real recording, OPENADAPT_FLOW_IDENTITY_SALT still wins, and the fixed recording_id / created_at are not unique lookup keys) are unchanged.

CI

At this head, required package jobs are green (30 success, 24 skipped). The only failures are review-verdict / Evaluate review verdict, which need this comment.

Generality gate

No engine source change in this commit. The earlier generality result still applies.

Merged via the queue into main with commit 345acc9 Dec 1, 2026
55 of 56 checks passed
@abrichr
abrichr deleted the feat/reproducible-tutorial-bundle branch December 1, 2026 17:33
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