Skip to content

OKF migration leaves broken internal links after RebuildIndex #9

Description

@mashenjun

Summary

After generating a wiki through /remember plus /compile, running engram9 migrate-okf --write converts legacy frontmatter successfully, but engram9 validate --strict still fails because generated internal links are broken.

Reproduction

  1. Start engram9 with a valid OpenAI-compatible model.
./engram9 -addr :9090 \
  -data ./claude-notes/catstock-stock-wiki \
  -model deepseek-v4-pro \
  -compile-interval 0
  1. Import multiple source documents through /remember.

  2. Wait for integrations to finish, then compile.

curl -sS -X POST http://127.0.0.1:9090/compile \
  -H "Content-Type: application/json" \
  -d "{}"
  1. Migrate the generated wiki to OKF.
./engram9 migrate-okf --write ./claude-notes/catstock-stock-wiki/wiki
  1. Validate strictly.
./engram9 validate --strict ./claude-notes/catstock-stock-wiki/wiki

Actual Result

Migration succeeds, but strict validation fails with broken internal links only.

OKF migration wrote: 94 file(s), 91 change(s)
OKF validation failed: 94 file(s), 0 error(s), 130 warning(s); strict mode treats warnings as failure

Examples:

warning semantic/index.md: broken internal link: semantic/companies/spacex.md
warning episodic/index.md: broken internal link: episodic/2026-06-24/samsung-400b-buyback.md
warning semantic/ai/anthropic-distillation-report.md: broken internal link: companies/anthropic.md

Expected Result

After migrate-okf --write, engram9 validate --strict <wiki> should pass, or at minimum generated structural indexes should not contain invalid relative links.

Suspected Causes

  1. RebuildIndex() writes category sub-index links using paths relative to the wiki root even when writing wiki/semantic/index.md or wiki/episodic/index.md.

Current code in internal/storage/fs.go:

lines = append(lines, fmt.Sprintf("- [%s](%s) — %s", filepath.Base(p.relPath), p.relPath, p.desc))

For wiki/semantic/index.md, a link like semantic/companies/spacex.md resolves as wiki/semantic/semantic/companies/spacex.md, which is invalid.

  1. Agent prompts still instruct legacy [[...]] links and do not require link targets to exist, so the LLM can emit links to missing pages such as semantic/companies/changxin-memory.md or semantic/commodities/oil.md.

Suggested Fix

  1. Generate sub-index links relative to the sub-index file directory.
  2. Add a regression test for RebuildIndex() that validates root index.md and category index.md links with engram9 validate --strict.
  3. Consider constraining agent prompts or write tools so internal links point only to existing pages unless a matching page is created in the same operation.

Activity

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