Skip to content

fix: an empty occurrence of an accumulating flag no longer erases the earlier ones - #1868

Open
v0ropaev wants to merge 1 commit into
anthropics:mainfrom
v0ropaev:fix/accumulating-flag-empty-value
Open

v0ropaev wants to merge 1 commit into
anthropics:mainfrom
v0ropaev:fix/accumulating-flag-empty-value

Conversation

@v0ropaev

Copy link
Copy Markdown

What is wrong

parseClaudeArgsToExtraArgs (base-action/src/parse-sdk-options.ts) decides whether a flag is a boolean before it looks at whether the flag accumulates:

if (nextArg && !nextArg.startsWith("--")) {
  if (ACCUMULATING_FLAGS.has(flag)) { ...accumulate... }
  else { result[flag] = nextArg; i++ }
} else {
  result[flag] = null // Boolean flag
}

nextArg && is a truthiness test, so shell-quote's "" for --allowedTools "" counts as "no value" and the occurrence falls into the else branch, which writes null over everything the earlier occurrences accumulated. Same for a --flag with nothing after it.

--allowedTools A --allowedTools B    ->  allowedTools ["A","B"]
--allowedTools A --allowedTools ""   ->  allowedTools undefined
--add-dir /work --add-dir /other     ->  additionalDirectories ["/work","/other"]
--add-dir /work --add-dir ""         ->  additionalDirectories undefined

That matters because tag and agent mode put their own flags in front of the user's claude_args (src/modes/tag/index.ts:180-192, agent mode the same). Running the tag-mode prefix through parseSdkOptions:

baseline                             allowedTools ["mcp__github_comment__update_claude_comment","Edit","Read","Write","Bash"]
                                     mcp-config   the github_comment server
--allowedTools "" --max-turns 10     allowedTools undefined
bare --allowedTools then a flag      allowedTools undefined
bare --mcp-config then a flag        mcp-config   null

So a user who writes claude_args: --allowedTools "" loses the action's own tool list, mcp__github_comment__update_claude_comment included, and Claude can no longer update its own comment. A bare --mcp-config drops the github_comment server config and leaves null in extraArgs, which then reaches the CLI as a flag with no value.

What this changes

Decide the accumulating case first, since those flags are never booleans. Gather every consecutive non-flag token and skip the empty ones; an occurrence that contributes nothing leaves the flag exactly as it was. The non-accumulating path is unchanged.

A side effect worth noting: a bare --mcp-config with no earlier value now leaves the key absent rather than null. Absent is what the SDK wants; null became a valueless flag on the command line.

I did not add a warning when an occurrence is dropped. Say the word if you would like one, it is two lines.

Test Plan

Four new tests in base-action/test/parse-sdk-options.test.ts, all failing before the change:

  • an empty --allowedTools after a real one keeps the real one
  • a value-less --allowedTools before another flag keeps the real one
  • a value-less --mcp-config keeps the earlier config
  • an empty --add-dir keeps the earlier directory
bun test base-action/test     168 pass, 0 fail
bun test                      961 pass, 9 fail

The nine are all in test/github-graphql-url.test.ts ("GitHub API client endpoint routing"). They fail the same way on unmodified main in a worktree here, because they reach github.com and this machine has no network for them, so they are environmental rather than anything in this change.

prettier --check clean on both files.

… earlier ones

parseClaudeArgsToExtraArgs decides boolean-vs-value before it looks at
whether the flag accumulates, so an occurrence with no usable value falls
into the else branch and writes null over what the earlier ones collected.
shell-quote returns "" for --allowedTools "", and "" is falsy, so the
empty string counts as no value.

Tag and agent mode both prepend their own --mcp-config and --allowedTools
in front of the user's claude_args, so a user writing --allowedTools ""
drops the action's own list, including
mcp__github_comment__update_claude_comment, and a bare --mcp-config drops
the github_comment server config.

  --allowedTools A --allowedTools ""   ->  allowedTools undefined
  --add-dir /work --add-dir ""         ->  additionalDirectories undefined

Decide the accumulating case first, skip empty tokens while gathering, and
leave the flag as it was when an occurrence contributes nothing. Four
tests, all failing before the change.

This branch has not been deployed

No deployments
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