Skip to content

refactor(flow): move the replayer's effect checks and read-back to a mixin, unchanged - #2463

Open
abrichr wants to merge 11 commits into
mainfrom
refactor/replayer-effect-checks
Open

abrichr wants to merge 11 commits into
mainfrom
refactor/replayer-effect-checks

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

This is step E5 of the approved monorepo refactor plan (openadapt-internal#277, track E). It moves code only. Stacked on E4 (#2462, approved); only the last changes are new.

The replayer's effect checks and read-back move unchanged into the EffectChecks mixin in openadapt_flow/runtime/replay/effects.py. That is 22 methods:

  • Pipelined read-back: _may_pipeline_readback, _defer_readback, _join_pipelined_readback, _copy_pipelined_evidence, _apply_pipelined_verdict, recheck_deferred_readback
  • Effect setup and pre-state: _apply_effect_fault_mutation, _resolve_effects, _capture_effect_pre_state, _keep_undo_prior_state, _effect_pre_state_for, _effect_binding_for, _candidate_binding_refusal
  • Verification: _verify_current_effect, _required_effect_pre_state_unreadable, _profile_effect_tier_refusal, _all_default_readback, _auto_readback_verifier, _server_response_mark, _collect_server_responses, _verify_effects, _mapped_selection_readback_region

recheck_deferred_readback is public API. It is still a method of Replayer, now inherited from the mixin.

Left out on purpose: _settle_pipelined_readback stays in replayer.py, because #2412 is editing it. It moves in a follow-up after #2412 lands.

replayer.py keeps every import it had. It goes from 18,693 to 17,872 lines (−821), and its budget is lowered to match.

Checks:

  • verify_moved_code.py against E4: 22 moved units, no edits, and no test patch to retarget.
  • Strict mypy passes across the stack.
  • These tests pass, 2,920 in all: test_import_surface.py, test_import_layers.py, test_fresh_imports.py, the generality test, test_replayer.py, and the read-back, effect and pipelined tests.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 469d401

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 469d401

Unique versus approved #2462 (98ebfac6): 22 methods move AST-identical into EffectChecks, including the public recheck_deferred_readback, which remains a Replayer method by inheritance. Replayer inherits QualificationFaultInjection, AssetsHealingAndEvidence, SettlingAndInterstitials, EffectChecks and no longer defines those 22 methods; the mixins do not overlap. _settle_pipelined_readback stays on Replayer. The host stub is TYPE_CHECKING only; the runtime mixin base is object. The size-ratchet budget for replayer.py is lowered 18693→17872, which matches the file. No unique test edits, and no existing test patches those methods through openadapt_flow.runtime.replayer. I did not merge.

Residual: replayer.py keeps unused imports under # noqa: F401 after the move. That does not change behavior.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 469d401

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 05be872

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 05be872

The move breaks runtime inspection of the public Replayer.recheck_deferred_readback method. In fresh Python 3.12 interpreters, typing.get_type_hints(Replayer.recheck_deferred_readback) resolved all six annotation entries on E4 at a871eb37. On this head it raises NameError: name 'Workflow' is not defined. The method now resolves its annotations in runtime/replay/effects.py, where Workflow, Mapping and RuntimeParamScalar are imported only under TYPE_CHECKING.

Please make those three names available at runtime in the defining module. Add a focused regression that resolves the public method’s annotations through Replayer and checks the resulting types. This preserves the API used by runtime introspection tools.

I compared the 22 moved method bodies with main at dee96b87. Their syntax trees and the origins of globals referenced by executable code match. A fresh import confirmed that the mixin supplies the public method. This finding applies across application targets. The review exercised public API inspection and adds no held-out application claim.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 05be872

Reviewer: gemini-3.1-pro-preview, as the cross-vendor fallback. Codex could not run because its config failed to load. Scope: the change unique to this PR, a871eb37f..05be872c6. The stacked base #2462 already has a Codex APPROVE at a871eb37f, and replayer.py on main has not changed since the merge base dee96b87.

What Gemini checked from the diff:

  1. For each of the 22 methods, the lines removed from replayer.py and the lines added to effects.py are identical, including the public recheck_deferred_readback.
  2. Every module-level name the moved code uses has a source in effects.py, either a module import or a local import inside the method. None is missing.
  3. None of the test patch targets on openadapt_flow.runtime.replayer (_DIALOG_WAIT_S, time.sleep, READBACK_DEADLINE_MARGIN_S, identity_mod.*, resolve) is read by the moved methods. READBACK_DEADLINE_MARGIN_S is read only by code that stays in replayer.py (line 2939), so no test patch silently stops applying.
  4. No safety check is removed or weakened. Effect verification, read-back, undo pre-state and the refusal paths keep the same code.

Command output given to Gemini, which it checked against the diff:

  • ruff --select F821,F811 on effects.py passes.
  • Replayer's method resolution order is QualificationFaultInjection, AssetsHealingAndEvidence, SettlingAndInterstitials, EffectChecks, object. At runtime EffectChecks derives from object, and each of the 22 names is defined only on EffectChecks.
  • replayer.py goes from 18,693 to 17,872 lines, which matches the new size-ratchet budget. _settle_pipelined_readback is still defined on Replayer.

Prior reviews: Grok approved 469d4010 with no blockers, so there is nothing to recheck. The noqa: F401 imports it noted do not change behavior.

Blockers: none.

Not verified here: the PR body's claims of 2,920 passing tests and clean strict mypy. CI was still pending at review time.

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

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 2796225

Delta versus Codex REQUEST CHANGES and Gemini APPROVE at 05be872c676215a57196d55e77807606b887b8b3 (request 7082843835). No prior Grok verdict at this head. effects.py, settling.py, and tests/test_replayer.py are byte-identical to that head. I did not merge.

P1 — get_type_hints(Replayer.recheck_deferred_readback) still raises NameError

Codex's finding at 05be872c is still present. The public method now lives in runtime/replay/effects.py, where Workflow, Mapping, and RuntimeParamScalar are imported only under TYPE_CHECKING. With from __future__ import annotations, typing.get_type_hints(Replayer.recheck_deferred_readback) has to resolve those names in the defining module and raises NameError: name 'Workflow' is not defined. I reproduced that annotation pattern on Python 3.13. Current main still imports those three names at runtime in replayer.py, so the same call works today.

Please make those three names available at runtime in effects.py, and add a focused regression that resolves the public method's annotations through Replayer and checks the resulting types. No such test was added; the test file is unchanged from the head Codex flagged.

Otherwise

The 22 EffectChecks methods, including recheck_deferred_readback, are AST-identical to Replayer on current main. The main-merge delta is the same save_settled_report call and the __main__.py budget alignment to 14237. replayer.py is exactly 17872 lines, matching its ratchet budget. This does not auto-publish.

I will not approve this head until the runtime imports and the regression test land.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 2796225

Independent cross-vendor review of refactor/replayer-effect-checks against origin/main.

Blocking finding (P1)

  • typing.get_type_hints(Replayer.recheck_deferred_readback) raises NameError: name 'Workflow' is not defined. packages/flow/openadapt_flow/runtime/replay/effects.py (lines 251–259) defines the public method recheck_deferred_readback(self, workflow: Workflow, deferred: Any, *, params: Mapping[str, RuntimeParamScalar], ...) -> StepResult under from __future__ import annotations, but Workflow, Mapping, and RuntimeParamScalar are imported only inside if TYPE_CHECKING: (lines 41–56). On origin/main, all three are imported at runtime in replayer.py.
  • Required fix: Import Mapping, Workflow, and RuntimeParamScalar at runtime in effects.py, and add a regression test calling typing.get_type_hints(Replayer.recheck_deferred_readback).

Verified non-blocking checks

  • All 22 methods in EffectChecks and 4 methods in SettlingAndInterstitials are AST-identical to origin/main Replayer, with zero leftovers in replayer.py and zero cross-mixin overlaps.
  • replayer.py is 17,872 lines, matching DECOMPOSITION.md.
  • Generality / durability: pure runtime decomposition refactor; no per-app code; advances maintainability of the durable read-back / reconciliation layer.
  • Note: protected-safety-review also requires a fresh exact-head Claude author declaration on the next commit (legacy refactor/... branch has no vendor prefix), and packages / flow core unit (shard 1/4) is currently blocked by stale packages/flow/tests/fixtures/cli_surface.json on main.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: d8a682b

Round-2 vs my REQUEST CHANGES at 279622535c16006fc3a8b4bdc7897c66f2444101 (7083733450). After a merge of current main (efdf76c9a), d8a682b2c keeps Workflow, Mapping, and RuntimeParamScalar as runtime imports in packages/flow/openadapt_flow/runtime/replay/effects.py instead of TYPE_CHECKING-only imports. Replayer still inherits EffectChecks, so typing.get_type_hints(Replayer.recheck_deferred_readback) can resolve those annotations. The new test_recheck_deferred_readback_type_hints_resolve is Replayer-mediated and asserts those parameter names resolve. The rest of the unique mixin tree (replayer.py, settling.py, DECOMPOSITION.md) is unchanged vs the previous head.

Non-blocking: other mixin methods still annotate Literal, Step, RunReport, and similar names that remain TYPE_CHECKING-only. Those methods are private (_-prefixed); the reported public API is fixed.

This is not publish-triggering. I am not merging.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: d8a682b

This is a cross-vendor review of a protected runtime path. Behaviour is unchanged. The effect checks and read-back that moved into the mixin keep the same checks in the same order, with the same fail-closed branches and the same verdicts. Method resolution order and attribute lookups match the old code. The get_type_hints fix does not turn errors into success.

Non-blocking:

  • P3: the get_type_hints fix covers only recheck_deferred_readback. The other 21 moved private methods still name types that effects.py imports only under TYPE_CHECKING (Step, Effect, Region, RunReport, QualificationFaultGate). Any later get_type_hints call on them would raise. Either resolve them the same way, or add a test that calls get_type_hints on every mixin method.

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