Skip to content

ci(ratchet): size budgets never rise; dropping the row of an existing file fails - #2430

Merged
abrichr merged 2 commits into
mainfrom
ci/ratchet-budgets-never-rise
Nov 21, 2026
Merged

abrichr merged 2 commits into
mainfrom
ci/ratchet-budgets-never-rise

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

This PR enforces the founder's decision on the monorepo refactor plan (openadapt-internal#277, decision 3, approved 2026-11-21): feature PRs never raise size budgets, and new code goes into new modules.

What changes

scripts/check_file_size_ratchet.py, with --base (the PR and merge-queue mode), now fails when a change:

  • raises a budget row in packages/flow/docs/design/DECOMPOSITION.md; or
  • removes the row of a listed file that still exists, since that is the other way to escape the limit.

These still work as before:

  • a change may lower a budget, and the check prints the number to lower it to;
  • a change may drop the row of a file it removed;
  • a new row may be added at any size.

The over-budget message now says to put the new code in a new module and keep only the call site. The DECOMPOSITION.md section 6 rule is updated to match; the notes about earlier raises stay as history.

Four new tests cover raising, lowering, dropping a row of an existing file, and dropping the row of a removed file. All 26 ratchet tests pass, and the check passes on main.

Effect on open PRs

I merged each open PR that edits the budget table onto this branch (git merge-tree) and ran the check:

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 59c118d

First review of this PR. Author is GitHub abrichr, not Grok. Review only; I am not merging.

The path-keyed part of the founder rule is implemented and tested. With --base, a raised budget fails, lowering one passes, dropping the row of a file that still exists fails, and dropping the row of a removed file passes. The over-budget message no longer offers "raise the budget" as a fix. Required CI already runs python3 scripts/check_file_size_ratchet.py --base HEAD^1 on the pull-request merge commit (fetch-depth 2, first parent is the base). That is the right place to enforce "never rise"; this workflow does not run on a bare push to main, which is fine if main only moves through that merge commit.

A rename can still raise a limit. Budgets and the raise check are keyed only by path. git mv a listed file, drop its old row (allowed, because the old path is gone), and add a row for the new path at a higher number: the new path is not in before, so the raise check never fires, and a new module is otherwise the intended escape hatch. The check should treat a git rename (or equivalent) of a listed file as the same budget: the new path's budget must be less than or equal to the old one. A test that does that move and raises the number should fail.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 319e797

Delta review after my REQUEST CHANGES at 59c118db453363f9758afa8b4a96415f7cdf7e96 (7059500262). Author is GitHub abrichr, not Grok. Review only; I am not merging.

renamed_from reads git diff --name-status -M against the same --base used for the old budgets. A new listed path that git sees as renamed from a previously budgeted file cannot have a higher limit than that origin. test_a_renamed_file_keeps_its_budget parametrizes raise (12 fails), keep (10), and lower (9). That closes the git mv raise I reported. A copy that git does not call a rename can still be listed as a new path with a fresh budget; that is the same new-module rule as before, not this rename hole.

@abrichr
abrichr merged commit 5a39ddd into main Nov 21, 2026
53 of 54 checks passed
@abrichr
abrichr deleted the ci/ratchet-budgets-never-rise branch November 21, 2026 12:18
abrichr added a commit that referenced this pull request Nov 21, 2026
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 added a commit that referenced this pull request Nov 22, 2026
* feat(flow): wait for a person at a sign-in's second factor

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.

* test(flow): pin the dashboard seal vector shared with Cloud

* refactor(flow): keep second-factor shape checks out of the budgeted modules

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.

* fix(flow): give a cached run's MCP child the run token with the control-plane URL

* refactor(flow): keep ir.py and replayer.py within their size budgets

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.

* fix(flow): bind, mask and type a second factor once, as its own action

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.

* fix(flow): fill a code only into a field that holds it, and arm the code-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.

* fix(flow): keep the heartbeat going while a second-factor command waits

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 added a commit that referenced this pull request Nov 23, 2026
…al (#2368)

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

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.

* test(flow): pin the dashboard seal vector shared with Cloud

* refactor(flow): keep second-factor shape checks out of the budgeted modules

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.

* fix(flow): give a cached run's MCP child the run token with the control-plane URL

* feat(flow): ask for a sign-in's second factor at the run's own terminal

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.

* refactor(flow): keep ir.py and replayer.py within their size budgets

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.

* fix(flow): bind, mask and type a second factor once, as its own action

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.

* fix(flow): fill a code only into a field that holds it, and arm the code-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.

* fix(flow): keep the heartbeat going while a second-factor command waits

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.

* fix(flow): discard input the terminal read did not take

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.

* feat(flow): ask for the second factor at a Windows console too

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.

* fix(flow): keep the Windows console reader on the clock and off POSIX 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.
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