Skip to content

fix(migration): skip backup when config content is unchanged (fixes #3222)#3301

Open
MoerAI wants to merge 2 commits intocode-yeongyu:devfrom
MoerAI:fix/config-migration-skip-noop-backup
Open

fix(migration): skip backup when config content is unchanged (fixes #3222)#3301
MoerAI wants to merge 2 commits intocode-yeongyu:devfrom
MoerAI:fix/config-migration-skip-noop-backup

Conversation

@MoerAI
Copy link
Copy Markdown
Contributor

@MoerAI MoerAI commented Apr 10, 2026

Summary

  • Prevent unnecessary .bak.<timestamp> backup files on every startup when no config changes are needed

Problem

migrateConfigFile() sets needsWrite=true in several code paths that update migration tracking state (sidecar writes, stripping legacy _migrations field) without actually changing the config file body. When needsWrite is true, a backup file is unconditionally created and the config is rewritten, even when the output is identical to the existing file. This causes a new .bak.<timestamp> file to accumulate on every OpenCode startup.

Fix

Added a content comparison before the backup/write block. The function now reads the existing config file content and compares it against the serialized migration output. If they are identical, the function applies in-memory mutations (e.g. stripped _migrations) and returns false without touching the filesystem. Backup and rewrite only occur when the config content has actually changed.

Changes

File Change
src/shared/migration/config-migration.ts Add content comparison guard before backup creation

Fixes #3222


Summary by cubic

Skip creating .bak.<timestamp> files and rewrites during config migration when the migrated output matches the original in-memory config. This prevents backup sprawl on startup and avoids unnecessary disk I/O.

  • Bug Fixes
    • Compare the serialized migrated config to an originalSnapshot of rawConfig (in-memory) before backup/write.
    • If identical, mutate rawConfig in memory and return; only create a backup and rewrite when content changes.

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

@MoerAI
Copy link
Copy Markdown
Contributor Author

MoerAI commented Apr 10, 2026

I have read the CLA Document and I hereby sign the CLA

Copy link
Copy Markdown

@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.

Auto-approved: Prevents redundant file writes and backups by checking for content changes. Safely updates in-memory config state and returns false correctly when no disk I/O occurs.

Copy link
Copy Markdown

@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.

0 issues found across 1 file (changes from recent commits).

Auto-approved: Prevents redundant backups by comparing serialized config before writing. Correctly handles in-memory object updates and uses standard JSON comparison to avoid unnecessary disk I/O.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant