Skip to content

🐛 fix(export): add partIndex/partTotal completeness marker for multipart JSON exports (REL-02) - #176

Merged
konih merged 1 commit into
mainfrom
fix/rel-02-export-completeness-marker
Aug 3, 2026
Merged

konih merged 1 commit into
mainfrom
fix/rel-02-export-completeness-marker

Conversation

@konih

@konih konih commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Audit finding REL-02 (P2) — multipart inventory export was non-atomic with no completeness marker, so a torn/stale set could masquerade as complete.

Fix (Option B — cheapest correct slice): each part of a multipart JSON ExportEnvelope carries partIndex/partTotal + generation, baked up-front (all parts marshalled with partTotal=N before the persistence loop), so a torn set's surviving parts flag incompleteness. Single-part exports stay markerless/byte-identical (additive; no golden changes). Redaction re-marshal preserves the markers.

Scope (honest): the guarantee covers the JSON envelope / state-sink contract (object stores + git document+json). The default Git/GitLab YAML layout projection (ADR-0419) intentionally carries no envelope metadata, so payload-level torn-detection doesn't apply there — documented explicitly in ADR-0405 and pinned by TestResolveSnapshotExport_GitDefaultYAMLDropsCompletenessMarker. Two follow-ups logged (INBOX): extend markers into the YAML projection via a manifest sidecar (REL-02-FUP); and a pre-existing 🔴 git-multipart path-collision (parts overwrite each other).

TDD: 5 tests incl. a fake-client torn-multipart controller test + the YAML-boundary guard. Independent review across two rounds (first caught the ADR over-claim P1 → fixed → fresh APPROVE). Deferred by design: manifest-last/staged-commit write-ordering rework.

Disjoint from REL-05 (different files in internal/collect).

Copilot AI review requested due to automatic review settings August 3, 2026 13:21
@konih
konih merged commit d28c746 into main Aug 3, 2026
21 of 22 checks passed
@konih
konih deleted the fix/rel-02-export-completeness-marker branch August 3, 2026 13:21

Copilot AI 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.

Pull request overview

Implements audit finding REL-02 by embedding a multipart completeness marker into multipart JSON ExportEnvelope payloads (partIndex/partTotal + generation) while keeping single-part exports markerless/byte-identical, and adds tests + ADR scope clarification for the Git default YAML projection boundary.

Changes:

  • Bake partIndex/partTotal into multipart JSON envelope bytes during partitioning, preserving markerless single-part behavior.
  • Preserve envelope header metadata (including completeness markers) when re-marshalling during sink capability redaction.
  • Add controller/export/layout tests and ADR updates to pin the guarantee scope (JSON envelope payloads only; default Git YAML projection drops envelope headers).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/sink/layout_export_test.go Adds regression test asserting Git default YAML projection drops envelope header fields (incl. completeness marker).
internal/sink/export.go Preserves original envelope metadata when re-marshalling redacted item sets.
internal/export/partition.go Refactors partitioning to precompute groups and bake multipart markers into emitted envelope bytes.
internal/export/partition_test.go Adds tests for multipart marker baking, markerless single-part compatibility, and torn/stale detection signals.
internal/export/envelope.go Extends export Metadata with PartIndex/PartTotal and forwards them into envelope marshaling.
internal/export/envelope_meta.go Exposes PartIndex/PartTotal via parsed envelope metadata.
internal/controller/kollectinventory_export_completeness_test.go Adds controller-level torn multipart export detectability test.
internal/collect/export_envelope.go Extends contract types to include partIndex/partTotal (omitempty) and documents completeness contract semantics.
internal/collect/export_envelope_test.go Adds round-trip tests for part markers and markerless backward compatibility.
docs/adr/0405-export-data-contract.md Documents REL-02 completeness marker, its scope boundary, and consumer validation requirements.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +153 to +157
parts, err := export.PartitionEnvelopes(
store.SnapshotNamespace("default"),
export.Metadata{Generation: got.Generation},
limit,
)
Comment on lines 36 to 45
func PartitionEnvelopes(items []collect.Item, meta Metadata, maxBytes int64) ([]EnvelopePartition, error) {
sorted, err := stableItems(items)
if err != nil {
return nil, err
}

full, err := MarshalEnvelope(sorted, meta)
groups, err := partitionItemGroups(sorted, meta, maxBytes)
if err != nil {
return nil, err
}
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.54902% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/sink/export.go 0.00% 10 Missing ⚠️
internal/export/partition.go 88.57% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
76.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

2 participants