Skip to content

Conversation

@jsl9208
Copy link

@jsl9208 jsl9208 commented Feb 10, 2026

Summary

  • ast_grep_replace with dryRun=false silently fails to write files because --json=compact and --update-all are passed in the same CLI invocation, and ast-grep ignores --update-all when --json mode is active
  • The tool reports "N replacement(s)" identically for both success and failure, causing AI agents to assume files were modified and enter incorrect debugging paths

Changes

  • Split runSg() into two separate CLI invocations when both rewrite and updateAll are requested:
    1. --json=compact (without --update-all) to collect match results
    2. --update-all (without --json) to perform actual file writes
  • Preserve match report on write failure ({ ...jsonResult, error })

Testing

Verified with real ast-grep binary (v0.40.5):

  1. dryRun=true — reports matches, file unchanged ✅
  2. dryRun=false — reports matches, file modified ✅

PR Checklist

  • Code follows project conventions
  • bun run typecheck passes
  • bun run build succeeds
  • Tested locally with OpenCode
  • Updated documentation if needed (README, AGENTS.md)
  • No version changes in package.json

Related Issues

None found — this bug was not previously reported.


Summary by cubic

Fixes ast_grep_replace writing no changes when using rewrite+updateAll by separating read and write passes so file updates actually happen. Also preserves match results and surfaces write errors instead of reporting false success.

  • Bug Fixes
    • Run ast-grep twice when rewrite and updateAll are both set: first with --json=compact, then with --update-all.
    • Return match report with an error message if the write pass fails.
    • Verified with ast-grep v0.40.5: dryRun=true reports matches without changes; dryRun=false updates files.

Written for commit fec12b6. Summary will update on new commits.

ast-grep CLI silently ignores --update-all when --json=compact is
present, causing replace operations to report success while never
modifying files. Split into two separate CLI invocations.
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: The separate write pass logic introduces new async subprocess handling with timeout and error paths. While the fix addresses a real CLI quirk, the new code path (lines 163-179) hasn't been validated…

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