Skip to content

feat(flow): wait for a person at a sign-in's second factor - #2363

Merged
abrichr merged 14 commits into
mainfrom
claude/remote-2fa-handoff
Nov 22, 2026
Merged

abrichr merged 14 commits into
mainfrom
claude/remote-2fa-handoff

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Some apps ask for a second factor after the password: a code sent by text message or email, an authenticator code, or a push approval. Until now a program could only stop there. With this change the run waits at that step for a person, types the code once into the field it checked, and keeps the code nowhere. If anything about the field, the answer or the backend can't be established, the step stops before typing.

What changes

  • Program. A second factor is its own action, second_factor (ActionKind.SECOND_FACTOR), and Step.one_time names its kind: code or approval. An older runtime doesn't know the action, so it refuses to load the bundle. It can't skip an approval or type an environment value into a code field (checked by loading both kinds with origin/main's ir.py). The step validator allows only a short list of fields, so no anchor, text, param, secret flag, key, API binding, effects or dialog response can route the step around the person. Other steps serialize exactly as before.
  • One handoff for recording and replay (openadapt_flow/runtime/second_factor_step.py):
    1. Claim the step for this run before anyone is asked, so a retry or a loop never asks or types again.
    2. Bind the focused element. It must be an empty text, tel, password or search input whose autocomplete names one-time-code, and it must take at least 4 characters. The page is made to draw every such field as dots (-webkit-text-security), on the element and in a stylesheet every later document gets, and the field must report that it is masked (openadapt_flow/backends/one_time_field.py).
    3. Ask the source. The deadline is checked again when the answer arrives, for every source.
    4. Just before typing, the same element must still have focus, be empty, be masked and take the whole code.
    5. Fill the code into that element once. It is never retried.
    6. Read back the length only. A mismatch stops the run as second_factor_unverified.
      Each check is held, refuted or not checked, as in the verdict kernel of feat(flow): one verdict kernel, a fail-open harness and a fold ratchet #2476; only held proceeds. When that kernel lands, the local Status becomes an alias of it.
  • Where the code can't go. No screenshot shows it: recorded frames, model-facing screenshots, gate frames and visual transition frames all show dots, and replay saves black frames for such a program as well. A program that keeps exact frames for a visual transition refuses a code step before asking. The compile agent's page listing withholds the value of one-time-code and password fields. The code lives in a OneTimeCode holder that can't be printed, pickled or copied and hands its value out once.
  • Sources. OPENADAPT_SECOND_FACTOR_URL with OPENADAPT_RUNNER_TOKEN (a runner's control plane; the code is sealed in the person's browser to a one-step P-256 key), or OPENADAPT_SECOND_FACTOR_COMMAND (a local command, no shell). The HTTP source checks the deadline before each poll and again when the poll returns. An answer with a line break inside it is refused, not joined. A cached run's MCP child gets only the selected source's variables; the run token goes only with the URL.
  • Sign-in rule. A form holding a username, a password and a code signs in. A form holding only a code signs in once, right after a username-and-password sign-in, with nothing between them but the click that focuses the code field. Any other code-only form (a second code page, or a "Verify" that confirms a payment) keeps the submit escalation.
  • Recording. The browser backend reports a field whose autocomplete names one-time-code. During openadapt wrap's first run the agent types ⟦one-time-code⟧ there. The recorder discards that text and runs the handoff. A declared input typed into a code field, or the marker typed anywhere else, is refused before typing.
  • Cached runs. _call_skill passes the current stderr to the MCP stdio client. The client's default is the stream bound when mcp was first imported; when that stream had been closed since, spawning the child failed, which is what made the wrap e2e fail with cached_tool_result after another test.

Refusal codes: second_factor_unavailable, second_factor_timeout, second_factor_declined, second_factor_invalid, second_factor_unbound (the field or backend can't be bound), and second_factor_unverified (typed once, read-back failed; a safety halt). All but the last stop before typing.

Limits

  • Only the local browser backend can take a code. Other backends refuse a code step with second_factor_unbound; an approval works on any backend.
  • A field split into one box per character is refused.
  • A code page that submits itself as the last character lands can't be read back, so under strict evidence that run is completed, not VERIFIED.
  • The recorder doesn't detect push approvals; an approval step has to be added by hand.

Codex review at fddab5f, mapped to fixes

# Finding Fix
1 The recording agent sees the OTP in the page listing The observe JS withholds one-time-code and password values; a headless test checks the listing after a code is filled
2 Gate and transition screenshots can show the OTP The field is masked in the page before the code is filled, and the mask is verified on the bound element; two codes render identical pixels (headless test, four input types). Exact-frame visual transitions refuse a code step before asking
3 The field can change during the handoff, or be prefilled Bind before asking, re-check focus, emptiness and mask just before filling, fill through the bound element handle
4 A retry can type the code twice The step is no longer a TYPE step, so the generic retry and readback never run; the ledger refuses a second ask; inconclusive readback halts. Tests count every delivery
5 Older runners skip approval or type an env value New action value; an older runtime refuses both kinds at load
6 An API binding can bypass the handoff The validator's allow-list refuses api_binding, effects and every other input field
7 Code-only submits are exempt Exempt once, only right after a username-and-password sign-in
8 Late HTTP answers are accepted The deadline is checked before and after each poll, and again in obtain for every source
9 Multiline codes are joined Internal line breaks are refused before separators are removed
10 The ir schema snapshot is stale Regenerated for the new action and field
P2 The run token reaches children that don't use it source_env forwards the token only with the URL

Tests

  • tests/test_second_factor.py (58): every source and refusal, the command heartbeat, late answers for every source and for the HTTP poll, multi-line answers, the step shape and the allow-list, the older-runtime action set, the handoff's bind, re-check, split-box, type-once and read-back rules with a field that counts deliveries, replay, recording, the sign-in arming rule, and the token's scope.
  • tests/test_second_factor_browser.py (15, headless Chromium): two codes of the same length render the same pixels for text, tel, password and search inputs; number, date and email inputs are refused; a later document masks its field; focus taken during the wait, a prefilled field, an ordinary field and a split-box field are refused; a dialog that steals focus gets nothing; a self-submitting page gets the code once; the agent's listing never holds the code.
  • tests/e2e/test_wrap_second_factor_e2e.py passes through the real wrap path (first run, canary, admission, publish staging, a cached run that reads its note back VERIFIED, and a declined run that halts at the code step), with a byte scan for the TOTP secret and recent codes. It ran with mcp 2.3.0 in a scratch environment, alone and after test_wrap_sign_in_e2e.py.
  • Also run locally: the import-layer, import-direction, import-surface and schema-surface suites, the file-size ratchet, the engine generality check, mypy on the changed modules, and the recorder, compiler, compile-agent, replayer, readback, risk, policy, execution-profile, action-evidence, interop, emit, teach-scope and wrap suites (1,136 passed). test_rl_env_typed.py fails locally only because openenv isn't installed here.

replayer.py and ir.py stay within their budgets; replayer.py's is lowered to 19219. The Cloud side (request routes, dashboard page, email, runner wiring) is in openadapt-cloud behind SECOND_FACTOR_HANDOFF_ENABLED. Its runner detects these steps by one_time alone, so it still finds them. Its test fixture uses the old TYPE shape, and hosted runners need a Flow release with this action before such bundles run: OpenAdaptAI/openadapt-cloud#552.

A step marked one_time (code or approval) asks the configured source when it
runs: the runner's control plane (the code sealed in the person's browser to a
one-step P-256 key) or a local command. The code is typed once and kept
nowhere. No source, no answer in time, a decline or a malformed answer stops
the step before typing with a closed second_factor_* code. The wrap recorder
turns an autocomplete=one-time-code field into such a step.
…odules

Raises the replayer budget by 7 lines and ir.py by 3 for the two hooks and
the Step field; lowers playwright_backend.py to its new size.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 682cb3e

I will not merge.

Author is GitHub abrichr (Claude 2FA-handoff agent), not Grok. I reviewed second_factor.py, the recorder/replayer/compiler hooks, and the tests on the box. I could not re-run packages/flow/tests/test_second_factor.py here (pytest is not installed).

The core fail-closed path is in good shape. No source, a bad or out-of-range timeout, a command or HTTP timeout, decline, a malformed or over-long code, a failed unseal, or a kind mismatch all raise a closed second_factor_* code and the replayer/recorder stop before typing. HttpSource requires HTTPS (or loopback HTTP), a bearer token, and follow_redirects=False. Sealing is one-step P-256 ECDH, HKDF-SHA256 with openadapt.second-factor/v1: plus the request id, and AES-256-GCM with the request id as AAD; unseal errors are generic. Existing steps omit one_time when unset. one_time_code is not a workflow or hosted parameter. Recording events keep the param and drop the text; has_one_time_steps blacks persisted frames even when secret_params is empty. Tests I read cover those leak and refusal cases (I did not re-execute them).

[P2] The hosted source cannot run through the compiled-skill path that this PR itself wires up. SOURCE_ENV_KEYS is (URL_ENV, COMMAND_ENV, TIMEOUT_ENV) and omits TOKEN_ENV (OPENADAPT_RUNNER_TOKEN). _call_skill in integrations/agents/skills.py starts the stdio MCP server with get_default_environment() plus only those keys. A child that receives OPENADAPT_SECOND_FACTOR_URL therefore does not receive the runner token, and HttpSource fails closed with second_factor_unavailable. That is the control-plane source Cloud #489 depends on; the local command source still forwards. Please add TOKEN_ENV to SOURCE_ENV_KEYS and a test that the skill-child environment includes the token whenever the URL is set.

P3: wrap detection of a code field is only autocomplete containing one-time-code. Pages that use name=otp or similar without that token will not take this path.

Review only; do not merge.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: fe61366

I will not merge.

This is a delta re-review of the P2 from my REQUEST CHANGES at 682cb3e17c6f29cbbf4142cf1e7a87a75f4d5382. The only change since that head is the token-forwarding fix. SOURCE_ENV_KEYS now includes OPENADAPT_RUNNER_TOKEN. source_env() copies only those keys that are set. _call_skill starts the stdio MCP child with get_default_environment() plus source_env(). test_a_cached_runs_child_gets_the_url_with_its_run_token intercepts the stdio client and checks that the child receives the control-plane URL and the run token, and that UNRELATED_SECRET does not. The hosted Modal path was already passing the token in the run environment and is unchanged. Docs now say a cached wrap run forwards the token when it is set.

The current GitHub merge state of this head is CONFLICTING/DIRTY, so it cannot land as-is. That is separate from the P2, which is fixed.

Review only; do not merge.

…doff

# Conflicts:
#	packages/flow/docs/design/DECOMPOSITION.md
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 3dca071

I will not merge.

This is a delta re-review of my APPROVE at fe61366e1bf43a40e3efb5c91b2d1fc047634d34, after a merge of current main (d10f0a2b9, which already carries ## v3.4.0 (2026-11-20)). Author is still abrichr, not Grok.

The P2 fix is intact: SOURCE_ENV_KEYS still includes OPENADAPT_RUNNER_TOKEN, source_env() still feeds the cached-run MCP child, and test_a_cached_runs_child_gets_the_url_with_its_run_token is still there. The second-factor hooks in replayer.py are still present. The v3.4.0 notes already on main (hosted admission, admitter keys, managed-run verification, #2335, #2341) are preserved. The one recorded conflict, packages/flow/docs/design/DECOMPOSITION.md, is a size-ratchet resolution (replayer.py 20101, which matches the file). No conflict markers.

[P2] The second-factor changelog entry was folded into the already-dated v3.4.0 section. Main's Flow changelog and packages/flow/pyproject.toml already name v3.4.0 (2026-11-20). This merge renamed the branch's ## Unreleased heading to ## v3.4.0 and left the new feature in that section, so the notes for work that is not in the cut 3.4.0 now read as if they shipped with it. Please restore ## Unreleased above ## v3.4.0 (2026-11-20) and move this PR's second-factor entry (and only that new entry) under Unreleased, leaving the published 3.4.0 section as it is on main.

Review only; do not merge.

# Conflicts:
#	packages/flow/docs/design/DECOMPOSITION.md
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 8f746a9

Delta re-review of my REQUEST CHANGES at 3dca071da285a310fb3eee6425b37688b1910fee, after another merge of current main. Author is still GitHub abrichr, not Grok. Review only; I am not merging.

The changelog P2 is addressed. main now holds the cut with ## v3.4.0 (held until PyPI serves openadapt-privacy 1.1.4), and this head uses the same heading. The second-factor notes sit in that held section, not under a dated shipped 3.4.0. The earlier P2 (token forwarding) is still intact: SOURCE_ENV_KEYS still includes OPENADAPT_RUNNER_TOKEN, and the second-factor hooks in replayer.py are still present.

The recorded conflict is still only packages/flow/docs/design/DECOMPOSITION.md. The resolved size-ratchet rows are replayer.py 20097 and ir.py 6838, which match the line counts of those files on this head.

# Conflicts:
#	packages/flow/docs/design/DECOMPOSITION.md
Budgets no longer rise (#2430). The environment-secret lookup for a secret
TYPE step moves from the replayer into secret_inputs.step_secret_text, so
the one-time code branch adds no lines. ir.Step's serializer drops unset
optional fields in one loop, and the one_time validator is bound beside
its field. The replayer imports runtime_value itself rather than the
second_factor module, so runtime/__init__'s lazy Replayer export is no new
import-layer debt site. replayer.py budget lowered to 19224.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: fddab5f

P1. A one-time code can be typed twice. The replayer delivers the value and enables ordinary text retry on unguarded web input. Its readback helper can then deliver the same value again. An unchanged field after delivery does not establish that the application never received the first input. Disable the second delivery for one-time steps and halt on inconclusive readback. Cover the inconclusive result with a synthetic backend that counts input calls. Replay call · Second delivery

P2. A response returned after the runner's deadline still resumes the step. The polling loop returns an answered code or confirmed approval before checking its monotonic deadline. This can happen through ordinary transport delay. Apply the configured deadline before polling and again when a response arrives. The existing fake clock can cover both response kinds without a live sign-in. Polling loop

P2. Cached tasks receive a runner credential when their selected source does not use it. Every cached skill gets the result of source_env(), which copies OPENADAPT_RUNNER_TOKEN whenever it is set. The local-command and unconfigured paths do not consume that token. Limit forwarding to the selected remote source. Extend the existing child-environment test to verify absence with either of the other configurations. Child environment · Environment selection

I compared the main merge and refactor with Grok's approved 8f746a9. The dedicated code source, secret-free workflow parameters, frame blackout and closed decline handling remain present. I reviewed the source and existing assertions. I did not run a sign-in or repeat the test suites.

  1. The changes are application-independent.
  2. Delivery count, deadline and credential scope must hold across capture and replay wherever the corresponding source is used.
  3. The recorded end-to-end evidence uses a synthetic Chromium app and a local code source. The remote control-plane fixture and browser sealing vector cover the protocol. This review establishes no live hosted or held-out application result.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Handoff note for the second-factor rework (merge sweep). No verdict here.

State at head fddab5f:

  • 1711925 merges origin/main. The only conflict was the size-budget table in packages/flow/docs/design/DECOMPOSITION.md, resolved to main's values.
  • fddab5f keeps ir.py and runtime/replayer.py within their budgets, which can no longer rise (ci(ratchet): size budgets never rise; dropping the row of an existing file fails #2430):
    • The environment-secret lookup for a secret TYPE step moved into secret_inputs.step_secret_text, with the same messages and order.
    • ir.Step's serializer now drops unset optional fields in one loop.
    • The one_time validator is now bound beside its field.
    • The replayer imports runtime_value directly instead of the second_factor module. That clears the new import-layer debt site at runtime/__init__.py:124, which caused the CI import-layer failure.
    • The replayer.py budget is lowered to 19224.
  • Verified locally: the import-layer debt check, the file-size ratchet, test_second_factor, test_secret_params, test_replayer, test_policy, and mypy on the touched files all pass. Codex compared 108 synthetic env-secret cases against 8f746a9 (same lookup, overrides, text, refusal order and messages).
  • Still failing locally, and also failing before my commit: tests/e2e/test_wrap_second_factor_e2e.py::test_an_authenticator_code_comes_from_a_person_and_never_persists. The second run is refused with cached_tool_result. This test runs only nightly in CI.

The Codex review at this head is REQUEST CHANGES, with 10 findings (see the Codex comment above for file:line references):

  1. The recording agent can see the OTP in the page listing, through autocomplete="one-time-code" input values.
  2. Gate screenshots and graph-replay transition frames can persist a visible OTP.
  3. The receiving field can change during the handoff (focus or a dialog), or be prefilled.
  4. A browser TYPE retry can type the same OTP twice.
  5. Older runners ignore one_time: an approval WAIT passes unanswered, and a code step types an env value.
  6. An API-bound one-time step can bypass the handoff.
  7. A code-only submit is exempt from submit-risk escalation, even for a non-sign-in "Verify".
  8. The HTTP source accepts answers that arrive after the deadline.
  9. A multiline code is normalised into a different valid-looking code.
  10. The IR schema snapshot fails on Pydantic 2.13.4 (six models, including Step and Workflow) and needs regenerating once the contract settles.

The Codex review at fddab5f found ten ways the one-time-code path could
leak a code, type it twice, type it into the wrong field or be skipped.
They share causes, so this replaces the per-path hooks with one handoff
that the recorder and the replayer both run
(openadapt_flow/runtime/second_factor_step.py):

- claim the step for this run before asking (a retry or loop never asks
  or types again);
- bind the focused element, which must be an empty
  autocomplete="one-time-code" input, and make the page draw it as dots
  (openadapt_flow/backends/one_time_field.py), so no screenshot, gate
  frame, transition frame or model image shows the code;
- ask the source, with the deadline checked again when the answer
  arrives, for every source;
- re-check, just before typing, that the same element still has focus,
  is empty and is masked;
- type once through the bound element handle, never retried;
- read back the length only, and halt as second_factor_unverified when
  it does not match.

The step is now its own action, ActionKind.SECOND_FACTOR, with one_time
naming code or approval. An older runtime refuses the bundle (checked
against origin/main's ir.py for both kinds) instead of skipping an
approval or typing an environment value. The step validator refuses any
field outside a short allow-list, so an API binding, effects, an anchor,
text or a param cannot route around the person.

Also:
- the compile agent's page listing withholds the value of one-time-code
  and password fields;
- a code-only form's submit counts as a sign-in only right after a
  username-and-password sign-in;
- normalize_code refuses an answer with an internal line break;
- source_env forwards the run token only with the control-plane URL;
- _call_skill passes the current stderr to the MCP stdio client, whose
  default can be a stream closed since mcp was imported (the cause of the
  order-dependent cached_tool_result failure in the wrap e2e);
- the changelog entry moves under Unreleased, the ir schema snapshot is
  regenerated, and replayer.py's budget is lowered to 19219.
abrichr added a commit that referenced this pull request Nov 22, 2026
…e deadline

Merges 2c4b0d0 (the class-based handoff, its own action, and current
main). The terminal source moves to openadapt_flow/second_factor_terminal.py
and no longer reads in a background thread:

- the read runs in the calling thread with select under the step's
  deadline, so nothing keeps reading after a timeout and the next prompt
  gets its answer;
- echo is turned off for a code read only and restored in finally,
  whatever ends the read;
- input typed before the prompt is discarded (tcflush), so an earlier
  keystroke cannot answer it;
- the source is used only on POSIX terminals; elsewhere a run with no
  other source stops before typing, as before.

The changelog entries for both pull requests sit under Unreleased, above the
published 3.4.0 section. The import-layer debt site that failed this
stack's shard 2 (runtime/__init__.py:124) is gone at this head; the
runtime handoff imports names from openadapt_flow.second_factor rather
than the module through the package.
…ode-only sign-in once

- The code is filled into the bound element instead of typed key by key,
  so no character can reach another field (a dialog that took focus, or
  the next box of an auto-advancing field).
- A field that takes fewer than 4 characters is refused before anyone is
  asked, and one shorter than the code is refused before typing: one box
  per character would spill the code into unbound, unmasked boxes.
- Only text, tel, password and search inputs count as code fields, since
  only they draw -webkit-text-security; number, date and email inputs are
  refused. The headless pixel test now runs for each allowed type.
- A code-only form's submit is exempt from the submit escalation once,
  right after a username-and-password sign-in, with at most the focusing
  click between them. A second code page, or browsing first, keeps the
  escalation.
- docs/SECOND_FACTOR.md states the limits: only the local browser backend
  takes a code, split-box fields are refused, and a self-submitting code
  page is completed, not VERIFIED, under strict evidence.
abrichr added a commit that referenced this pull request Nov 22, 2026
… in the pty tests

The pty tests answer once the prompt has been written, instead of after a
fixed delay, so a slow runner only makes them slower. The docs and
CAPABILITIES row say the terminal prompt needs a POSIX terminal; on Windows
a run with no other source stops before typing, as it did before this pull
request's first head.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 907fba3

Author declaration for this head. Claude wrote the changes on this branch, including the rework after the Codex review at fddab5f (2c4b0d0 and 907fba3). The pull request body maps each of Codex's ten findings and its token-scope P2 to its fix.

Local checks on this head, single-process, load under 15:

  • tests/test_second_factor.py 57 passed; tests/test_second_factor_browser.py 15 passed (headless Chromium).
  • tests/e2e/test_wrap_second_factor_e2e.py and tests/e2e/test_wrap_sign_in_e2e.py passed together, in a scratch environment with mcp 2.3.0 (the default local environment has mcp 1.30, where the cached-run half skips).
  • Import layers, import direction, import surface and schema surface: 2,253 passed. The ir snapshot was regenerated for the new action and field.
  • Recorder, compiler, compile-agent, replayer, readback, risk, policy, execution-profile, action-evidence, interop, emit, teach-scope and wrap suites passed. test_rl_env_typed.py fails locally only for a missing openenv.
  • scripts/check_file_size_ratchet.py --base origin/main: no budgeted file grew; replayer.py's budget is lowered to 19219. Engine generality check and mypy on the changed modules: clean. ruff 0.17.0 check and format: clean on every changed file.
  • A bundle with a code step and one with an approval step, loaded with origin/main's ir.py, are both refused at steps.0.action.

Codex is unavailable until Nov 27, so the cross-vendor review for this head is Gemini's.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 907fba3

Gemini run on 907fba3 (gemini-3.1-pro-preview). Codex is unavailable until Nov 27, so this is the cross-vendor review. Gemini received the PR body, the full diff against origin/main for packages/flow (fixtures omitted), the six required properties, and Codex's ten findings at fddab5f plus the token-scope P2. Claude checked the blocker against the code before posting.

Blocker

  1. P2. packages/flow/openadapt_flow/second_factor.py, CommandSource.obtain: no heartbeat while the command waits. It calls heartbeat() once and then blocks in subprocess.run for up to the step's timeout (120 s by default). docs/SECOND_FACTOR.md says the runtime prints a progress line every 20 seconds so a supervisor that ends silent runs leaves this one alone; with a command source it doesn't. The run fails closed (nothing is typed), but a waiting person can lose the run. Fix: run the command with Popen and wait in communicate(timeout=...) slices, calling heartbeat() between them. Verified: the code matches the description.

Non-blocking

  • runtime/second_factor_step.py, _keeps_exact_frames: if the replayer has no _program_guard_uses_frame, every transition counts as frame-keeping. That fails closed and may be stricter than needed for a future replayer.

What Gemini checked and found fixed

All ten Codex findings and the token-scope P2: the listing withholds one-time-code values; the field is masked before the code is filled; focus, emptiness and the mask are re-checked before filling; the new action and the ledger stop a second delivery; older runtimes refuse the action; the allow-list refuses an API binding; the code-only exemption is armed only by a username-and-password sign-in; the HTTP source checks the deadline before and after each poll; internal line breaks are refused; the schema snapshot is updated; the token goes only with the URL. It also checked the injected page scripts (shadow DOM, navigation), evidence classification for code and approval, and that unreadable states and exceptions in the handoff refuse.

Review only; I am not merging.

CommandSource ran the command with subprocess.run, which blocked for the
whole timeout after one heartbeat, so a supervisor that ends silent runs
could end one waiting for a person (Gemini at 907fba3). The command now
runs under Popen and is waited for in heartbeat-sized slices; on the
deadline it is killed and the step stops before typing, as before.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: edd8b1b

Author declaration for this head. Claude wrote the changes on this branch. The only change since 907fba3 fixes the blocker in the Gemini review: CommandSource waits for the command in heartbeat-sized slices under Popen, kills it at the deadline, and stops before typing. A new test checks the heartbeat fires while a command waits.

Local checks on this head: tests/test_second_factor.py and tests/test_second_factor_browser.py 73 passed; tests/e2e/test_wrap_sign_in_e2e.py and tests/e2e/test_wrap_second_factor_e2e.py passed together (mcp 2.3.0 scratch environment); mypy and ruff 0.17.0 clean on the changed files.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: edd8b1b

Gemini run on edd8b1b (gemini-3.1-pro-preview). This delta re-review follows its REQUEST CHANGES at 907fba3. Gemini received the delta 907fba3..edd8b1b.

The blocker is fixed. CommandSource runs the command under Popen and waits in HEARTBEAT_S slices, calling heartbeat() after each one. The overall deadline uses time.monotonic(). At the deadline the command is killed and reaped, and the step stops with second_factor_timeout before typing. OSError still maps to second_factor_unavailable. The new test would fail against the old subprocess.run code. Gemini found no regression and no new fail-open path in the delta.

P3: the internal TimeoutExpired names self._argv without the kind and step id. It is caught at once and has no visible effect.

Review only; I am not merging.

# Conflicts:
#	CAPABILITIES.md
#	llms-full.txt
#	packages/flow/CHANGELOG.md
#	packages/flow/docs/design/DECOMPOSITION.md
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: ec2d377

Review only. I am not merging this PR. This is a delta stamp versus Gemini's APPROVE at edd8b1bfe6863f22ddf5613fda051939641604df.

The only new commit is a merge of current main, including regenerated CAPABILITIES.md / llms-full.txt and a mechanical CHANGELOG.md / DECOMPOSITION.md resolution. Unique source hunks in second_factor / compiler / ir / playwright / execution profiles are unchanged aside from line-number shifts. The ratchet row this PR still owns is playwright_backend.py 6,818, which matches the file on this head (2 lines under main's 6,820).

I approve this head. I am not merging it.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Gemini independent review: APPROVE

From: Gemini
Audited head: ec2d37764e26c98dbe775cf1ebad71953ff31606

Independent diff audit of ir.py, second_factor.py, runtime/second_factor_step.py, backends/one_time_field.py, backends/playwright_backend.py, backends/_field_metadata_js.py, compile_agent/observe.py, compiler/compile.py, recorder.py, runtime/replayer.py, runtime/secret_frames.py, execution_profiles.py, action_evidence.py, teach_scope.py, and integrations/agents/skills.py:

  • Dedicated ActionKind.SECOND_FACTOR + Step.one_time (code | approval) ensures older runtimes fail closed on load; check_step_shape enforces the strict _STEP_FIELDS allow-list so no api_binding, text, param, secret, effects, or anchor can bypass the handoff.
  • DeliveryLedger.claim executes before asking so retries/loops never re-ask or re-type; OneTimeCode is single-use, non-printable, non-picklable, and discarded in finally.
  • PlaywrightOneTimeField masks autocomplete~="one-time-code" via init script + inline -webkit-text-security: disc !important, restricts to text/tel/password/search, verifies computed masking + emptiness + max_length >= 4 before asking, re-verifies same connected focused empty masked element and max_length >= code.length before filling the exact element handle once, and reads back length only (halting with second_factor_unverified on mismatch; leaving input_verified unset if the page auto-submitted).
  • Secret hygiene: compile_agent/observe.py withholds OTP/password values, persisted_run_frame blacks out frames for workflows with one-time steps, _keeps_exact_frames refuses code steps if any visual transition guard keeps raw frames, and source_env() passes OPENADAPT_RUNNER_TOKEN only when OPENADAPT_SECOND_FACTOR_URL is set.
  • HttpSource enforces HTTPS (or localhost), follow_redirects=False, ephemeral P-256 ECDH + HKDF-SHA256 + AES-256-GCM (request_id as AAD), and checks deadlines before and after each poll (plus in obtain). normalize_code rejects internal line breaks before stripping group separators. _form_submit_steps arms at most one code-only sign-in exemption immediately after a username+password submit.
  • Generality & durability: standard HTML autocomplete="one-time-code" + generic Source protocol, zero per-app engine code, comprehensive unit + headless Chromium + wrap E2E tests, honest limits.

CI blocker (not merge-ready yet): CI is red on stale CLI help snapshots (packages / flow core unit (shard 1/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: c84ecbd

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

@abrichr
abrichr merged commit 860c200 into main Nov 22, 2026
59 of 60 checks passed
@abrichr
abrichr deleted the claude/remote-2fa-handoff branch November 22, 2026 22: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