Skip to content

fix(knowledge): update root versions through YAML fields - #407

Open
Afloat16 wants to merge 2 commits into
simplexai-labs:mainfrom
Afloat16:afloat/okf-version-yaml-shape
Open

Afloat16 wants to merge 2 commits into
simplexai-labs:mainfrom
Afloat16:afloat/okf-version-yaml-shape

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Parse valid repaired frontmatter as a YAML mapping before replacing okf_version. Preserve unrelated field values and the Markdown body, including versions expressed as quoted keys, multiline scalars and flow mappings.

Valid root index metadata no longer becomes invalid YAML or gains duplicate version keys when the Wiki sets its format version. When no repair is needed and the parsed version is already the current string, return the original document byte-for-byte. This avoids rewriting an unchanged root index because YAML serialization reflows a long plain field or changes flow-collection spacing. Metadata that needs normalization still takes the repair path.

How it was verified

Comparison base: 77abdcb37f779f9c9d2de89fa245efa88d3f6584. Linux, Node 26.5.0 and pnpm 11.7.0.

  • Original regressions: five cases failed on the base for folded, quoted, multiline and flow-map versions and preservation of sibling metadata; 22 controls passed.
  • For review 6051565152, added LF and CRLF preservation cases with a long description, flow tags, a quoted version key, a comment and unchanged Markdown. On a4c8751f, the package file produced 2 failed / 28 passed.
  • With the guard, pnpm --filter @linger/knowledge-format check passes typecheck, lint and 30/30 tests. A current-version malformed-frontmatter control confirms required repair still occurs.
  • The real Wiki caller's complete wiki-candidate-validation.llm-wiki.test.ts file passes 36/36.
  • The repository's changed-file check passes formatting, lint and English-only checks; git diff --check passes.

Complete consumer gate

On 7d309573b2e73aa1e7ee45ea0ff45b42f3e6d1c3, pnpm --filter @linger/node-services check exits 0: feature-catalog verification, TypeScript and lint pass; 268 files passed, 8 skipped; 2,711 tests passed, 51 skipped. The published tree ab05aca42ab067f0f936fd1f92b6280b5800b09f matches the locally checked tree. Dependencies were installed with the frozen lockfile in an isolated worktree; the normal configuration and a task-local temporary directory were used. No timeout or skip settings changed.

Hosted run 45565491359 also passes its selected gates. The latest review 6053274955 reports the P2 resolved and no new findings; formal maintainer approval is still pending.

  • Focused tests for the changed behavior
  • make check BASE=origin/<target-branch> or every affected app's fast check
  • No contract regeneration required

Boundary

The owning behavior documentation is updated. No dependency or wire-contract change, network round trip or file walk is added. Live-service/E2E results are not claimed.

@Afloat16
Afloat16 marked this pull request as ready for review November 25, 2026 03:39

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with nits (1 P2)

Scope: base main, merge base 77abdcb3, 1 commit, 3 files reviewed (packages/knowledge-format/src/index.ts, its test, README) plus the only production caller apps/node-services/src/llm-wiki/wiki-candidate-validation.ts. I followed the review guidance from coderbook (design/commits/three passes), ponytail-review (sections 1–3) and karpathy-guidelines (sections 2–3) but did not load those skills separately. The review ran in a separate session.

Findings

P2

packages/knowledge-format/src/index.ts:113: valid frontmatter is now always re-serialized, even when okf_version is already current

The function now always returns document.toString() for valid mapping frontmatter. That rewrites the whole block with yaml's default stringify options, even when nothing needs to change. I checked this with a probe on this head. The input was a root index.md whose version was already "0.2", with a 150-character plain description and tags: [a, b]. The output folded description onto three continuation lines and changed tags to tags: [ a, b ]. The values are the same when parsed, but the text is different.

The caller (wiki-candidate-validation.ts:735, then the write at :762-764) writes index.md whenever the normalized text differs from the original. So every existing root index with a long plain line or a flow collection gets rewritten once, with no semantic change, the next time the wiki candidate is normalized. The old line-based path left an already-current file byte-for-byte unchanged.

Fix (small): return content unchanged when document.get("okf_version") === OKF_VERSION. Optionally, also pass { lineWidth: 0, flowCollectionPadding: false } to toString() so a real version update doesn't reflow sibling fields. Add a test that an index already at 0.2 with a long description comes back unchanged.

Verified as fine

  • Root cause. Valid YAML now goes through parseDocument + document.set (index.ts:108-115). That covers quoted keys, block/folded scalars, multiline quoted scalars and flow-map roots, which the line regex at :117-119 could not handle. Invalid YAML, a non-mapping root, an empty block and duplicate keys with different values (uniqueKeys: true reports an error) all still fall back to the existing line-based path. Nothing is left dead.
  • Sibling values and body. The body is taken from content.slice(match[0].length), the same as before. The new tests check sibling fields with block scalars and flow maps, and check idempotency (index.test.ts:11-41).
  • Quoting. The new value is a string "0.2". Under the core schema the serializer quotes it, so it does not come back as a float. My probe also confirmed that existing single quotes are kept (okf_version: '0.2'), and that anchors and aliases survive (x: &a {...}, y: *a). toString() does not expand aliases, so leaving out maxAliasCount does not cause alias blow-up.
  • CRLF. As before, the frontmatter is emitted with LF and the body keeps its own line endings. The old fallback also joined lines with \n, so this is unchanged.
  • Caller compatibility. removeDuplicateRootVersion (wiki-candidate-validation.ts:1000) only touches the body and still applies. normalizeOkfMarkdown runs afterwards on output that is already valid.
  • Repository rules. No CJK in added lines or the commit message. No new dependency (yaml is already a dependency). The README update matches the behavior. Commit subject: fix(knowledge): ….

Process notes

  • None. There is one commit, it is not a merge or fixup, and its author is linked (Afloat16).
  • mergeStateStatus is BLOCKED, presumably pending required review. The branch is not behind.

CI

  • All required checks that ran pass: check (packages), repository-gate, web-static, web tests and changes. The others were skipped by path selection.
  • CI did not run the consumer @linger/node-services. I ran it locally: vitest run tests/llm-wiki/wiki-candidate-validation.llm-wiki.test.ts passed (36/36).
  • I also ran packages/knowledge-format src/index.test.ts together with a temporary probe test (28/28 passed). The probe produced the reformatting described in the P2 above. I deleted the probe afterwards; the tree is clean.

Automated review by Claude Code


Automated review of a4c8751 by Claude Code.

Return a valid current-version root index unchanged when no frontmatter
repair is needed, so wiki normalization does not rewrite long scalar lines
or flow collection spacing.

Keep normalization for malformed metadata and cover LF/CRLF byte preservation.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 findings)

Scope: follow-up on a4c8751, reviewing head 7d30957 against main (merge base 77abdcb); 2 commits, 3 files. Loaded coderbook. ponytail-review and karpathy-guidelines were not loaded because they were not needed for a 12-line change. The review ran in a separate session.

Previous findings

  • P2: Frontmatter is re-serialized even when the version is already 0.2. Resolved. packages/knowledge-format/src/index.ts:114 now returns content unchanged when two things hold: repairOkfFrontmatter left the block untouched, and okf_version already equals the string OKF_VERSION. The new test keeps an already-current root index byte-for-byte covers LF and CRLF, and also covers a long plain description, flow-list spacing and a quoted key with a comment. still repairs current-version frontmatter that needs normalization confirms that malformed metadata still gets repaired.

Findings

None.

Verified as fine

  • The early-return condition is narrow enough.
    • An unquoted okf_version: 0.2 parses as the number 0.2 under the core schema, so it fails the === OKF_VERSION check and is still rewritten to the string.
    • Duplicate keys make parseDocument(..., { uniqueKeys: true }) report errors, so that input falls through to the line-based fallback (index.ts:111-124).
    • A quoted "okf_version" key still resolves through document.get. The CRLF test exercises this.
  • The caller still behaves the same. apps/node-services/src/llm-wiki/wiki-candidate-validation.ts:735 passes the result through removeDuplicateRootVersion (:1000), which accepts \r?\n. Before, the frontmatter was re-serialized with LF; now the original newlines are kept, and that function handles both. I traced the existing test normalizes a duplicate root OKF version emitted as body text (apps/node-services/tests/llm-wiki/wiki-candidate-validation.llm-wiki.test.ts:739) by hand through the new early-return path. It still yields ---\nokf_version: "0.2"\n---\n\n# Wiki\n. I traced this rather than running it, because dependencies are not installed in this worktree.
  • Docs match the code. The README states the byte-for-byte guarantee and that repair still happens, and that matches the code.
  • Added lines and commit messages contain no CJK. The PR changes no dependencies and no contracts.

Process notes

  • origin/main is 338 commits ahead of the merge base, and main requires branches to be up to date. The branch probably needs a rebase before merge.
  • The PR has no merge commits. The second commit is a separate behavior refinement with its own test, not a fixup.

CI

All checks that ran pass: check (packages), check (web), web tests (1/2, 2/2), web-static, repository-gate, changes. Checks for the other apps were skipped by path selection. No node-services check ran, even though the LLM Wiki caller's behavior changes slightly, which is why I traced its test by hand. I ran no tests myself.

Automated review by Claude Code


Automated review of 7d30957 by Claude Code.

@Afloat16

Copy link
Copy Markdown
Contributor Author

Addressed P2 in 7d309573b2e73aa1e7ee45ea0ff45b42f3e6d1c3.

The function now returns the original document only when the parsed mapping already has the current string version and repairOkfFrontmatter left the block unchanged. This preserves the long plain field, flow spacing, comments, line endings and Markdown body without bypassing repairs that are still needed.

The two new LF/CRLF cases failed on the previous head; the package check now passes all 30 tests with typecheck and lint. A current-version malformed-frontmatter control confirms normalization still runs. The actual Wiki caller file also passes 36/36.

The complete Node Services check passes on the published tree: 268 files / 2,711 tests, with the existing 8 files / 51 tests skipped. Feature-catalog verification, typecheck, lint and the changed-file checks also pass. Integration with current main follows the merge queue described in CONTRIBUTING.md.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 findings)

Scope: follow-up on 7d30957 (the head is unchanged since the previous review, which had no findings). I re-ran the assumption check over the whole PR against the merge base 77abdcb3 on main. Reviewed 2 commits and 3 files (packages/knowledge-format/{README.md,src/index.ts,src/index.test.ts}). Loaded the review skill's checklist; coderbook, ponytail-review and karpathy-guidelines were applied from that checklist and not loaded separately. This review ran in a separate session.

Previous findings

The previous review on 7d30957 reported no findings, so there is nothing to carry over.

Findings

None.

Verified as fine

  • Fallback when the YAML is not a usable map. The new path runs only when document.errors.length === 0 && isMap(document.contents) (packages/knowledge-format/src/index.ts:113). Duplicate keys (uniqueKeys: true), invalid YAML, an empty block and a non-map root all fall through to the existing line-based replacement at index.ts:120-125. document.toString() throws only when the document has errors, and that case is excluded before it is called.
  • Byte-for-byte return when nothing needs to change. The early return needs both repaired === block and a parsed string version equal to OKF_VERSION (index.ts:114). Metadata that needs repair still goes through normalization, which the test "still repairs current-version frontmatter that needs normalization" covers.
  • Caller interaction. apps/node-services/src/llm-wiki/wiki-candidate-validation.ts:735 passes the result through removeDuplicateRootVersion, which only edits the body, and then normalizeOkfMarkdown (:757, :762). The file is rewritten only when the result differs from the original (:763). With the early return, an already-current index is no longer rewritten. No other callers exist (git grep setOkfRootIndexVersion).
  • Inputs I probed myself with a temporary focused vitest file, deleted afterwards:
    • A plain numeric okf_version: 0.1 or 0.2 (a number under the core schema) is written as the string "0.2", not left as a number.
    • Anchors and aliases are preserved, and so are comments on sibling keys.
    • With CRLF input, the frontmatter comes out as LF while the body keeps CRLF. The old line-based path already did the same.
    • Missing versions are appended.
    • Every output parses with no issues, is a fixed point of normalizeOkfMarkdown, and stays unchanged when setOkfRootIndexVersion runs again.
  • PR description claims. The quoted-key, multiline, folded and flow-map cases, the LF/CRLF preservation case and the repair control all exist in src/index.test.ts. The README documents the new behavior. No contract, env or dependency change is involved: yaml's parseDocument/isMap were already imported at index.ts:1.
  • Other checks.
    • No CJK in the added lines or in the commit messages.
    • No merge commits and no fixup commits.
    • No duplicate helper: it reuses repairOkfFrontmatter and the FRONTMATTER_BLOCK regex.

Process notes

None. mergeStateStatus is BLOCKED, which is consistent with a pending required approval. The branch is not behind main (the merge base is main's current tip 77abdcb3).

CI

Selected gates pass: check (packages), check (web), both web tests shards, web-static, repository-gate and changes. Other app checks were skipped by the path plan. CI does not run @linger/node-services for this change. The PR body reports that a local full pnpm --filter @linger/node-services check passed, but I did not re-run it. The only thing I ran was the temporary probe described above, and it passed.

Automated review by Claude Code


Automated review of 7d30957 by Claude Code.

@Afloat16

Copy link
Copy Markdown
Contributor Author

Consolidated review request for the current ready heads

@LeoXing1996, could you review these changes, or route them to the appropriate maintainer, and queue acceptable changes for merge? You previously reviewed the Node Services work in #408; these follow the same repository checks and contribution process.

All twelve PRs are ready for review and currently mergeable without conflicts. The checks reported for their current heads have completed without failures. Each description records the owning-package validation and its limits; the hosted matrix skips are kept distinct from the local Node Services checks.

PR Current head Scope
#405 631da2fc Drain source writes before releasing a failed sync
#407 7d309573 Preserve YAML fields and already-current root indexes
#412 41e454b3 Candidate-window contract tests and documentation only
#413 7d187509 Unicode name lengths and plain-word alias filtering
#415 3c94ac45 Reject cancelled image bundles after reads
#416 e9aae7d6 Preserve carriage-return delimited records
#417 2bbd2341 Refuse blocking special-file source reads
#418 cd2b54a8 Query-only BM25 counting; latest follow-up moves documentation
#420 3395075c Bound delimited table expansion by the output budget
#421 fdcf914c Reject stale worker-readiness probes
#422 6adc5c16 Preserve literal links, BOMs and label/title boundaries
#423 8f592821 Fence Wiki publication after lock ownership is lost

The incorrect shared-budget runtime proposal in #412 has been withdrawn, and its title and description now match the tests-only diff. Recent follow-ups for #407, #413 and #422 have no remaining findings in their latest review. Formal maintainer approval is still required by branch protection. Integration with current main can follow the merge queue described in CONTRIBUTING.md.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant