Skip to content

fix(agentmain): reject unknown CLI arguments (v3, re-roll onto current main)#703

Open
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-566-argparse-guard-v3
Open

fix(agentmain): reject unknown CLI arguments (v3, re-roll onto current main)#703
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-566-argparse-guard-v3

Conversation

@Kailigithub

Copy link
Copy Markdown
Contributor

Summary

Reject unsupported command-line arguments before GenericAgent initializes. This makes mistyped launch modes such as --goal fail with argparse's non-zero error instead of falling through to the interactive path.

Problem

agentmain.py used parse_known_args() and silently ignored unknown flags. A typo like --goal (intended for a different launcher) was accepted without warning, causing the process to fall through to interactive mode and hang without dispatching any work — users reported "agent launched but did nothing."

Fix

Single-source change in agentmain.py: when _unknown (leftover from parse_known_args()) is non-empty AND --reflect is not active, call parser.error() to print usage and exit non-zero.

--reflect mode is exempted because reflect scripts receive the extra key/value pairs as parameters and need them forwarded (existing behavior preserved).

args, _unknown = parser.parse_known_args()
if _unknown and not args.reflect:
    # Reject unknown CLI flags unless we are in --reflect mode, where
    # extra key/value pairs are forwarded to the reflect script as parameters.
    # Without this guard, typos like `--goal` silently fall through to
    # interactive mode and the process looks alive without doing any work.
    parser.error(f"unrecognized arguments: {' '.join(_unknown)}")
_extra_args = dict(zip([k.lstrip('-') for k in _unknown[::2]], _unknown[1::2])) if _unknown else {}

Verification

  • python3 -m py_compile agentmain.py — syntax OK
  • Regression harness at /tmp/test_issue_566.py — 4 checks:
    • test_source_has_guard: confirms if _unknown and not args.reflect + parser.error are present.
    • test_unknown_arg_rejected: python3 agentmain.py --goal /tmp/foo.json exits with code 2 and the message unrecognized arguments: --goal /tmp/foo.json.
    • test_help_still_works: --help exits 0 without the new guard firing.
    • test_extra_args_dict_still_populated_for_reflect: the _extra_args dict assignment is untouched.
  • Three-step dance (stash → test fails on main → pop → test passes with fix) confirms the test catches the regression.

Scope

Previously, agentmain.py used parse_known_args() and silently ignored
unknown flags. A typo like --goal (intended for a different launcher)
was accepted without warning, causing the process to fall through into
interactive mode and hang without dispatching any work.

Now, unknown arguments are only permitted when --reflect is set, since
extra key/value pairs are forwarded to the reflect script as parameters.
Otherwise parser.error() prints usage and exits non-zero.

Re-roll of lsdefine#697 onto current main (original PR drifted into CONFLICTING
state due to ~60K lines of stale drift in the branch baseline).

Closes lsdefine#566
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.

Goal Hive can silently hang when launched with unsupported --goal argument

1 participant