Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Correct the unreadable-reference rationale (PRD-7687) (#3124)

tim-inkeep2a7217bea7c7
diff --git a/packages/server/src/skill-path-classifier-equivalence.test.ts b/packages/server/src/skill-path-classifier-equivalence.test.ts
index f045fa4a9..eeac2116d 100644
--- a/packages/server/src/skill-path-classifier-equivalence.test.ts
+++ b/packages/server/src/skill-path-classifier-equivalence.test.ts
@@ -18,7 +18,7 @@ import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSyn
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { parseSkillDir } from '@inkeep/open-knowledge-core/skills-catalog';
-import { beforeEach, describe, expect, test } from 'vitest';
+import { afterEach, beforeEach, describe, expect, test } from 'vitest';
import { classifyHostEntry } from './skill-migrate.ts';
import { classifyInPlaceDest } from './skill-projection.ts';
@@ -46,6 +46,9 @@ beforeEach(() => {
canonicalHash = parseSkillDir(canonical)?.contentHash ?? '';
expect(canonicalHash).not.toBe('');
});
+afterEach(() => {
+ rmSync(root, { recursive: true, force: true });
+});
/** Both classifiers, over the same path, in one call. `occupied` reports its
* `by` discriminator too — that is the whole reason the payload exists. */
@@ -139,13 +142,11 @@ describe('the two classifiers DISAGREE, deliberately', () => {
});
});
-// The reference bundle can be unreadable at classification time (a concurrent
-// delete between the caller resolving its realpath and this call). The two
-// classifiers used to disagree here and now do not: projection always returned
-// `different`, migration hash-compared and could return `same-copy`. Unifying
-// on the shared walk adopted projection's answer for both. That is the SAFE
-// direction for migration, whose `same-copy` branch deletes the store dir, so
-// the row is pinned deliberately rather than left to drift back.
+// The reference bundle can be unreadable at classification time: a concurrent
+// delete between the caller resolving its realpath and this call. Both
+// classifiers answer `different` there, and this row exists so that stays true.
+// What the answer costs, and why the walk cannot do better without changing
+// shape, is in `skill-path-entry.ts`'s header.
describe('the reference bundle is gone', () => {
test('a byte-identical real dir reads as `different` for BOTH once the reference is unreadable', () => {
const dest = join(root, 'same-copy-orphaned');
diff --git a/packages/server/src/skill-path-entry.ts b/packages/server/src/skill-path-entry.ts
index fa4c97507..ad5dfed03 100644
--- a/packages/server/src/skill-path-entry.ts
+++ b/packages/server/src/skill-path-entry.ts
@@ -20,11 +20,18 @@
* | symlink → nothing (dangling) | link (removable) | occupied(foreign-link) |
* | dir that IS the reference | canonical-dir | same-copy |
*
- * One row the two USED to disagree on and no longer do: when the reference dir
- * itself is unreadable, projection always answered `different` while migration
- * hash-compared and could answer `same-copy`. The shared walk adopts
- * projection's answer for both, which is the safe direction because migration's
- * `same-copy` branch deletes the store dir. Pinned in the equivalence suite.
+ * An unreadable `referenceDir` yields `different` for a real dir at `path`
+ * under both callers, rather than falling through to a hash compare that could
+ * call the entry a same-content copy. A symlink at `path` reads `dangling` in
+ * that same race instead: the reference realpath sits inside that branch's own
+ * `try`, so the throw never reaches the dir arm. Migration is the only caller
+ * for which the `different` answer costs anything, and only when the store dir
+ * is already gone: no user content is at risk either way, since its `same-copy`
+ * branch would be rm-ing a path that no longer exists. What it costs is the
+ * install-marker entry, which the `same-copy` path would have dropped and the
+ * skip does not. The walk cannot tell which `realpathSync` threw, so
+ * distinguishing the two is a change to this function rather than a mapping
+ * choice. Pinned in the equivalence suite.
*
* Those rows are not oversights. Migration treats a dangling link as foreign on
* purpose — an OK projection whose store source is about to move would not