Repository navigation
🐛 fix(export): add partIndex/partTotal completeness marker for multipart JSON exports (REL-02) - #176
Merged
Merged
Conversation
…ltipart exports are detectable (REL-02)
There was a problem hiding this comment.
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/partTotalinto 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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
ExportEnvelopecarriespartIndex/partTotal+generation, baked up-front (all parts marshalled withpartTotal=Nbefore 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).