p1-6: doc-only TODO markers (section_label, doc_version invariant)

M9: add a `TODO(P2/P3)` comment near the NULL persistence at
documents.rs (put_chunks). The `section_label` column exists in the §5.5
DDL but neither the in-memory Chunk struct nor the §2.6 wire schema
carries the field, so NULL is the correct canonical value today —
flag the future-bump intent in-line rather than leaving it implicit.

M10: add a one-line invariant comment near the i64 -> u32 narrowing for
`doc_version` in `get_document`. The invariant is documented at the
write site (UPSERT bumps by 1 per re-ingest) — restate it at the read
site so the cast is not silently load-bearing.

No behaviour change. No tests touched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-30 17:34:17 +00:00
parent 15b4d80efc
commit b7367dedfe

View File

@@ -124,6 +124,9 @@ impl kb_core::DocumentStore for SqliteStore {
// §5.5 has a `section_label` column but the in-memory Chunk
// struct does not carry it (nor does the wire schema §2.6).
// Persist NULL until a future bump introduces the field.
// TODO(P2/P3): populate `section_label` once Chunk and the
// wire schema gain the field; until then NULL is the correct
// canonical value.
stmt.execute(params![
chunk.chunk_id.0,
chunk.doc_id.0,
@@ -203,6 +206,12 @@ impl kb_core::DocumentStore for SqliteStore {
metadata,
provenance,
parser_version: kb_core::ParserVersion(row.parser_version),
// INVARIANT: `doc_version` is bumped by 1 on every re-ingest
// (see `upsert_document`). The column is INTEGER (i64) but
// CanonicalDocument carries u32; an overflow would require
// 2^32 re-ingests of the same document, which is well beyond
// any realistic ingest frequency. Truncating cast is safe
// under that invariant.
schema_version: row.schema_version as u32,
doc_version: row.doc_version as u32,
}))