{"record":{"id":"6e806e0587fe74dc","repo":"dagger/dagger","slug":"failed-to-create-new-copy-ref-w","errorCode":null,"errorMessage":"failed to create new copy ref: %w","messagePattern":"failed to create new copy ref: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/filesync/localfs.go","lineNumber":176,"sourceCode":"//\n// NOTE: This currently does not handle resetting parent dir modtimes to match the client. This matches\n// upstream for now and avoids extra performance overhead + complication until a need for those modtimes\n// matching the client's is proven.\nfunc (local *localFS) Sync( //nolint:gocyclo\n\tctx context.Context,\n\tremote ReadFS,\n\tcacheManager bkcache.Accessor,\n\tforParents bool,\n) (_ bkcache.ImmutableRef, _ digest.Digest, rerr error) {\n\tvar newCopyRef bkcache.MutableRef       // the mutable ref we will copy into with the frozen files+dirs if needed\n\tvar cacheCtx bkcontenthash.CacheContext // track file+dir hashes\n\n\t// skip creating a cache ref if we're only syncing parent dirs\n\tif !forParents {\n\t\tvar err error\n\t\tnewCopyRef, err = cacheManager.New(ctx, nil)\n\t\tif err != nil {\n\t\t\treturn nil, \"\", fmt.Errorf(\"failed to create new copy ref: %w\", err)\n\t\t}\n\t\tdefer func() {\n\t\t\tctx := context.WithoutCancel(ctx)\n\t\t\tif newCopyRef != nil {\n\t\t\t\tif err := newCopyRef.Release(ctx); err != nil {\n\t\t\t\t\trerr = errors.Join(rerr, fmt.Errorf(\"failed to release copy ref: %w\", err))\n\t\t\t\t}\n\t\t\t}\n\t\t}()\n\n\t\tnewCopyMD, ok := any(newCopyRef).(bkcache.RefMetadata)\n\t\tif !ok {\n\t\t\treturn nil, \"\", fmt.Errorf(\"copy ref metadata: unexpected ref type %T\", newCopyRef)\n\t\t}\n\t\tcacheCtx, err = bkcontenthash.GetCacheContext(ctx, newCopyMD)\n\t\tif err != nil {\n\t\t\treturn nil, \"\", fmt.Errorf(\"failed to get cache context: %w\", err)\n\t\t}","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/filesync/localfs.go#L158-L194","documentation":"In localFS.Sync, when not syncing parents-only (forParents=false), a fresh cache ImmutableRef is allocated with cacheManager.New(ctx, nil) to hold the copied data. If the cache manager cannot allocate the ref, the error is wrapped as \"failed to create new copy ref\". It indicates the engine's content cache refused/failed to create a new mutable record.","triggerScenarios":"cacheManager.New(ctx, nil) failing during a normal host-directory sync: cache backend I/O error, context cancelled mid-allocation, or cache store corrupted/full.","commonSituations":"Engine disk full (ENOSPC on the cache volume), corrupted buildkit cache database, context cancellation (Ctrl-C) racing the allocation, container running with a read-only cache mount.","solutions":["Check the wrapped cause: if ENOSPC, free space on the engine cache volume (dagger engine prune).","Restart the engine / clear the cache if the buildkit cache DB is corrupted.","Avoid cancelling the client context during sync; retry with a clean context.","Verify the cache volume is writable in the engine container configuration."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// preflight: ensure the engine cache volume has free space and is writable\n// df -h <cache-dir> && touch <cache-dir>/.writetest && rm <cache-dir>/.writetest","typeGuard":null,"tryCatchPattern":"newRef, err := cacheManager.New(ctx, nil)\nif err != nil {\n    if errors.Is(err, context.Canceled) {\n        return fmt.Errorf(\"sync cancelled during cache ref allocation; retry with a clean context\")\n    }\n    return fmt.Errorf(\"check engine cache volume (space/permissions/corruption): %w\", err)\n}","preventionTips":["Keep free space on the engine cache volume; prune regularly.","Don't cancel contexts mid-sync; Ctrl-C races the ref allocation.","Recreate the engine if the buildkit cache DB is suspected corrupted.","Ensure the cache mount is read-write in the engine container config."],"tags":["cache","buildkit","filesync","engine"],"backgroundTag":"cache-ref-allocation-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}