Skip to content

fix(flow): wrap the same task again, exit 0 on admission, one plaintext line - #2864

Open
abrichr wants to merge 3 commits into
mainfrom
fix/wrap-repeat-canary-exit-noise
Open

abrichr wants to merge 3 commits into
mainfrom
fix/wrap-repeat-canary-exit-noise

Conversation

@abrichr

@abrichr abrichr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Problem

The Nov 30 staging run of self-serve openadapt wrap --person admitted a notes program, but it showed three rough edges:

  1. Canary values collide across wraps. canary_params are fixed. When you wrap the same task again on the same app, the second canary finds the first canary's record too and halts: "2 records match the target selector but exactly 1 was expected".
  2. Admission exits 1. A retry that only admits the kept draft ends status: admitted, verified: false, and wrap returned 0 if verified else 1.
  3. Prompt noise. A run prints one plaintext-at-rest WARNING for each JIT-draft artifact, before and around the two questions.

Change

Canary suffix (compile_agent/pipeline.py, integrations/agents/{recording,skills}.py)

  • Before each canary, wrap reads the system of record. If a record already matches what the canary's claim would match (an earlier wrap's or attempt's canary), it adds a suffix to one input of that canary: a space, oa and six random hex digits, for example canary note 1 oa3f9c2e. Anything it can't judge (no read, a routed claim, a typed or coded input) counts as a possible match. With no match, the values are saved as written, so a first wrap behaves as before.
  • The suffix goes on the longest public input that every new-record claim in the confirmed checks binds plainly (param, optionally stored). It never goes on:
    • a sign-in input;
    • an input with map, kind or null in its binding (a select's code, a typed value);
    • a value with no letter, an email address or a URL.
  • One input is enough to make the record's match unique. The record check still wants exactly one match.
  • Run 1's values are still compared with the canary values as written.
  • The admission summary and the terminal canary line name the input and the suffix, so the person can find the canary's record.
  • wrap task files turn this on by default. "unique_canaries": false saves the values as written. FirstRunCompiler.admit, compile_first_run and SkillCache default to off, so library callers behave as before.

Exit status (wrap/cli.py)

  • status: admitted exits 0. Admission is reached only after a VERIFIED canary.
  • When verified is false, stderr says this attempt saved nothing with the caller's inputs and an earlier run may have saved them, so check the app before saving the same values again.
  • verified is not changed.
  • docs/WRAP_PUBLISH.md gains an exit-status table, written around what decides the code: verified: true or admitted.

One plaintext line per run (at_rest.py, wrap/cli.py)

  • New at_rest.one_warning_line(). In the block, the first plaintext write prints one line that names it and the ledger path. Later writes get their ledger line only.
  • The state is process-wide behind the existing lock, so writes from the MCP endpoint's threads count too.
  • wrap runs task.call inside the block. --serve is not included.
  • Strict mode still refuses before anything is written, and a write the ledger can't record is still refused.
  • The "Before you record" notice, the scrubber notice and the refuse=False ERROR line are unchanged.

Docs and map: WRAP_PUBLISH.md steps 3 and 4 (new paragraphs only, outside #2837's step-4 hunk) and a new capabilities row, 0158.

Tests

  • tests/test_wrap_rough_edges.py, 24 unit tests:
    • One line and N ledger lines for N writes, and nested blocks still print one line.
    • Strict mode refuses, and a failed ledger write is refused while quiet.
    • When a suffix is needed (an earlier matching record; case and spacing ignored; unknowns count as a match) and which input gets it (map, kind, secret, email, URL and digits are excluded; a map in any claim excludes the input).
    • admit() with a stubbed canary: the suffix lands on the public input, a sign-in input is unchanged, no suffix without an earlier match or with the option off.
    • The terminal canary line names the suffix.
    • The task-file default, the opt-out, and that the setting is not part of the task key.
    • Exit status for each status.
  • tests/e2e/test_wrap_canary_unique_e2e.py, on the real MockMed app with headless Chromium, an outside MCP command and admitter-key admission, never reset between wraps:
    • Two wraps of one task both admit. The first canary is saved as written, and the second gets a suffix.
    • With "unique_canaries": false, the second canary halts on "2 records match the target selector but exactly 1 was expected". This is the staging failure.
    • A CLI retry of that draft with the default setting gives admitted, verified: false, exit 0, the stderr line, and at most one plaintext line. Run 1's note is not saved twice.
  • MockMed's ?idempotency=demo dedupes every save on one fixed key, and both strict policies require that key. So the e2e uses ?fault=ok and the bundled permissive policy to model an app that doesn't dedupe. The canary's record check is the same under every policy.
  • In real default at-rest mode, with fix(flow): confirming a draft's parameters recompiles it in plaintext #2842 merged locally: a CLI first run printed 1 plaintext line (before: the draft line plus one per artifact), and the admit-only retry printed 1.
  • 550 tests pass across the wrap, compile-agent, admit-pipeline, JIT-lifecycle, at-rest, sealed-at-rest, skill-cache and e2e suites, run 4-way in parallel. One more, test_compile_agent_e2e.py::test_compile_agent_then_replay_with_no_model_calls, hit browser_readiness_unavailable under that load and passed when run alone. ruff and mypy pass on the changed modules, and check_engine_generality.py passes.

Not covered

Review

One review pass at high effort, on this branch. It found:

  • Important, fixed: a suffix on every canary could break a first wrap whose longest plain-bound input accepts only certain text. The suffix now goes on only when a matching record already exists.
  • Nits, fixed:
    • The docs overstated which inputs are skipped.
    • The stderr line claimed a test save on the already-admitted path.
    • The suffix wasn't shown to the person.
    • admit() had no direct unit test.
  • Follow-up, not changed: teach-over-MCP's fixed canary values (listed above).

…xt line

Three edges of self-serve `openadapt wrap` from the Nov 30 staging run:

- Canary values collided across wraps: the second canary found the first
  canary's record too and halted on "2 records match the target selector
  but exactly 1 was expected". Each attempt now adds a short random suffix
  (`oa` + six hex digits) to one text input of its canary: the longest
  public input that every new-record claim binds plainly (never a sign-in
  input, a select's code, a typed value, an email or a URL). The record
  check still wants exactly one. Run 1's values are still compared with
  the values as given. `"unique_canaries": false` keeps them as written.
- A retry that only admitted the kept draft ended `status: admitted,
  verified: false` and exited 1. Admission is reached only after a VERIFIED
  canary, so it now exits 0, with a stderr line that nothing was saved
  with the caller's inputs. WRAP_PUBLISH.md documents the exit statuses.
- A run printed one plaintext-at-rest WARNING per JIT-draft artifact.
  `at_rest.one_warning_line()` prints one line per run (naming the first
  write and the ledger); every write still gets its ledger line, strict
  mode still refuses, and a write the ledger can't record is still refused.
The kept draft exists because the earlier attempt's run 1 already saved,
so the stderr line now says that and asks the person to check the app
instead of pointing at wrap run. The exit-status table is written around
what decides the code (verified, or admitted): a read-back run 1 exits 0
while the program is still a draft or its canary failed. The canary's
stamp key is written only when a suffix was applied, and the new e2e
tests are skipped under the default at-rest lane until #2842 lands.
Review of #2864: a default suffix on every canary could break a first
wrap whose longest plain-bound input only takes certain text (options
stored as labels, a date in words). The suffix now goes on only when the
system of record already has a record the canary's claim would match
(an earlier wrap's or attempt's canary); anything that can't be judged
counts as a possible match. A first wrap saves the values as written.

Also: the admit-only stderr line no longer claims a test save in this
call (the already-admitted path has none), the terminal canary line names
the input and suffix, the docs say exactly which inputs are skipped, and
admit() has unit tests with a stubbed canary (secret inputs unchanged).
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: dbbd3c4

I found no blocker in the stated fix. A second wrap of the same task suffixes one public free-text canary input only when a record already matches what that canary would save. A first wrap with no matching record is saved as written. status: admitted exits 0 even when verified is false, and stderr says this attempt saved nothing with the caller's inputs. Other unverified outcomes still exit 1. Inside one_warning_line(), the first plaintext write prints one line; later writes in the block still go to the ledger, and strict mode still refuses before anything is written.

Behavior

_repeats_run1 and _duplicate_canary_rows run on the unsuffixed rows, so the suffix cannot hide a canary that repeats run 1. _canary_would_collide treats an unreadable check file, a missing system-of-record read, a routed claim, or a typed/coded binding as a possible match, which is fail-closed: the suffix is attempted. _canary_stamp_param will not stamp a secret, a sign-in input, an email, a URL, a digits-only value, or an input whose binding carries map, kind or null. The stamp recorded on the canary entry is the parameter name and suffix only, never the value.

_exit_status returns 0 for verified is True first, then for status == "admitted". A later skill run that fails its record check uses statuses such as RECORD_CHECK_FAILED, not admitted, so it still exits 1. I also checked that a later fill of an already-admitted program is not turned into an exit 0 by this helper.

Limitation, not a blocker for this head

If a collision is detected but no input is stampable, the canary is left as written and can still halt on "2 records match". That is fail-closed, and it is the same class of halt this PR cannot suffix away. Teach-over-MCP admission still uses fixed canary values, as the description already notes. I did not run the two MockMed/Chromium e2e tests.

Tests at this head (Linux, Python 3.12)

  • tests/test_wrap_rough_edges.py: 24 passed in 0.81s. ruff check and ruff format --check were clean on the eight changed Python files.
  • With tests/test_at_rest_default.py, tests/test_at_rest_review_round3.py, tests/test_compile_agent.py, tests/test_compile_agent_canary_values.py, tests/test_wrap_cli.py, tests/test_wrap_publish.py and tests/test_wrap.py: 266 passed, 1 skipped.
  • packages/flow/scripts/check_engine_generality.py reported "Engine generality OK (7 baseline hits left)". packages/flow/scripts/check_verdict_folds.py reported "Verdict folds OK (2615 baseline folds left)".

Generality gate: point 1 passes; check_engine_generality.py is clean, and the new suffix logic is app-agnostic. Point 2 passes for the wrap-task collision this PR is about: any wrap task with unique_canaries (the default) gets the suffix when a match already exists and one input can take it. The teach-over-MCP path is an explicit follow-up, not a hole in this class.

CI at this head: flow core unit shard 3/4 and default-at-rest shard 3/4 are red on tests/test_quickstart_encrypted.py::test_quickstart_on_a_fresh_machine_seals_every_run: TypeError: run_quickstart() got an unexpected keyword argument 'break_it'. That test is unchanged here. It is the inherited break from #2840; #2866 already fixed it on main. This branch is 50 commits behind origin/main (9f3a947b4, including #2842 and #2866). GitHub still reports the PR mergeable. I am not merging main into this branch.

Please merge main so CI can go green, and then drop the two tests/e2e/test_wrap_canary_unique_e2e.py lines from tests/default_at_rest_skips.txt, as the description already says to do once #2842 has landed.

I didn't push to this branch, and I won't merge it.

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