flipped-aurora/gin-vue-admin · error

清理重复 staging 文件失败: %w

Error message

清理重复 staging 文件失败: %w

What it means

Raised when the target file already contains exactly the content this task wants to publish (currentHash == AfterHash), and deleting the now-redundant staged copy fails with an error other than NotExist. The task treats the publish as a no-op but must remove the staging file to avoid leaking temp files; that cleanup failure aborts the commit.

Source

Thrown at server/service/system/auto_code_task.go:197

		published, err := publish(file)
		if err != nil {
			return applied, err
		}
		if published {
			applied = append(applied, index)
		}
	}
	return applied, nil
}

func publishPreparedAutoCodeFile(file *autoCodeTaskFile) (bool, error) {
	currentHash, exists, err := hashAutoCodeTarget(file.TargetPath)
	if err != nil {
		return false, err
	}
	if exists && currentHash == file.AfterHash {
		if removeErr := os.Remove(file.StagedPath); removeErr != nil && !errors.Is(removeErr, fs.ErrNotExist) {
			return false, fmt.Errorf("清理重复 staging 文件失败: %w", removeErr)
		}
		file.StagedPath = ""
		return false, nil
	}
	if exists != file.Existed || (file.Existed && currentHash != file.BeforeHash) {
		return false, fmt.Errorf("%w: %s", errAutoCodeFileConflict, file.TargetPath)
	}
	if err = os.MkdirAll(filepath.Dir(file.TargetPath), 0o755); err != nil {
		return false, fmt.Errorf("创建目标目录 %s 失败: %w", filepath.Dir(file.TargetPath), err)
	}
	if err = os.Rename(file.StagedPath, file.TargetPath); err != nil {
		return false, fmt.Errorf("原子发布 %s 失败: %w", file.TargetPath, err)
	}
	file.StagedPath = ""
	return true, nil
}

func (task *autoCodeFileTask) rollback(applied []int) error {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check permissions/ownership of the staging directory (parent repo root) and the staged file; ensure the server process can delete them
  2. Confirm no external cleanup job deleted/locked .autocode-staging-* directories mid-task
  3. Re-run the task after freeing the file (close editors/watchers holding it)
  4. If persistent, ensure staging dir and target are on the same writable local filesystem

Example fix

// before: server running as user without write access to repo root staging dir
$ sudo -u gva ./server  # os.Remove(.autocode-staging-xxx/000001) -> permission denied

// after: chown the workspace to the service user
$ sudo chown -R gva:gva /path/to/project
Defensive patterns

Strategy: retry

Validate before calling

func stagingDirWritable(root string) error {
	probe, err := os.MkdirTemp(root, autoCodeStagingPrefix)
	if err != nil {
		return err
	}
	if err := os.Remove(probe); err != nil {
		return fmt.Errorf("staging cleanup probe failed: %w", err)
	}
	return nil
}

Try / catch

published, err := publishPreparedAutoCodeFile(file)
if err != nil && strings.Contains(err.Error(), "清理重复 staging 文件失败") {
	// transient lock/cleanup issue: clear stale staging dirs and retry once
	os.RemoveAll(staleStagingDirs(root))
	published, err = publishPreparedAutoCodeFile(file)
}

Prevention

When it happens

Trigger: publishPreparedAutoCodeFile detects target content already matches AfterHash, then os.Remove(file.StagedPath) fails due to permission problems on the staging directory, the staged file being held/locked, or the staging dir having been removed by an external cleaner between prepare and commit.

Common situations: Running the server as a different user than the one that created the .autocode-staging-* dir; tmp cleaner jobs removing staging files; read-only temp filesystem; disk full is unlikely for remove but immutable attributes can block it.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/911440e666889e57. Report an issue: GitHub.