{"record":{"id":"1788429752cb1d44","repo":"multica-ai/multica","slug":"reconcile-stale-s-w","errorCode":null,"errorMessage":"reconcile stale %s: %w","messagePattern":"reconcile stale (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/internal/daemon/execenv/hermes_home.go","lineNumber":562,"sourceCode":"\n// reconcileMirroredEntries removes overlay entries that are neither overlay-owned\n// nor currently mirrored from the shared home, so a shared entry deleted between\n// runs (or a Windows copy-fallback left behind) doesn't survive as stale state.\nfunc reconcileMirroredEntries(hermesHome string, mirrored map[string]struct{}) error {\n\tentries, err := os.ReadDir(hermesHome)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read overlay home: %w\", err)\n\t}\n\tfor _, entry := range entries {\n\t\tname := entry.Name()\n\t\tif isHermesOverlayOwnedEntry(name) {\n\t\t\tcontinue\n\t\t}\n\t\tif _, keep := mirrored[name]; keep {\n\t\t\tcontinue\n\t\t}\n\t\tif err := os.RemoveAll(filepath.Join(hermesHome, name)); err != nil {\n\t\t\treturn fmt.Errorf(\"reconcile stale %s: %w\", name, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// prepareHermesTaskLocalState migrates an overlay built by an older daemon away\n// from the shared Hermes SQLite session store. Without the marker, state.db and\n// its sidecars may be symlinks or independently copied files; neither is safe to\n// reuse as task-local state. Remove only those entries inside the generated\n// overlay, then record the migration atomically. Hermes lazily creates a fresh\n// database, and later prepares preserve it because the marker is present.\nfunc prepareHermesTaskLocalState(hermesHome string) error {\n\tmarker := filepath.Join(hermesHome, hermesTaskLocalStateMarker)\n\tif fi, err := os.Lstat(marker); err == nil {\n\t\tif !fi.Mode().IsRegular() {\n\t\t\treturn fmt.Errorf(\"state marker is not a regular file: %s\", marker)\n\t\t}\n\t\treturn nil","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/daemon/execenv/hermes_home.go#L544-L580","documentation":"reconcileMirroredEntries tried to os.RemoveAll an overlay entry that is neither overlay-owned nor currently mirrored from the shared home, and the removal failed. This is the pruning half of mirroring: a shared entry deleted between runs (or a Windows copy-fallback file) must not linger, and a failed prune aborts the overlay rather than shipping stale state.","triggerScenarios":"The stale entry is read-only or owned by another user; on Windows the file is open/locked (SQLite or indexer holding a handle); the dir contains a file the daemon UID cannot unlink (sticky bit, immutable flag).","commonSituations":"Overlay reused across runs with changed UIDs; a previous task still holds an open handle to a pruned file on Windows; a leftover root-owned file from a privileged debugging session.","solutions":["Identify the named entry under hermes-home and check ownership/permissions: fix with chown/chmod -R on the overlay dir.","On Windows, stop processes holding handles to the entry (or reboot) and retry the task.","If ownership is unsalvageable, wipe the entire overlay dir — it is fully regenerable from the shared home.","Run the daemon under a consistent UID so overlay entries are always deletable by later runs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := reconcileMirroredEntries(hermesHome, mirrored); err != nil {\n\tvar pe *os.PathError\n\tif errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES) {\n\t\t// foreign-owned or read-only stale entry: reset the whole regenerable overlay\n\t\treturn os.RemoveAll(hermesHome) // caller rebuilds on next prepare\n\t}\n\treturn err\n}","preventionTips":["Run all tasks for an env under the same UID.","On Windows, make sure previous task processes exit before overlay reuse.","Do not chmod overlay contents read-only; the daemon must be able to prune them."],"tags":["filesystem","windows","hermes","execenv","stale-state"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}