Files
configkit/docs/roadmap/remediation.md

17 KiB
Raw Blame History

Failed-load inspection review

Reviewed commit 729724debab789ffb0e91147a134283bb2e236fa against the implementation plan, the feature roadmap, and ADR 0025. The follow-up integration audit reviewed 36a54ec788e9c912f335652ecfe244a30e90e8a3, whose production code is unchanged, and adds Findings 2 and 3 below.

Finding 1 — Preserve the actual layered main checkpoint and its collection policy

Status: Complete. Retained the policy-aware main checkpoint, protected it from overlay mutation, and covered overlay/underlay/version failures and invalid main identities. Focused tests and ./scripts/check.sh passed.

Priority: P2. Affected stages: 3 and 6; regression coverage belongs with the stage 8 integration cases.

Relevant code

  • executeLoadRequest captures mainCandidate before the layered loader composes the main tier, and supplies that descriptor to failure handling after layered assembly fails.
  • assembleLayeredInput composes the main tier using the completed underlays' collection policies. Its local mainComposition is not retained in the returned input on a later error.
  • sourceFailure, particularly its call to compositionForInputWithPolicy, reconstructs the main candidate without the lower collection policy used by the actual load.

Circumstances and observed behavior

An underlay can declare an identity for a collection that the main tier's imports then use during strict composition. This is established collection-policy behavior; applications need not duplicate the declaration in the main document or register it in Go.

The following fixture reproduces the issue through the public API:

# Underlay supplied through LayeredOptions.Underlays
config:
  sequences:
    - destination: [items]
      key: id
items: [{id: lower, value: base}]

---
# main.yml (loaded with Input.Imports: true)
config:
  imports:
    - path: a.yml
    - path: b.yml

---
# a.yml
items: [{id: a, value: first}]

---
# b.yml
items: [{id: b, value: second}]

LoadLayered succeeds with these inputs and no selected overlay. With an explicit overlay filesystem and a nonexistent selected overlay, it correctly returns a load error. However, LoadError.InspectSubtree(Path{}) returns false, instead of exposing the completed main tier with its a and b records at InspectionStageMain. This occurs under the normal history limits.

The load already composed that main tier successfully using the underlay's identity rule. Failure handling instead recomposes the two imported lists with no identity rule, encounters an ordinary overlapping-list conflict, and discards the available checkpoint.

The same policy mismatch can manufacture a misleading checkpoint in the other direction. With the same underlay, a single main document containing items: [{id: a}, {id: a}] fails main composition with compose.conflict. A document containing items: [{other: a}] fails with compose.invalid. In both cases the fallback nevertheless returns a main view: reconstruction without the identity rule succeeds even though the main composition required by this invocation did not. The plan distinguishes completed main composition from failures before such a checkpoint exists.

Remediation and verification

Retain the actual completed main-tier document and its source/history/policy evidence when layered assembly produces it, preserving ownership across later tier and overlay operations. Pass that checkpoint to failure inspection rather than reconstructing it under different collection rules. Where lazy main materialization remains necessary, use the applicable policy context and report only the processing actually completed. Keep the original diagnostics and the existing checkpoint availability rules.

Add a focused layered-load regression covering an underlay-only YAML identity, strict main imports, and a later overlay failure. Verify the main values, stage, origins and history, without including underlay values as main-tier values. Also verify that main composition rejected by the applicable identity rule does not become a completed checkpoint merely by retrying without that rule. No new consumer registration requirement, callback retry, source reread, or history limit is needed.

Finding 2 — Record consumption of descendants inside an inheritance selector

Status: Complete. The control producer now records every consumed selector descendant. Public regression coverage verifies explanations, metadata history and historical paths after decode failure, validation failure and success. Focused inheritance tests and ./scripts/check.sh passed.

Priority: P2. Affected stages: 3 and 8, integrating the shared inheritance-history producer with failed-load inspection.

Relevant code

  • observeSourcePrefix reuses observeInheritanceEvidence for source-stage failure snapshots.
  • observeInheritanceControl records consumption only at the control's root path, then removes its complete subtree from the scratch document.
  • selectHistory selects exact and descendant observations for a query. Its producer contract requires facts for every affected path; it does not infer consumption of an unobserved descendant from an ancestor control observation.
  • Explain and appendInheritanceExplanation consequently omit the consumption event for that descendant.

Circumstances and observed behavior

Consider a typed configuration with Count int and Items []map[string]any, loaded from:

config:
  sequences: [{destination: [items], key: id}]
count: invalid
items:
  - {id: parent, width: 5}
  - {id: child, extends: {id: parent}, width: 20}

Inheritance completes and decoding rejects count, so the error exposes an inherited inspection. /items/1/extends/id remains a valid historical query. Its explanation correctly reports Effective.Present == false, but its history contains only the source contribution with After.Present == true and YAML parent. Its metadata history likewise contains no inheritance consumption. Querying /items/1/extends does include the removal event.

Expected behavior is that the nested query also includes the containing control's consumption, with the control path as its reported operation path, and an absent after-value. This follows the existing descendant-history and consumed-control behavior in the configuration contract; it requires no new inheritance or configuration semantics.

The same omission was reproduced with count: 0 both on successful loading and on semantic validation rejection. This is an existing shared-history defect, not a newly introduced composition regression. Reusing that producer makes the new failure views inherit it, and outcome-parity tests alone cannot detect it. Effective configuration values are correct; the missing operation makes their history incomplete and inconsistent between parent and descendant queries.

Remediation and verification

Have the inheritance producer register consumption for the concrete descendant shapes present in a mapping-valued control before removing it, reusing the existing operation payload, attribution and reported control path. Keep query selection and ordinary scalar-control behavior consistent; do not substitute a synthetic decoding event for the inheritance operation.

Add focused coverage through the shared inspection interface for a consumed selector field. Verify effective absence, the inheritance event and its before/after presence in explanation, metadata history, and retained historical paths. Exercise the source-stage failure case and a successful counterpart so both use the same corrected evidence.

Finding 3 — Clarify the diagnostic-only statement about load errors

Status: Open. Priority: P3. Affected stage: 10.

docs/config.md, around line 925, still states that metadata records, diagnostics and load errors contain no configuration values. The earlier results-and-failures section and the new LoadError.InspectSubtree explicitly permit error inspection to expose non-secret configuration values and historical snapshots. The unconditional statement leaves the owning contract inconsistent about the boundary between diagnostic reporting and explicit configuration inspection.

Qualify the existing statement to cover diagnostic records and ordinary LoadError.Error() reporting. State that explicitly requested inspection snapshots can expose non-secret values under the existing redaction rules, regardless of load outcome. Preserve the implemented error accessor and inspection behavior; this calls for documentation clarification, not another restriction on inspecting rejected configuration.

Finding 4 — Avoid repeated scans of source observations during history construction

Status: Open. Priority: P2. Affected stages: 3, 4 and 6 through their shared source-history construction.

Relevant code and complexity

observeSourcePrefix calls observeSourceEvidence. That producer first records every source application's contributions, then processes overlay records. For each displaced definition it calls sourceOriginRepresentedByOperation in the same file (around line 194). The helper scans every observation at the path, filtering out contributions, definitions and operations that cannot represent the requested origin.

Let K source applications contribute the same scalar path and let R overlay records displace that path. Every helper call must scan past the initial K contribution observations before reaching any eligible operation. The displaced definition loop alone therefore requires at least K * R observation visits. With K ordered underlay tiers repeatedly replacing setting, R = K - 1, giving quadratic work even though this path's retained contributions and replacement evidence have linear size. Later operation observations also accumulate and are rescanned. Final-tree summary construction performs further calls to the same helper.

This is an existing shared-helper inefficiency, now also used to construct earlier failure views. It can increase the cost of reporting a decode or resolver failure after many tier replacements. The selected design explicitly reuses the producer; it does not prescribe this internal lookup algorithm. The finding does not challenge chronological history, ownership copies, checkpoint fallback, or the expressly selected whole-snapshot diff.

Refactoring opportunity

Maintain an incremental index of eligible after-operation evidence by concrete path and attribution rather than searching the general observation list for each query. Narrow candidates using layer, operation and source/location identity, retaining originRepresentedByChange semantics for composite origins and ancestor replacements. Singleton-origin scalar replacements can then use expected constant-time indexed lookups, making the repeated-scalar fixture linear in its history size. A separate list containing only operations would remove irrelevant contribution scans but would still leave repeated scans of earlier operations; address both costs.

Preserve semantic key/index shapes, subset attribution, deduplication and chronological output. Composite-origin matching may require additional work proportional to attribution size; no general public performance guarantee is proposed. Existing source/history cases should verify behavior after refactoring, with a focused repeated-tier fixture covering the affected deduplication. No timing thresholds or benchmarks are required to establish this static finding.

Review coverage and validation

The review followed all ten implementation stages in order:

Stages Reviewed outcome
1 Accepted decision separates failure status from inspection and extends existing view comparison.
2 Shared finalization classifies snapshots and attaches conservative source catalogs, passive contexts and known references.
3 Source prefixes reuse source/inheritance evidence without inventing typed defaults. Findings 1 and 2 affect main selection and inherited control history.
4 CLI and resolver failures retain their frozen entry candidates without failed partial edits.
5 Late failures retain resolved evidence, including pre-validator values and known secret references.
6 Ownership and budget fallback are implemented; Finding 1 affects preservation of the actual layered main checkpoint.
7 Root-owned API and stage conversions reuse the existing inspection view, including nil/zero and absent scopes.
8 Evidence, redaction, comparison and detachment tests protect many parity cases. Integration probes expose the shared-history omission in Finding 2; the policy-dependent fallback in Finding 1 is also missing.
9 Maintained consumer example reports failed loads from one invocation and preserves the error.
10 Public/configuration/architecture/internal documentation describes checkpoint inspection and retains existing lifecycle boundaries. Finding 3 identifies an unrevised diagnostic-boundary statement.

./scripts/check.sh and go test -race ./... passed using Go 1.27.4 with dependency downloads disabled, including during the follow-up integration audit. An uncached focused run also passed for failure inspection, history, source versions, destinations, resource contexts, resolution and the consumer reporting example.

Disposable public-API probes outside the repository confirmed Finding 1 and the missing selector-consumption history in Finding 2. Additional probes checked source-stage replay for strict imports, lower-tier upsert, mapping and identified sequence inheritance, mounted mapping inputs, and imported sequence-item inputs. Those cases agreed on effective and historical values apart from Finding 2. The stage-by-stage follow-up also traced error-source sanitization, frozen resolver-entry metadata, late secret/validation failures, scoped comparison, passive contexts, nil/zero facade behavior and the one-invocation example. No production code or permanent tests were changed during either review. No further actionable integration gaps were identified.

Algorithmic follow-up audit

Reviewed a675d3ab50b9c6c2659e22bb4b8210a6004c5dc4, with the same production baseline as the prior audits. Finding 4 is additional; Findings 1–3 remain open. The analysis followed the implementation stages in order:

Stage Algorithmic review
1 ADR 0025 establishes checkpoint semantics, without an additional executable algorithm to assess.
2 Shared finalization retains classification and source handling; extracting it adds no input-sized nested loop. Existing selected sensitivity/comparison mechanisms were preserved.
3 Source-tree traversal and origin copying scale with visited paths and attribution payloads. Finding 4 identifies avoidable repeated history scans in the shared producer.
4 Prefix construction reuses that producer, so Finding 4 also applies here. CLI application lists and source-ID deduplication otherwise use sequential walks and maps.
5 Late failures reuse the already-frozen resolved history rather than rebuilding it. No additional suboptimal algorithm was identified.
6 The number of checkpoint candidates is fixed by the lifecycle. Retrying a fixed number of prefixes does not itself make traversal quadratic in configuration size. Retained-node counting and document lookup construction memoize node identity. Ownership cloning remains as selected in the plan.
7 Stage conversion is constant-time and scope normalization scales with path length. Whole-snapshot comparison followed by scope filtering is expressly selected and was not reconsidered.
8 Reviewed the exercised construction/query paths without introducing performance assertions or changing selected comparison and redaction algorithms.
9 The maintained example acquires views from the same retained inspection and does not reload inputs.
10 Documentation and validation add no production algorithm; prior correctness/documentation findings were preserved rather than duplicated.

Finding 4 follows directly from loop ordering and lookup contents; no empirical performance data was collected. Production code and tests remain unchanged. The prior successful checks apply to the unchanged runtime; this pass validates the report's links and whitespace. No further algorithmic findings were identified within the reviewed feature scope.