Skip to content

fix(flow): guard __main__.py entrypoints with if __name__ == '__main__' - #2639

Merged
abrichr merged 1 commit into
mainfrom
gemini/fix-main-fresh-imports
Nov 24, 2026
Merged

abrichr merged 1 commit into
mainfrom
gemini/fix-main-fresh-imports

Conversation

@abrichr

@abrichr abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes the deterministic main-push CI failure in packages.yml run 45435843467 (flow core unit (shard 2/2)), which cancelled shard 1/2 via matrix fail-fast and blocked packages-gate / PyPI publishing of openadapt-flow 4.0.0.

Root Cause

tests/test_fresh_imports.py::test_every_module_imports_alone (skipped in the PR fast lane, runs on main push) imports every module under openadapt_flow in a fresh interpreter. Two __main__.py modules called main() unconditionally at import time:

  • packages/flow/openadapt_flow/agent_test/__main__.py
  • packages/flow/openadapt_flow/verify_draft/__main__.py

Fix

Wrap both entrypoints in if __name__ == "__main__": (verified no other openadapt_flow/**/__main__.py files are missing this guard).

Verification

  • Fresh importlib.import_module on both modules: OK
  • ruff check & ruff format --check: OK
  • gitleaks: 0 leaks

@claude @grok — tiny 2-file CI unblock (dda5d10eaf29e0d794986132017f145f5aaa1826), ready for quick review & merge.

Unblocks main push CI (flow core unit shard 2/2: test_fresh_imports.py::
test_every_module_imports_alone) so packages-gate turns green and
release-package.yml can publish openadapt-flow 4.0.0.

Both openadapt_flow.agent_test.__main__ and openadapt_flow.verify_draft.__main__
called main() unconditionally at import time, causing argparse to exit
when imported in a fresh interpreter.
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: dda5d10

This PR fixes the only failure in main's flow core unit (shard 1/2), in run 45419324497 at b454999: test_every_module_imports_alone reported that openadapt_flow.agent_test.__main__ ran the CLI's argparse on import.

  • Both __main__.py files now call main() only under if __name__ == "__main__", so python -m behaves the same as before.
  • I checked every __main__.py under packages/flow/openadapt_flow at this head for other top-level calls. None are left; vlm_service only creates a logger at top level.
  • I didn't run tests locally. CI at this head is the evidence.

This also unblocks the types 0.24.2 publish. Types' newest commit is b454999, and its push run can't go green because the bug exists at that commit. After this merges, a commit that changes packages/types is still needed to restart the types release wait. I'm opening that PR next.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: dda5d10

The code fix is correct. The blocker is what this merge would publish.

The fix works.

  • I ran tests/test_fresh_imports.py at this head with in-tree openadapt-types: 5 passed, including test_every_module_imports_alone.
  • Control: with main's agent_test/__main__.py put back, the same test fails with openadapt test: error: argument cmd: .... That is the failure from main's push run.
  • python -m openadapt_flow.agent_test --help and python -m openadapt_flow.verify_draft --help still print their usage.
  • Every other __main__.py under packages/ already has the guard.
  • CI: 25 passed, 18 skipped, none failed.

P1: merging this publishes openadapt-flow 4.0.0 with the openadapt-types>=0.24.0 floor.
release_plan.py publishes a package when the newest main commit that changed it has a green push run, its version is new on PyPI, its CHANGELOG starts with that version, and PyPI serves every dependency floor. After this merge:

  • the newest commit that changes packages/flow is this one, and this PR fixes the only failure in that run;
  • packages/flow/pyproject.toml says 4.0.0, and PyPI's newest is 3.4.0;
  • changelog_top() skips ## Unreleased, so it returns 4.0.0;
  • the floor openadapt-types>=0.24.0 is met, because PyPI serves 0.24.0 (0.24.2 is not there yet);
  • the pypi-flow environment has a branch policy and no required reviewer.

That is the publish #2640 and #2637 say must not happen: "Flow 4.0.0 imports check_level and evidence_scope, so it must not publish with the >=0.24.0 floor." I checked the effect too. With Flow's lock (types 0.24.0 from PyPI) and no in-tree types, the same fresh-import test fails: openadapt_flow.exceptions.* modules raise ModuleNotFoundError for openadapt_types.run_ledger, which the 0.24.0 wheel does not contain.

#2637 can't land first, because Flow's lock can't take 0.24.2 until PyPI serves it.

What the branch needs: keep Flow 4.0.0 from passing the release plan until #2637 merges. The simplest way I see is to leave the v4.0.0 entry undated in this PR, so changelog_top() returns 3.4.0 and the plan waits. #2637 then dates it when it raises the floor. Another gate that holds Flow is fine too. The author should make this change. I have not pushed to this branch.

Generality gate: the change is a generic entrypoint guard with no app-specific logic. I did not run Windows.

@abrichr
abrichr merged commit 47e1435 into main Nov 24, 2026
86 of 91 checks passed
@abrichr
abrichr deleted the gemini/fix-main-fresh-imports branch November 24, 2026 19:04
abrichr added a commit that referenced this pull request Nov 24, 2026
#2640)

Types 0.24.2 publishes from its newest commit, so it ships #2495's
check_level and evidence_scope. Those were listed under Unreleased. The
#2495 push run failed on a Flow __main__ import bug (fixed in #2639), so
this commit also gives types a new commit to publish from.
abrichr added a commit that referenced this pull request Nov 24, 2026
* fix(flow): require openadapt-types>=0.24.2 for Flow 4.0.0

Flow 4.0.0 imports openadapt_types.check_level and evidence_scope (#2495),
which no released types version has. The >=0.24.0 floor let pip resolve
types 0.24.0 and fail on import.

* chore(flow): hold Flow 4.0.0 until its types floor is 0.24.2

release_plan publishes a version only when CHANGELOG.md's first dated entry
matches it. Undating v4.0.0 keeps the plan at wait, so #2639's green push
run can't publish 4.0.0 with openadapt-types>=0.24.0, which fails on import.
#2637 re-dates the entry together with the >=0.24.2 floor.

* chore(flow): re-date v4.0.0 with the 0.24.2 types floor (undoes the #2641 hold)

* chore(flow): relock openadapt-types 0.24.2

* chore(connectors): relock eligibility for the 0.24.2 types floor; name all new types imports
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