Skip to content

Fix delta deploy failure when cached and changed files share directories#689

Merged
phinze merged 1 commit intomainfrom
phinze/fix-delta-deploy-dir-exists
Mar 24, 2026
Merged

Fix delta deploy failure when cached and changed files share directories#689
phinze merged 1 commit intomainfrom
phinze/fix-delta-deploy-dir-exists

Conversation

@phinze
Copy link
Copy Markdown
Contributor

@phinze phinze commented Mar 23, 2026

We hit this in prod deploying cloud to a cluster running v0.6.0 — the deploy failed with error extracting changed files: mkdir /tmp/buildkit-3500590234/db: file exists. The workaround was to SSH in and nuke the source code cache, which forced a full upload instead of a delta.

The issue is a collision between the two phases of a delta deploy. PrepareUpload stages cached files into a temp directory, creating parent directories as needed with os.MkdirAll. Then BuildFromPrepared extracts the changed-files tar into that same directory using TarFS, which calls bare os.Mkdir — no tolerance for directories that already exist. If any directory appears in both the cached and changed file sets (like db/ in this case), boom.

One-line fix: add an os.IsExist check so TarFS skips directory entries that are already present, just like extractFilesFromLayer already does. Added a test that reproduces the exact scenario.

TarFS used os.Mkdir to create directories from tar entries, which fails
if the directory already exists. During a delta deploy, PrepareUpload
stages cached files into the session directory (creating parent dirs
with os.MkdirAll), then BuildFromPrepared extracts the changed-files
tar into that same directory. If the tar contains directory entries
that were already created during staging, the deploy blows up with
"error extracting changed files: mkdir .../db: file exists".

Tolerate pre-existing directories by checking os.IsExist on the error,
matching how extractFilesFromLayer already handles this.
@phinze phinze requested a review from a team as a code owner March 23, 2026 23:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5328242-2240-4658-90a7-7f20f3227ed3

📥 Commits

Reviewing files that changed from the base of the PR and between 316ceaf and 2e7d133.

📒 Files selected for processing (2)
  • pkg/tarx/tarx.go
  • pkg/tarx/tarx_test.go

📝 Walkthrough

Walkthrough

The TarFS function in pkg/tarx/tarx.go was modified to handle pre-existing directories. When extracting directory entries from a tar archive, the function now suppresses errors from os.Mkdir if the directory already exists on the target path, rather than aborting. Correspondingly, a new unit test TestTarFS_PreExistingDirectory was added to pkg/tarx/tarx_test.go that verifies this behavior by pre-creating directories on disk before extracting, confirming that TarFS completes successfully and correctly writes file contents even when the target directory structure already exists.


Comment @coderabbitai help to get the list of available commands and usage tips.

@phinze phinze merged commit 7cbab06 into main Mar 24, 2026
10 checks passed
@phinze phinze deleted the phinze/fix-delta-deploy-dir-exists branch March 24, 2026 14:14
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.

2 participants