Skip to content

safeoutputs: fail fast on invalid stdin JSON payload mode instead of falling through to “no arguments” - #53455

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-safeoutputs-json-error-message
Aug 17, 2026
Merged

safeoutputs: fail fast on invalid stdin JSON payload mode instead of falling through to “no arguments”#53455
pelikhan merged 4 commits into
mainfrom
copilot/fix-safeoutputs-json-error-message

Conversation

Copilot AI commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

JSON stdin payload mode (safeoutputs <tool> . / piped stdin with no flags) was swallowing JSON.parse failures and incorrectly surfacing “No arguments provided,” which misdiagnosed real payload errors. This change makes payload-mode parse/object-shape failures explicit and stops the misleading help fallback.

  • Payload-mode error semantics

    • parseToolArgs now throws when JSON payload mode is requested and stdin is:
      • invalid JSON, or
      • valid JSON but not an object (e.g. array).
    • Error text includes mode context (. sentinel vs piped stdin/no flags) and corrective guidance.
  • Main-path routing change

    • main now catches argument-parse failures before help/tool-call routing.
    • On parse failure, it emits an argument parsing error and returns early instead of entering the “empty args → help” path.
  • Operational diagnostics

    • When stdin is read for payload/per-field mode, bridge logs captured stdin byte count to make stdin activity visible in run logs.
  • Focused regression coverage

    • Added/updated tests for:
      • explicit . + invalid JSON,
      • payload JSON that is non-object,
      • piped/no-flag invalid JSON,
      • end-to-end main-path behavior ensuring invalid payload does not reach tool help/tool call.
// Before: invalid payload in JSON mode could fall through to empty-args help
printf('{"body":"broken "json"}') | safeoutputs add_comment .

// After: explicit parse failure with mode-aware message
// Error: stdin is not valid JSON: ...
// JSON payload mode was requested with '.'. Pass --key value flags instead, or correct the JSON.

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output.

Review the workflow run logs for details.

Run: https://github.com/github/gh-aw/actions/runs/32057540470> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.9 AIC · ⌖ 8.58 AIC · ⊞ 8.8K ·

Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JSON parsing error message in safeoutputs safeoutputs: fail fast on invalid stdin JSON payload mode instead of falling through to “no arguments” Aug 17, 2026
Copilot AI requested a review from pelikhan August 17, 2026 18:38
@pelikhan
pelikhan marked this pull request as ready for review August 17, 2026 18:49
Copilot AI balanced review requested due to automatic review settings August 17, 2026 18:49

Copilot AI left a comment

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.

Pull request overview

Improves safeoutputs diagnostics for malformed stdin JSON payloads.

Changes:

  • Fails fast on invalid or non-object JSON payloads.
  • Logs captured stdin size and prevents fallback to misleading help.
  • Adds focused parser and end-to-end regression tests.
Show a summary per file
File Description
actions/setup/js/mcp_cli_bridge.cjs Adds payload validation, diagnostics, and early error routing.
actions/setup/js/mcp_cli_bridge.test.cjs Tests invalid payload handling and main-path behavior.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

parsed = JSON.parse(trimmedStdin);
} catch (err) {
const parseError = getErrorMessage(err);
throw new Error(`stdin is not valid JSON: ${parseError}. JSON payload mode was requested ${isExplicitJsonSentinel ? "with '.'" : "from piped stdin with no flags"}. Pass --key value flags instead, or correct the JSON.`);
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output.

Review the workflow run logs for details.

@copilot please refresh the branch if possible, then run the pr-finisher skill and address the open review thread:

Please post a short follow-up describing the fix.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.9 AIC · ⌖ 8.58 AIC · ⊞ 8.8K ·
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take another pass on this PR. Refresh the branch if possible, review any unresolved feedback, and run the skill before handing back to maintainers.

Run: https://github.com/github/gh-aw/actions/runs/32059494377

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 6.71 AIC · ⌖ 5.69 AIC · ⊞ 8.8K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

[!CAUTION]
agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation....

Addressed in 35222d3.

I updated safeoutputs payload parsing so explicit . mode now fails on whitespace-only stdin (including zero-byte stdin), while no-flag piped mode remains distinct: truly empty stdin still falls back to help, but whitespace-only stdin now surfaces a JSON parse error. I also added regression tests for all of these paths in both parseToolArgs and main routing tests.

Copilot AI commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please take another pass on this PR. Refresh the branch if possible, review any unresolved feedback, and run the skill before handing back to maintainers.

Run: https://github.com/github/gh-...

I refreshed against origin/main and re-checked the unresolved stdin payload thread. The behavior is already covered in 35222d3: explicit . now fails on empty/whitespace stdin, while no-flag mode still keeps help fallback only for truly empty stdin. I also re-ran actions/setup/js/mcp_cli_bridge.test.cjs and all tests passed.

@pelikhan
pelikhan merged commit cb879b9 into main Aug 17, 2026
10 checks passed
@pelikhan
pelikhan deleted the copilot/fix-safeoutputs-json-error-message branch August 17, 2026 20:12
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.1

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.

safeoutputs JSON stdin mode reports invalid JSON as "No arguments provided" and prints help

4 participants