Repository navigation
feat(flow): wait for a person at a sign-in's second factor - #2363
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.
Independent adversarial review: REQUEST CHANGESFrom: Grok I will not merge. Author is GitHub 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 [P2] The hosted source cannot run through the compiled-skill path that this PR itself wires up. P3: wrap detection of a code field is only Review only; do not merge. |
Independent adversarial review: APPROVEFrom: Grok I will not merge. This is a delta re-review of the P2 from my REQUEST CHANGES at 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
Independent adversarial review: REQUEST CHANGESFrom: Grok I will not merge. This is a delta re-review of my APPROVE at The P2 fix is intact: [P2] The second-factor changelog entry was folded into the already-dated v3.4.0 section. Main's Flow changelog and Review only; do not merge. |
# Conflicts: # packages/flow/docs/design/DECOMPOSITION.md
Independent adversarial review: APPROVEFrom: Grok Delta re-review of my REQUEST CHANGES at The changelog P2 is addressed. The recorded conflict is still only |
# 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.
Independent adversarial review: REQUEST CHANGESFrom: Codex 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 I compared the main merge and refactor with Grok's approved
|
|
Handoff note for the second-factor rework (merge sweep). No verdict here. State at head fddab5f:
The Codex review at this head is REQUEST CHANGES, with 10 findings (see the Codex comment above for file:line references):
|
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, 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:
Codex is unavailable until Nov 27, so the cross-vendor review for this head is Gemini's. |
Independent adversarial review: REQUEST CHANGESFrom: Gemini 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 Blocker
Non-blocking
What Gemini checked and found fixedAll 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.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. The only change since 907fba3 fixes the blocker in the Gemini review: Local checks on this head: |
Independent adversarial review: APPROVEFrom: Gemini 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. P3: the internal Review only; I am not merging. |
# Conflicts: # CAPABILITIES.md # llms-full.txt # packages/flow/CHANGELOG.md # packages/flow/docs/design/DECOMPOSITION.md
Independent adversarial review: APPROVEFrom: Grok Review only. I am not merging this PR. This is a delta stamp versus Gemini's APPROVE at The only new commit is a merge of current I approve this head. I am not merging it. |
Gemini independent review: APPROVEFrom: Gemini Independent diff audit of
CI blocker (not merge-ready yet): CI is red on stale CLI help snapshots ( |
Independent adversarial review: APPROVEFrom: Gemini Delta review versus previously approved head |
#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
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
second_factor(ActionKind.SECOND_FACTOR), andStep.one_timenames its kind:codeorapproval. 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 withorigin/main'sir.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.openadapt_flow/runtime/second_factor_step.py):inputwhoseautocompletenamesone-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).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
Statusbecomes an alias of it.OneTimeCodeholder that can't be printed, pickled or copied and hands its value out once.OPENADAPT_SECOND_FACTOR_URLwithOPENADAPT_RUNNER_TOKEN(a runner's control plane; the code is sealed in the person's browser to a one-step P-256 key), orOPENADAPT_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.autocompletenamesone-time-code. Duringopenadapt 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._call_skillpasses the current stderr to the MCP stdio client. The client's default is the stream bound whenmcpwas first imported; when that stream had been closed since, spawning the child failed, which is what made the wrap e2e fail withcached_tool_resultafter 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), andsecond_factor_unverified(typed once, read-back failed; a safety halt). All but the last stop before typing.Limits
second_factor_unbound; an approval works on any backend.approvalstep has to be added by hand.Codex review at fddab5f, mapped to fixes
api_binding, effects and every other input fieldobtainfor every sourcesource_envforwards the token only with the URLTests
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.pypasses 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 aftertest_wrap_sign_in_e2e.py.test_rl_env_typed.pyfails locally only becauseopenenvisn't installed here.replayer.pyandir.pystay within their budgets;replayer.py's is lowered to 19219. The Cloud side (request routes, dashboard page, email, runner wiring) is in openadapt-cloud behindSECOND_FACTOR_HANDOFF_ENABLED. Its runner detects these steps byone_timealone, 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.