Skip to content

fix(agents): allow orchestrator.py to run as a direct script#275

Merged
cvsz merged 1 commit into
mainfrom
codex/fix-modulenotfounderror-in-orchestrator.py
Apr 26, 2026
Merged

fix(agents): allow orchestrator.py to run as a direct script#275
cvsz merged 1 commit into
mainfrom
codex/fix-modulenotfounderror-in-orchestrator.py

Conversation

@cvsz
Copy link
Copy Markdown
Owner

@cvsz cvsz commented Apr 26, 2026

Motivation

  • Running python agents/orchestrator.py from the repository root caused ModuleNotFoundError: No module named 'agents' because absolute imports failed when sys.path[0] pointed at the agents/ package.

Description

  • When __package__ is empty, prepend the repository root to sys.path by inserting str(Path(__file__).resolve().parent.parent), ensuring from agents.* imports resolve when the orchestrator is executed directly.

Testing

  • Ran python agents/orchestrator.py and the orchestrator executed end-to-end without the import error (script completed successfully).

Codex Task

@cvsz cvsz merged commit d8fcdbf into main Apr 26, 2026
1 of 5 checks passed
@cvsz cvsz deleted the codex/fix-modulenotfounderror-in-orchestrator.py branch April 26, 2026 14:31
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies agents/orchestrator.py to include a manual sys.path adjustment for handling imports when the script is run directly. The review feedback correctly identifies this as a maintenance anti-pattern that can lead to module shadowing and suggests using the standard python -m execution method instead.

Comment thread agents/orchestrator.py
Comment on lines +7 to +8
if __package__ in {None, ""}:
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Manually manipulating sys.path is generally considered a maintenance anti-pattern in Python. It can lead to unexpected side effects such as module shadowing (where a local file unintentionally overrides a standard library or third-party module) and makes the code fragile if the directory structure changes. The standard and recommended way to execute a script within a package is to use the -m flag from the project root: python -m agents.orchestrator. This approach correctly sets up the module search path and handles absolute imports without requiring manual overrides in the source code.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant