Skip to content

refactor: split Flask entry into wiring and route modules - #1002

Closed
Pigbibi wants to merge 1 commit into
mainfrom
refactor/untangle-p0-p2
Closed

Pigbibi wants to merge 1 commit into
mainfrom
refactor/untangle-p0-p2

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

AI assistance

Cursor Auto (Composer) with local agent session. Owner authorized commit, push, and merge for this untangle refactor batch.

What changed

  • Structure-only refactor for high cohesion / low coupling (module splits, re-exports, compatibility shims).
  • No intentional change to HTTP/CLI contracts, order semantics, or secrets handling.

How verified

  • Local focused checks as listed in the prior PR summary (imports/AST/unit where applicable).
  • CI re-run on updated head after commitlint body fix and export/test follow-ups.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T18:58:11.852501Z c993641 New commits
🔒 Security Review ✅ Completed 2026-11-13T18:58:01.652526Z c993641 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Pigbibi
Pigbibi enabled auto-merge (squash) November 13, 2026 18:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a9c4d6880

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread http_routes.py
Comment on lines +864 to +866
def handle_dry_run():
return _handle_dry_run_with_deadline()
def handle_paper_execution_command_consumer():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore Flask route registration for the moved handlers

All ten @app.route(...) decorators from the previous entrypoint were removed during extraction, and a repository-wide search finds no replacement registration. Consequently, the application exported as main:app has only Flask's static route: execution, reconciliation, monitoring and health requests all return 404 once import succeeds. This also violates the route contract enforced by scripts/validate_cloud_run_startup.py, which the Dockerfile runs during image construction. Restore the decorators or explicitly register the handlers on this app.

Useful? React with 👍 / 👎.

Comment thread main.py Outdated
Comment on lines +4 to +6
from notifications_runtime import * # noqa: F403, F401
from strategy_plugins_runtime import * # noqa: F403, F401
from http_routes import * # noqa: F403, F401

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve private helpers consumed through the main module proxy

Python star imports exclude underscore-prefixed names unless __all__ explicitly exports them, so this no longer exposes the private helpers that application/http_routes.py still resolves dynamically through its main proxy. For example, local monitor prechecks call main._handle_dry_run_with_deadline, successful probes with account facts call main._account_facts_match_runtime_target, and probe error handling calls main._publish_runtime_failure_notification; each now raises AttributeError. Even after restoring route registration, these flows remain broken. Explicitly re-export the required helpers or update their consumers to resolve them from their new owning modules.

Useful? React with 👍 / 👎.

Comment thread main.py Outdated
Comment on lines +3 to +6
from runtime_wiring import * # noqa: F403, F401
from notifications_runtime import * # noqa: F403, F401
from strategy_plugins_runtime import * # noqa: F403, F401
from http_routes import * # noqa: F403, F401

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the extracted modules in the distribution

When this project is installed as a wheel rather than run from its checkout, importing main now fails with ModuleNotFoundError: No module named 'runtime_wiring'. pyproject.toml explicitly enumerates the top-level py-modules, but none of the four newly imported modules is listed; its separate package-discovery configuration does not include standalone .py modules. A repository-wide packaging-config and tracked-artifact search found no alternative inclusion mechanism. Add all four extracted modules to the distribution configuration so the installed entrypoint retains its dependencies.

Useful? React with 👍 / 👎.

Keep main as a thin export surface for tests and process entry.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Pigbibi
Pigbibi force-pushed the refactor/untangle-p0-p2 branch from 0a9c4d6 to c993641 Compare November 13, 2026 18:54
@Pigbibi Pigbibi added the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9936416e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread main.py
Comment on lines +8 to +9
def _export(module):
globals().update({key: value for key, value in vars(module).items() if not key.startswith("__")})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve entrypoint overrides when exporting extracted functions

Copying functions into main does not change their global namespace, so existing overrides on main no longer affect the extracted implementations. This breaks the notification guards installed with setattr(main, name, forbidden) in scripts/pilot_app_isolation_entry.py, as well as regression tests that replace main.connect_ib, main.build_composer, or main.RUNTIME_SETTINGS. For example, replacing main.RUNTIME_SETTINGS leaves main.get_ib_port() reading the original settings in runtime_wiring. Preserve dynamic dependency lookup through the entrypoint or update all override consumers to patch the owning modules.

Useful? React with 👍 / 👎.

Comment thread main.py
Comment on lines +3 to +6
import http_routes as _http_routes
import notifications_runtime as _notifications_runtime
import runtime_wiring as _runtime_wiring
import strategy_plugins_runtime as _strategy_plugins_runtime

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reload extracted configuration for each test runtime

The existing strategy_module_factory in tests/conftest.py changes environment variables and removes/reloads only main to construct each runtime. These imports now leave runtime_wiring and the other extracted modules cached, so every subsequent factory call retains the first runtime's settings and strategy configuration. Tests such as test_ib_connect_timeout_can_be_overridden consequently observe whichever timeout an earlier test loaded rather than their requested value, and paper/live configuration cases no longer exercise their intended runtime. Update the factory's module lifecycle alongside this extraction so configuration and dependent modules are recreated for each runtime.

Useful? React with 👍 / 👎.

Comment thread http_routes.py
def handle_request():
if request.method != "POST":
return "Method Not Allowed", 405
return _route_with_runtime_error_fallback(_handle_request)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wire dependencies between the extracted runtime modules

Even after route registration is restored, any POST reaching handle_request or handle_probe raises NameError because _route_with_runtime_error_fallback lives in notifications_runtime but is never imported into this module. The same incomplete wiring affects ordinary execution calls such as the bare load_strategy_plugin_signals() reference, whose implementation now lives in strategy_plugins_runtime. Importing those modules as nr and spr does not expose their functions as bare names, and exporting everything into main does not populate the extracted functions' defining namespaces. Explicitly import or qualify the cross-module dependencies so the default handlers work without overrides.

Useful? React with 👍 / 👎.

@Pigbibi

Pigbibi commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Closing without merge: the mechanical main.py split introduced broken private-symbol exports and adapter call sites (confirmed by CI + Codex review). QuantAIService #503 and QuantPlatformKit #782 from this untangle batch already merged. Platform entry splits will be redone in a follow-up PR with test-backed adapter wiring.

@Pigbibi Pigbibi closed this Nov 13, 2026
auto-merge was automatically disabled November 13, 2026 19:00

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant