Repository navigation
feat(flow): ask for a sign-in's second factor at the run's own terminal - #2368
Conversation
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.
…doff # Conflicts: # packages/flow/docs/design/DECOMPOSITION.md
An interactive run with no other source asks at its terminal (no echo for a code, the same timeout). A run without a terminal never prompts and stops before typing, as before.
Independent adversarial review: REQUEST CHANGESFrom: Grok Author is GitHub The terminal source itself is carefully fail-closed. Findings
CI on this head also has protected-safety-review / Evaluate protected-path evidence red for process metadata. That is secondary. What I ran
Review only; I am not merging. |
# Conflicts: # packages/flow/docs/design/DECOMPOSITION.md
Independent adversarial review: REQUEST CHANGESFrom: Gemini This PR is protected and Claude-authored, so the review has to come from another vendor. Codex could not run (its local config failed to parse), so Gemini (gemini-3.1-pro-preview) reviewed it. Gemini received the full diff, the PR body, the head versions of Blockers
|
# 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.
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.
…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.
… 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.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. This head merges #2363 at 907fba3 and moves the terminal source to Local checks on this head, single-process:
The cross-vendor review for this head is Gemini's. |
Independent adversarial review: REQUEST CHANGESFrom: Gemini Gemini run on 4374127 (gemini-3.1-pro-preview). Codex is unavailable until Nov 27, so this is the cross-vendor review. Gemini received the PR body, the diff against #2363's head 907fba3, Blocker
What Gemini checked and found holding
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.
A timeout, an over-long answer or an interrupt left the person's partial input in the terminal queue; with echo back on, the shell would read and show it after the run (Gemini at 4374127). The read now flushes pending input in finally, before echo is restored. A pty test types part of a code, lets the prompt time out and checks nothing is left to read.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 4374127: the terminal read flushes input it did not take in Local checks on this head: |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on cbae062 (gemini-3.1-pro-preview). This delta re-review follows its REQUEST CHANGES at 4374127. Gemini received the delta 4374127..cbae062 and The blocker is fixed. Review only; I am not merging. |
The terminal prompt was POSIX-only, so a Windows laptop with no control plane or command source stopped at the code step. One line reader now serves both platforms over a small Console interface: - PosixConsole: echo off for a code, select on the descriptor (as before). - WindowsConsole: msvcrt.getwch reads one key at a time and never echoes; kbhit is polled in short slices under the step's deadline. Either way the read runs in the calling thread, keys typed before the prompt are discarded, and in finally the keys the read did not take are discarded and normal input restored, whatever ended the read (an answer, the deadline, Ctrl-C, an over-long answer or a failed read). Function and arrow keys are skipped; backspace edits the line. tests/test_second_factor_console.py drives WindowsConsole with an injected kbhit, getwch and sleep on a fake clock, so the deadline and discard logic runs on every platform; one test uses the real msvcrt and runs only on Windows.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since cbae062: the terminal prompt works on the Windows console too. One line reader serves POSIX ( Local checks on this head: |
Independent adversarial review: REQUEST CHANGESFrom: Gemini Gemini run on eb05728 (gemini-3.1-pro-preview). This is a delta review of the Windows console path (cbae062..eb05728), with Blockers
P3: What Gemini checked and found holdingA code is never echoed on either platform, keys typed before the prompt are discarded, and Ctrl-C, timeouts, EOF and a failed Review only; I am not merging. |
… input Gemini at eb05728: - The \x00/\xe0 function-key prefix is skipped only on the Windows console (Console.prefixed_keys). A POSIX terminal keeps U+00E0 and the character after it; a pty test reads "àn" whole. - WindowsConsole.wait measures on a monotonic clock, so a sleep that oversleeps can't stretch the deadline; a test oversleeps threefold. - Ending a Windows read drops keys for up to half a second instead of 1,024 keys, so a long paste is dropped whole; a test pastes 5,000. - PosixConsole decodes with an incremental UTF-8 decoder, so a character split across two reads stays whole.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since eb05728 the commit fixes the three blockers and the P3 from the Gemini review: the function-key prefix applies only on Windows, the Windows wait runs on a monotonic clock, the drain is bounded by time, and POSIX decoding is incremental. Each blocker has a test that fails on the previous code. Local checks on this head: the console, terminal and second-factor suites, 75 passed with 1 Windows-only test skipped on macOS (run twice). mypy and ruff 0.17.0 are clean. |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 9b07008 (gemini-3.1-pro-preview). This delta re-review follows its REQUEST CHANGES at eb05728. Gemini received the delta eb05728..9b07008 and All three blockers and the P3 are fixed:
P3: if only part of a multi-byte character ever arrives, Review only; I am not merging. |
# Conflicts: # CAPABILITIES.md # llms-full.txt # packages/flow/CHANGELOG.md # packages/flow/docs/SECOND_FACTOR.md # packages/flow/docs/design/DECOMPOSITION.md # packages/flow/openadapt_flow/second_factor.py
Independent adversarial review: APPROVEFrom: Gemini Independent cross-vendor review of What was verified
|
#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
Stacked on #2363 ("wait for a person at a sign-in's second factor"). Retarget it to
mainonce #2363 merges.When no other source is set (no control plane and no command), an interactive run asks at its own terminal: stdin and stderr must both be a TTY.
ndeclines.The source is in
openadapt_flow/second_factor_terminal.py. One line reader serves both platforms over a small console interface:termios): echo is turned off for a code, andselectwaits on the terminal.msvcrt):getwchreads one key at a time and never echoes, andkbhitis polled in short slices. Function and arrow keys are skipped, and backspace edits the line.Either way the read runs in the calling thread under the step's deadline, so nothing keeps reading after a timeout and the next prompt gets its answer. Keys typed before the prompt are discarded, so an earlier keystroke can't answer it. In
finally, the keys the read did not take are discarded and normal input is restored, whatever ended the read (an answer, the deadline, Ctrl-C, an over-long answer or a failed read), so the shell never reads part of a code. The code then goes through #2363's handoff like any other source's answer.A run without a terminal never prompts and still stops before typing with
second_factor_unavailable; that covers services, hosted sandboxes, MCP servers and CI.OPENADAPT_SECOND_FACTOR_PROMPT=offturns the prompt off, and the variable is passed to a cached run's MCP child.Cloud follow-up (runner fixture and Flow release pin): OpenAdaptAI/openadapt-cloud#552.
Earlier findings
selectread under the deadline, echo restored infinally, input flushed before each prompt. A pty test times out a prompt, checks echo is back on and that no thread is left, then answers the next prompt## Unreleasedruntime/__init__.py:124, reached when runtime code imported thesecond_factormodule through the package. The handoff imports names fromopenadapt_flow.second_factorinstead; the import-layer suites pass at this headTests
tests/test_second_factor_terminal.py(7) runs on a real pty, answering each prompt once it has been written: a code is read without echo and echo comes back; a timeout restores echo and the next prompt gets its answer; input left unread at a timeout is discarded; input typed before a prompt doesn't answer it; an empty code declines and an approval can be confirmed or declined; a run without a TTY never prompts,PROMPT=offwins, and a command source wins over the terminal; the prompt setting reaches a cached run's child without the run token.tests/test_second_factor_console.py(7) drives the Windows console reader with an injectedkbhit,getwchandsleepon a fake clock, so its deadline and discard logic runs on every platform: keys before the prompt, a partial code at the deadline, Ctrl-C, function keys and backspace, an over-long answer, a shown approval reply and a failing console. One more test uses the realmsvcrtand runs only on Windows; no pre-merge CI lane runs Flow tests on Windows, so it runs on Windows developer machines.tests/test_second_factor.pyand the import-layer suites pass at this head.The docs (SECOND_FACTOR.md), the CHANGELOG, the CAPABILITIES row and
llms-full.txtare updated.