fix(agentmain): reject unknown CLI arguments (v3, re-roll onto current main) - #703
fix(agentmain): reject unknown CLI arguments (v3, re-roll onto current main)#703Kailigithub wants to merge 1 commit into
Conversation
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
|
Closing this PR — its underlying work has been covered by #742 (
The fix is a strict superset of #703's behavior; #742 covers #703's case and adds deeper malformed-input guards. Diff preserved on the branch tip and can be cherry-picked at any time. Happy to reopen if the simpler one-line approach is preferred over the comprehensive guard. Closing this PR — 同一文件同一 bug 域已在 #742(
修复效果是 #703 v3 的严格超集;#742 覆盖 #703 v3 的 case 并补充了更深的畸形输入守卫。差异保留在分支 tip 可随时 cherry-pick。如更倾向于单行简化写法,可重新打开本 PR。 |
Summary
Reject unsupported command-line arguments before GenericAgent initializes. This makes mistyped launch modes such as
--goalfail with argparse's non-zero error instead of falling through to the interactive path.Problem
agentmain.pyusedparse_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 fromparse_known_args()) is non-empty AND--reflectis not active, callparser.error()to print usage and exit non-zero.--reflectmode is exempted because reflect scripts receive the extra key/value pairs as parameters and need them forwarded (existing behavior preserved).Verification
python3 -m py_compile agentmain.py— syntax OK/tmp/test_issue_566.py— 4 checks:if _unknown and not args.reflect+parser.errorare present.python3 agentmain.py --goal /tmp/foo.jsonexits with code 2 and the messageunrecognized arguments: --goal /tmp/foo.json.--helpexits 0 without the new guard firing._extra_argsdict assignment is untouched.Scope