Skip to content

Memory: MemoryTypes.ts hand-copies the relation vocabulary and has fallen behind KnowledgeSchema.ts, so any proposal with a derived-from link is rejected whole #2827

Open

Description

@Luo0oo

What. The relation vocabulary for Cortex related: links has one canonical definition and three hand-maintained copies that have drifted apart:

Where Members Has derived-from
LIFEOS/TOOLS/KnowledgeSchema.ts:119 RELATION_VOCAB (canonical, what validate() and KnowledgeLint check notes against) 9 ✅
LIFEOS/TOOLS/MemoryTypes.ts:140 RelatedLinkType and :155 ALL_RELATED_TYPES 8 ❌
LIFEOS/TOOLS/MemoryReviewer.ts:532, the reviewer's system prompt: "The 8 valid related types are: …" 8 ❌
skills/Cortex/References/CompleteGuide.md:97, "9 relationship types" table 9 ✅

What happens. sanitizeTypedItemForPersistence in LIFEOS/TOOLS/MemorySystem.ts checks each link's type against ALL_RELATED_TYPES (:779) and returns invalid for the whole item on the first unknown type. So a proposal the knowledge schema would accept is thrown away by the memory loop:

sanitizeTypedItemForPersistence({ type: "idea", title: "t", content: "c", source_session: "s",
  confidence: 0.9, related: [{ slug: "other-note", type: "supports" }] })
// → { ok: true, ... }

sanitizeTypedItemForPersistence({ ...same, related: [{ slug: "other-note", type: "derived-from" }] })
// → { ok: false, code: "EINVAL_ITEM", message: "related[0].type is invalid" }

The whole idea is lost, not just the link. Today the reviewer prompt also lists only 8 types, so it rarely proposes derived-from, which hides the bug; the next member added to RELATION_VOCAB will hit it the same way, and adding it to the prompt alone would make the loss common.

Suggested fix. Derive every copy from RELATION_VOCAB instead of copying it:

  1. In MemoryTypes.ts, import RELATION_VOCAB and RelationType from ./KnowledgeSchema and re-export them as ALL_RELATED_TYPES and RelatedLinkType, so existing imports keep working.
  2. In MemoryReviewer.ts, build the prompt's list and count from ALL_RELATED_TYPES (${ALL_RELATED_TYPES.length}, ${ALL_RELATED_TYPES.join(", ")}).
  3. Object.freeze RELATION_VOCAB where it is defined: as const is type-level only, and once MemoryTypes aliases the array, a single bad cast could otherwise widen the schema validator itself.
  4. A small test that fails when any of these files carries a hand-typed member list, so the class of drift turns a suite red rather than this one instance.

CompleteGuide.md is model-facing prose, so it cannot import; a check that its stated count and members match RELATION_VOCAB would keep it honest.

We have run this derivation locally since September 2026, and it has held across the 7 → 8 upgrade.

Activity

  1. Luo0oo commented on Nov 16, 2026

    @Luo0oo
    Author

    Note

    🤖 Harper (AI assistant) responding on behalf of Luo

    A correction to suggestion 4 above, from testing it properly. The test we run locally compares the reviewer prompt's list with ALL_RELATED_TYPES. A planted control showed it catches a stale list, such as the 8-member one, but not a hand-typed list that happens to equal today's vocabulary: that passes until the next member is added. So it is a drift check, not a "no hand-typed copy" check, and I overstated it.

    If you want the stronger guarantee, a behavioural check holds up better than one that inspects how the source is written. Feed sanitizeTypedItemForPersistence one link of every RELATION_VOCAB member and assert that none is rejected, after first asserting that an unknown type is rejected, so the check cannot pass vacuously. That fails the moment any copy lags, whatever the copy looks like.

    For CompleteGuide.md, the check that has held up for us reads the stated "N relationship types" and the table under it, then compares both the count and the member set with RELATION_VOCAB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions