Skip to content

fix(weave): append-only current-only ReferenceCatalog inventory weave - #34

Merged
djradon merged 1 commit into
mainfrom
lane/reference-catalog-append
Aug 2, 2026
Merged

fix(weave): append-only current-only ReferenceCatalog inventory weave#34
djradon merged 1 commit into
mainfrom
lane/reference-catalog-append

Conversation

@djradon

@djradon djradon commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Bite 1 of wa.task.2026.2026-05-17-append-onlyish-inventory — the first production consumer migrated onto the existing planInventoryAppend. Brief and evidence audit are in that note.

What

renderCurrentOnlyReferenceCatalogWovenKnopInventoryTurtle previously split the KnopInventory into subject blocks, replaced the ReferenceCatalog block, upserted a page block, and rejoined the whole document. It now routes through planInventoryAppend, so the operation:

  • preserves the existing inventory byte-for-byte as an exact prefix,
  • appends only genuinely missing settled facts,
  • returns the exact input bytes on a semantic no-op,
  • fails with both requested and existing facts named on a real conflict,
  • treats only sflo:hasWorkingLocatedFile as single-valued — hasResourcePage is not functional in the core ontology (verified: plain owl:ObjectProperty).

The planner itself is untouched; this is a consumer migration.

It also closed a false negative

The conflict test found a defect in the code being replaced: the old substring guard accepted the requested working locator appearing in an unrelated ex: predicate while a different locator was actually carried — so a genuine conflict passed silently. The new path refuses it.

Fail-on-old, all three recorded

  • Append: failed the exact-prefix assertion, because the old renderer rejoined blocks.
  • No-op: failed byte equality — the old renderer reordered page types and dropped a trailing blank line.
  • Conflict: threw nothing at all under the old guard.

New tests live in src/core/weave/knop_inventory_renderers_test.ts, deliberately kept out of weave_test.ts to avoid colliding with concurrent lanes. Full deno task ci and deno task build:npm-lib green.

Not in this bite

Versioned ReferenceCatalog history, the PageDefinition twin, MeshInventory/payload/batch/progression refactors, and — flagged as its own correctness bite — the resource_page_policy.ts path that deletes disallowed settled page facts, a sharper violation of the append-onlyish contract than what this fixes.

Implemented by Codex (codex exec) as Kim under the standing grant; reviewed, gated, and landed by the planning seat.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LHrFYeUefDr227gLuWWuq1

Summary by CodeRabbit

  • New Features

    • Current-only ReferenceCatalog inventory rendering now adds requested catalog facts while preserving existing content.
    • Generated IRIs and predicates are normalized for consistent output.
  • Bug Fixes

    • Conflicting requested and existing catalog facts now produce a clear input error.
    • Unchanged inventories remain byte-for-byte identical.
  • Tests

    • Added coverage for fact appending, exact-prefix preservation, unchanged output, and conflict reporting.

- renderCurrentOnlyReferenceCatalogWovenKnopInventoryTurtle now routes
  through the existing planInventoryAppend instead of splitting,
  replacing, and rejoining subject blocks: existing inventory bytes are
  preserved as an exact prefix, a semantic no-op returns the exact input
  bytes, and only hasWorkingLocatedFile is treated as single-valued
  (hasResourcePage is not functional in the ontology)
- conflicts now report both requested and existing facts instead of a
  substring guard
- new knop_inventory_renderers_test.ts (kept out of the active-lane
  weave_test.ts): fail-on-old recorded for all three — the append test
  failed exact-prefix because the old renderer rejoined blocks; the
  no-op test failed byte equality because the old renderer reordered
  page types and dropped a trailing blank line; the conflict test threw
  nothing because the old substring guard accepted the requested
  locator appearing in an unrelated ex: predicate while a different
  working locator was carried
- first production consumer migrated onto the append planner per
  wa.task.2026.2026-05-17-append-onlyish-inventory (brief in that note)

Implemented-By: Codex (codex exec) as Kim
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LHrFYeUefDr227gLuWWuq1
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

ReferenceCatalog inventory rendering

Layer / File(s) Summary
Plan ReferenceCatalog fact appends
src/core/weave/knop_inventory_renderers.ts
The renderer uses planInventoryAppend for current-only facts, reports conflicting IRIs with WeaveInputError, preserves no-op inventories, and compacts generated RDF values.
Validate rendering outcomes
src/core/weave/knop_inventory_renderers_test.ts
Tests verify prefix preservation, byte-for-byte no-op output, and conflict error details.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Renderer as ReferenceCatalog renderer
  participant Planner as planInventoryAppend
  participant Inventory as Existing inventory
  participant Error as WeaveInputError
  Renderer->>Planner: Submit requested facts
  Planner->>Inventory: Compare existing facts
  alt Conflict
    Planner-->>Renderer: Return conflict
    Renderer->>Error: Report both conflicting IRIs
  else Missing facts
    Planner-->>Renderer: Return planned append
    Renderer->>Inventory: Combine compacted append
  else Complete inventory
    Planner-->>Renderer: Return no-op
    Renderer-->>Inventory: Preserve bytes unchanged
  end
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the append-only change to current-only ReferenceCatalog inventory weaving.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lane/reference-catalog-append

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

djradon added a commit that referenced this pull request Aug 2, 2026
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/core/weave/knop_inventory_renderers.ts (1)

347-364: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Hardcoded IRI-to-prefix replacement list is brittle to future additions.

This chain manually enumerates every SFLO predicate and class IRI that must be compacted. If a new predicate or class is added to requestedSettledFactsTurtle in the future but the corresponding .replaceAll() entry is forgotten, the appended Turtle silently keeps the full uncompacted IRI instead of failing a test or a compile check. Extract a small generic compaction helper driven by a name-to-IRI map, so adding a new term to the Turtle template does not require a matching manual .replaceAll() entry to remember.

♻️ Proposed generic compaction helper
+const REFERENCE_CATALOG_COMPACTION_TERMS: ReadonlyArray<[string, string]> = [
+  [`${RDF_NAMESPACE}type`, "a"],
+  [`${SFLO_NAMESPACE}ReferenceCatalog`, "sflo:ReferenceCatalog"],
+  [`${SFLO_NAMESPACE}DigitalArtifact`, "sflo:DigitalArtifact"],
+  [`${SFLO_NAMESPACE}RdfDocument`, "sflo:RdfDocument"],
+  [`${SFLO_NAMESPACE}hasWorkingLocatedFile`, "sflo:hasWorkingLocatedFile"],
+  [`${SFLO_NAMESPACE}hasResourcePage`, "sflo:hasResourcePage"],
+  [`${SFLO_NAMESPACE}ResourcePage`, "sflo:ResourcePage"],
+  [`${SFLO_NAMESPACE}LocatedFile`, "sflo:LocatedFile"],
+];
+
+function compactTurtleTerms(turtle: string): string {
+  return REFERENCE_CATALOG_COMPACTION_TERMS.reduce(
+    (text, [iri, compact]) => text.replaceAll(`<${iri}>`, compact),
+    turtle,
+  );
+}
-  let compactAppendTurtle = plan.appendTurtle
-    .replaceAll(`<${RDF_NAMESPACE}type>`, "a")
-    .replaceAll(
-      `<${SFLO_NAMESPACE}ReferenceCatalog>`,
-      "sflo:ReferenceCatalog",
-    )
-    .replaceAll(`<${SFLO_NAMESPACE}DigitalArtifact>`, "sflo:DigitalArtifact")
-    .replaceAll(`<${SFLO_NAMESPACE}RdfDocument>`, "sflo:RdfDocument")
-    .replaceAll(
-      `<${SFLO_NAMESPACE}hasWorkingLocatedFile>`,
-      "sflo:hasWorkingLocatedFile",
-    )
-    .replaceAll(
-      `<${SFLO_NAMESPACE}hasResourcePage>`,
-      "sflo:hasResourcePage",
-    )
-    .replaceAll(`<${SFLO_NAMESPACE}ResourcePage>`, "sflo:ResourcePage")
-    .replaceAll(`<${SFLO_NAMESPACE}LocatedFile>`, "sflo:LocatedFile");
+  let compactAppendTurtle = compactTurtleTerms(plan.appendTurtle);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/weave/knop_inventory_renderers.ts` around lines 347 - 364, Replace
the hardcoded replaceAll chain used to build compactAppendTurtle with a small
generic compaction helper driven by the existing SFLO name-to-IRI mapping,
applying each mapping entry to plan.appendTurtle and retaining the RDF type
conversion. Ensure future terms added to requestedSettledFactsTurtle are
compacted automatically without requiring a separate manual replacement.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/core/weave/knop_inventory_renderers.ts`:
- Around line 347-364: Replace the hardcoded replaceAll chain used to build
compactAppendTurtle with a small generic compaction helper driven by the
existing SFLO name-to-IRI mapping, applying each mapping entry to
plan.appendTurtle and retaining the RDF type conversion. Ensure future terms
added to requestedSettledFactsTurtle are compacted automatically without
requiring a separate manual replacement.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c11b5fd-3ede-4a41-98d3-1d5db6729e0f

📥 Commits

Reviewing files that changed from the base of the PR and between 76db215 and 3573bf9.

📒 Files selected for processing (2)
  • src/core/weave/knop_inventory_renderers.ts
  • src/core/weave/knop_inventory_renderers_test.ts

@djradon
djradon merged commit 036b225 into main Aug 2, 2026
7 checks passed
@djradon
djradon deleted the lane/reference-catalog-append branch August 2, 2026 03:15
djradon added a commit that referenced this pull request Aug 2, 2026
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