Skip to content

fix(aws): honor explicit --output json/yaml losslessly#2140

Open
maxmilian wants to merge 2 commits into
rtk-ai:developfrom
maxmilian:fix/aws/honor-explicit-output-json
Open

fix(aws): honor explicit --output json/yaml losslessly#2140
maxmilian wants to merge 2 commits into
rtk-ai:developfrom
maxmilian:fix/aws/honor-explicit-output-json

Conversation

@maxmilian
Copy link
Copy Markdown

Summary

  • Fixes aws lambda commands: rtk corrupts --output json (returns non-JSON schema skeleton, drops field values) #2139: rtk aws ... --output json returned a lossy schema skeleton (string, int, string[64]) or a one-line table summary instead of valid JSON, dropping field values (ImageUri, CodeSha256, env vars) and breaking downstream jq / json.load.
  • Root cause: rtk applied its summarizers (filter_lambda_get) or generic schema compression (filter_json_string) regardless of the user-requested output format.
  • Fix: when the user explicitly requests a structured, parseable format (--output json / --output=json / yaml / yaml-stream), run() short-circuits to a new byte-faithful run_passthrough. Lossy/human formats (table, text) and the no-flag default keep the existing compression behavior.

This covers all aws subcommands, not just lambda.

Test plan

  • cargo fmt --all clean
  • cargo clippy --all-targets — zero warnings
  • cargo test --all — 1947 passed
  • New unit test test_explicit_lossless_format covers json/yaml/=json positives and table/text/absent negatives

🤖 Generated with Claude Code

rtk forced its summarizers/schema compression on aws commands even when
the user explicitly requested --output json (or yaml), dropping field
values and emitting non-parseable output. Route explicitly-requested
lossless formats through an unmodified passthrough so jq/json.load keep
working (issue rtk-ai#2139).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@maxmilian
Copy link
Copy Markdown
Author

Automated triage on #2139 (by wshm) independently confirms this: categorized as bug, priority high, 93% confidence, with the recommended fix being to "bypass summarization when an explicit output format flag is present" — which is exactly what this PR does.

This PR narrows that slightly: it only bypasses for parseable formats (json / yaml / yaml-stream) where losslessness is a contract, while keeping the existing compression for the human-readable table / text formats and the no-flag default — so token savings are preserved everywhere they don't break parsing.

- explicit_lossless_format: last --output wins (aws CLI semantics), and a
  dangling --output (no value) no longer falls through to lossy filtering
- run_generic: detect the --output=<fmt> form so it doesn't inject a
  second --output json on top of an explicit human format
- run_passthrough: document the intentional tee skip
- tests: cover repeated and dangling --output

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@maxmilian
Copy link
Copy Markdown
Author

Note for the PR Testing Checklist: the "token savings ≥60%" item is N/A here. This isn't a new/compressing filter — it's a correctness fix that bypasses compression when the user explicitly requests --output json/yaml. It directly applies design principle Correctness vs Token Savings: a flag that explicitly asks for parseable, lossless output must not be reformatted into a lossy summary/skeleton.

The remaining checklist items are covered:

  • Unit tests added (test_explicit_lossless_format, incl. repeated/dangling --output)
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — all green (1947 passed)
  • Manual rtk aws ... --output json verified to pass through byte-for-byte

On security: the new run_passthrough forwards the user's args to the aws binary via Command::arg (no shell string interpolation), so it doesn't widen any injection surface versus the existing runners.

@dessite
Copy link
Copy Markdown

dessite commented May 28, 2026

I believe I tackled this problem a bit differently a few hours earlier #2135 ;) rtk adds --output json on it's own if no --output defined afair

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.

aws lambda commands: rtk corrupts --output json (returns non-JSON schema skeleton, drops field values)

2 participants