Document failed-load inspection behavior

This commit is contained in:
2026-12-05 16:15:33 +00:00
parent cb31324243
commit 729724deba
11 changed files with 96 additions and 22 deletions

View File

@@ -50,6 +50,8 @@ Start with one file. Optional features use the same loading and inspection model
references and choose which configuration fields to hide in inspection output.
- [Inspect a load](docs/config.md#layered-metadata): examine sources, presence,
history, safe YAML output, or [changes between two loads](docs/config.md#effective-configuration-diffs).
- [Investigate a rejected load](docs/consumers/README.md#failed-load-reporting):
inspect available evidence while retaining its diagnostics and failure status.
- [Hand settings to libraries](docs/consumers/README.md#component-handoff): share
one result and let each consumer select its own settings and reporting scope.
@@ -72,7 +74,7 @@ examples](docs/config.md#strict-document-composition) for the details and
exceptions.
Loading finishes before the call returns. ConfigKit then stays inactive until you
call it again; inspection uses the saved result. See
call it again; inspection uses saved load evidence. See
[completion and resource lifetime](docs/config.md#completion-and-resource-lifetime).
The [architecture goals](docs/policy/architecture.md#success-criteria) and

View File

@@ -7,6 +7,8 @@ import (
)
// LoadError reports safe structured diagnostics for a failed configuration load.
// InspectSubtree provides a reporting view when a coherent snapshot is available;
// the error remains the load's outcome and no execution result is returned.
// It intentionally does not expose or unwrap parser and application errors.
type LoadError struct{ value *engine.LoadError }

View File

@@ -2,7 +2,7 @@ package configkit
import "go.maximumdirect.net/configkit/internal/engine"
// Difference describes one changed value or subtree between two successful loads.
// Difference describes one changed value or subtree between two inspection snapshots.
// Left is the earlier value and Right is the later value. Snapshots are copies;
// Present distinguishes absence from explicit null. Redacted reports hiding
// based on sensitivity from either load. Mappings compare by key; a changed

View File

@@ -256,6 +256,37 @@ placement available when loading failed, which may be incomplete; it does not
promise a record for every attempted source. Nil or zero-valued errors and empty
or unknown IDs return false.
`LoadError.InspectSubtree(path)` obtains the same reporting view as a successful
result when the failing invocation retained a coherent snapshot. The Boolean
reports snapshot availability and path validity, not whether that path is present
or whether loading succeeded. An absent scope is valid. The error and its
diagnostics remain authoritative; no typed execution result is returned. Queries
use retained evidence without reopening sources or rerunning callbacks. The view
and error share the same conservatively sanitized source catalog, and resource
contexts are available only where they were established.
`Inspection.Stage()` identifies the processing completed for the snapshot:
| Value | Represented state |
| --- | --- |
| `main` | Completed main tier before later tiers or selected overlay. |
| `composed` | Completed source and overlay composition, before inheritance. |
| `inherited` | Completed structural inheritance, before typed defaults and decoding. |
| `decoded` | Decoded typed values before CLI assignments. |
| `overridden` | Values after CLI assignments, before application resolution. |
| `resolved` | Values after recorded resolution, before successful final validation. |
| `validated` | A successful load's completed inspection. |
The first three represent source trees without invented defaults. Failed phases
do not contribute partial changes: a resolver failure exposes its entry candidate,
and a validator failure exposes the candidate presented to it, even when the
validator mutates it. A resolved view does not assert successful secret lookup,
final identity checking, or validation. Earlier failures can have diagnostics
and sources without a view. With absent input there is no raw source checkpoint,
although decoding defaults can produce a typed snapshot. Existing history limits
can prevent a view or select an earlier admissible checkpoint; the original error
and diagnostics remain unchanged. The zero view's stage is empty.
### Completion and resource lifetime
`Load` finishes its work before returning. Success means input assembly,
@@ -743,11 +774,11 @@ historical classification. Redaction empties `Text` while retaining presence
and null state. Returned copies are detached; evidence does not reopen inputs.
Consult [ADR 0013](adr/0013-shared-source-version-checks.md) for the accepted
decision and the [development guide](development.md#baseline-validation) for
the completed implementation and remediation records in Git history.
development validation guidance.
### Layered metadata
Use inspection to understand a completed load without reading the files again:
Use inspection to understand an available snapshot without reading the files again:
| Need | API to use |
| --- | --- |
@@ -1030,7 +1061,8 @@ its normal nil-result/`LoadError` behavior, which callers handle before invoking
`Diff`.
`Inspection.Diff` compares focused views at the same canonical location, even
when their application root Go types differ. It compares the complete frozen
when their application root Go types, checkpoints, or load outcomes differ. It
compares represented values rather than diagnostic status. It compares the complete frozen
snapshots with the same paired redaction and retains records at, below, or above
the focus. Because sequences and structural replacements can be atomic, an
ancestor record may reflect a change outside the selected value. Different

View File

@@ -28,6 +28,7 @@ Start with one file, then choose the tasks your application needs:
| Reuse settings or combine record lists | [Inheritance](#named-sibling-inheritance) and [identified sequences](#identified-prompt-sequences) |
| Handle credentials | [Typed-secret reference](../config.md#typed-secret-references), [configured startup](#configured-secrets-startup), and the [direct-directory example](../../examples/consumers/consumers_test.go) |
| Inspect sources, earlier values, or changes | [Inspect a completed load](#inspect-a-completed-load) and [diffs](#effective-configuration-diffs) |
| Investigate a rejected load | [Failed-load reporting](#failed-load-reporting) |
| Hand one result to library consumers | [Component handoff](#component-handoff) |
| Upgrade an existing consumer | [Migration guidance](#intentional-migration-changes) |
@@ -131,6 +132,19 @@ Add imports, a selected overlay, or explicitly set CLI values through options
only when needed. An overlay changes configuration; choosing an LLM, report, or
execution profile remains application logic.
### Failed-load reporting
Handle the load error before using configuration. When it is a `*LoadError`,
`InspectSubtree` can provide the same reporting view as a result, including a
checkpoint that identifies how much processing completed. Keep the diagnostics
and failure status even when a view is available. Some early failures have no
view; source and diagnostic evidence can still be available.
The [failed-load example](../../examples/consumers/failure_inspection.go)
uses one invocation, reports an imported rejected value and its original source,
and shares show/explain presentation across successful and failed loads. See
the [checkpoint contract](../config.md#results-and-failures) for availability.
## Explicit main-file discovery
Applications choose the search conventions and their precedence, then pass the

View File

@@ -59,6 +59,7 @@ Accepted decisions:
- [Keep the public facade root-owned](adr/0006-public-facade.md)
- [Compare frozen effective configuration snapshots](adr/0010-effective-configuration-diff.md)
- [Compare inspection views across application types](adr/0024-compare-inspection-views-across-application-types.md)
- [Inspect failed configuration loads](adr/0025-inspect-failed-configuration-loads.md)
- [Place inputs at literal application mapping paths](adr/0011-input-destinations.md)
- [Share dependency-ready ordering](adr/0015-shared-dependency-ready-ordering.md)
- [Separate import selection controls](adr/0016-independent-import-controls.md)
@@ -141,6 +142,7 @@ code changes. Use the component overview to find the corresponding implementatio
| Shared source-version modes and evidence | [Engine source-version tests](../internal/engine/source_version_test.go), [public facade tests](../facade_source_version_mode_test.go), and [consumer example tests](../examples/consumers/layered_test.go) | `go test ./internal/engine -run 'SourceVersion'`, `go test . -run 'SourceVersion'`, and `go test ./examples/consumers` |
| Schema, defaults, projection, cloning | [Implementation flow](internal/overview.md#implementation-flow), [schema](../internal/engine/schema_test.go), [decoding](../internal/engine/decode_test.go), [projection and typed cloning](../internal/engine/projection_test.go) | `go test ./internal/engine -run 'Schema\|Decode\|Projection\|Clone\|Inline\|CompareDocument'` |
| Current values and focused inspection | [Value tests](../facade_result_value_test.go), [view tests](../facade_inspection_view_test.go), [comparison tests](../facade_inspection_diff_test.go), and [history integration](../facade_inspection_history_test.go) | `go test . -run 'TestResultValue\|TestInspectionView'` and `go test ./internal/engine -run 'TestResultValue\|Diff\|History'` |
| Failed-load inspection and checkpoints | [Public failure views](../facade_failure_inspection_test.go), [evidence parity](../facade_failure_evidence_test.go), and [engine failure paths](../internal/engine/failure_inspection_test.go) | `go test . -run 'TestLoadErrorInspection\|TestFailureInspection'` and `go test ./internal/engine -run 'TestFailed\|TestFailureInspection\|TestSourceInspection\|TestLoadHistoryBudget'` |
| Lifecycle, resolution, validation, callback ownership | [Loading](../internal/engine/load_test.go), [resolution](../internal/engine/resolution_test.go), [validation](../internal/engine/validation_test.go), [ownership](../internal/engine/callback_ownership_test.go), [independence](../internal/engine/independence_test.go) | `go test ./internal/engine -run 'Load\|Resolution\|Validation\|Validator\|Hook\|Callback\|Parallel'` |
| Resolution sequence matching and inspection | [Correspondence](../internal/engine/resolution_correspondence_test.go), [auditing and history](../internal/engine/resolution_compare_test.go), [public integration](../facade_resolution_sequences_test.go) | `go test ./internal/engine -run 'Resolution\|History\|Explain\|Sensitivity'` and `go test . -run 'Resolution\|SequenceIdentity\|Diff'` |
| Paths, metadata, provenance | [Paths](../internal/engine/path_test.go), [metadata](../internal/engine/metadata_test.go), [provenance](../internal/engine/provenance_test.go) | `go test ./internal/engine -run 'Path\|Metadata\|Provenance\|Queries'` |

View File

@@ -49,6 +49,8 @@ Implemented component owners:
engine schema builder and existing field/path bindings. Root `Inspection`
wraps an engine view borrowing the frozen inspection and canonical scope;
it reuses history enumeration, document redaction, and whole-result diff.
Both results and load errors can select a view; the error retains only frozen
reporting evidence and established passive contexts.
- `internal/document` owns the parser-independent ordered tree and cloning.
`internal/yaml` is the sole upstream YAML adapter and parser/dumper boundary.
- Engine mechanism tests own source, composition, inheritance, decoding,
@@ -182,6 +184,16 @@ pre-secret admission boundary, [`prepareInspectionHistory`](../../internal/engin
freezes that builder and counts the retained document roots before secret lookup
and validation.
On eligible failure exits, the engine freezes the latest admissible source,
decoded, or resolver-entry history prefix. Source prefixes reuse the same source
and inheritance producers without a typed baseline; failure-only fallback tries
earlier candidates when the retained-node budget prevents a newer view. The
shared finalizer in [`load_result.go`](../../internal/engine/load_result.go)
classifies sensitivity and attaches source records, contexts, diagnostics, and
known resolved references for both outcomes. Failure views use the error's
conservatively sanitized source catalog. [ADR 0025](../adr/0025-inspect-failed-configuration-loads.md)
records the decision.
The frozen model is shared by `Metadata` and `Inspection`. Its shape-aware
selection in [`history_select.go`](../../internal/engine/history_select.go)
drives metadata history, explanation, and historical-path membership; the model

View File

@@ -188,8 +188,10 @@ network provider into the library.
Configuration loading is a synchronous, complete-on-return operation. A successful
load provides the final configuration and inspection metadata after the configured
processing and validation phases complete. A failed load reports diagnostics and
returns no usable partial result. The normal application pattern is one load near
processing and validation phases complete. A failed load returns a nil result and
diagnostics, and may retain an inspectable coherent checkpoint as reporting
evidence. Inspection does not turn failure into successful configuration. The
normal application pattern is one load near
startup; applications may explicitly initiate additional loads.
ConfigKit releases its library-owned loading handles before returning and remains
@@ -311,19 +313,20 @@ metadata, and effective inspection must agree, including application resolution
changes; see [ADR 0003](../adr/0003-preserve-presence-and-resolution-history.md).
Safe historical values and an explanation renderer are part of the implemented contract,
including superseded/deleted paths and effective source attribution. Inspection
must agree with the final typed snapshot and apply historical sensitivity rules.
must agree with the represented snapshot and apply historical sensitivity rules.
See [ADR 0005](../adr/0005-explicit-overrides-and-safe-explanation.md).
Detailed syntax and operation tables belong to the
[current configuration contract](../config.md).
The frozen inspection boundary supports comparing completed same-type results
and focused views across application root types without reopening sources or
and focused views across application root types and load outcomes without reopening sources or
rerunning the load lifecycle. The
[configuration contract](../config.md#effective-configuration-diffs) owns
comparison and disclosure behavior, the [component overview](../internal/overview.md)
owns implementation responsibility, and [ADR 0010](../adr/0010-effective-configuration-diff.md)
and [ADR 0024](../adr/0024-compare-inspection-views-across-application-types.md)
record the accepted decisions.
record the comparison decisions. [ADR 0025](../adr/0025-inspect-failed-configuration-loads.md)
extends inspection to available failure checkpoints.
## Collection Identity And Combination

View File

@@ -1,7 +1,7 @@
# Inspect configuration independently of validation outcome
Status: agreed target; public accessor and checkpoint approach settled; not
implemented.
Status: implemented and validated. The [configuration contract](../config.md)
owns current behavior.
Baseline: commit `4a7ae66`, following the typed-value and inspection-view work.
## Purpose and user intent

View File

@@ -1,6 +1,6 @@
# Implementation plan: inspect failed configuration loads
Status: implementation in progress.
Status: complete; all stages implemented and validated.
Baseline: `5e0f406`, with runtime behavior at `4a7ae66`.
## Scope and execution
@@ -314,6 +314,8 @@ consumer dependencies or copied downstream CLI infrastructure.
## Stage 10 — Update owning documents and complete validation
**Complete.**
Update declaration comments and docs/config.md for failure inspection,
checkpoint availability/stages, source evidence and comparison eligibility.
Replace the architecture policy's categorical failure/no-usable-result wording

View File

@@ -6,17 +6,20 @@ import (
"go.maximumdirect.net/configkit/internal/engine"
)
// Inspection is a reporting view of a completed load. Its scope filters
// enumeration; explicit queries and source records retain their native paths.
// Inspection is a reporting view of a frozen load checkpoint, whether the load
// succeeded or failed. Its scope filters enumeration; explicit queries and
// source records retain their native paths.
type Inspection struct{ view engine.InspectionView }
// InspectionStage identifies the completed processing represented by a view.
// It does not indicate the error location or whether a load succeeded.
type InspectionStage string
// Inspection checkpoints describe completed source assembly, typed processing,
// resolution, and validation. A resolved view does not imply successful secret
// lookup, identity checking, or validation.
// Inspection checkpoints describe completed processing: main-tier composition,
// all source composition, inheritance, decoding, overrides, resolution, and
// validation, respectively. The first three retain source trees before typed
// defaults. A resolved view does not imply successful secret lookup, identity
// checking, or validation.
const (
InspectionStageMain InspectionStage = "main"
InspectionStageComposed InspectionStage = "composed"
@@ -60,8 +63,9 @@ func (r *Result[T]) InspectSubtree(path Path) (Inspection, bool) {
return Inspection{view: view}, ok
}
// InspectSubtree selects a canonical reporting location from a failed load's
// available frozen snapshot. An absent location is valid. Nil or zero errors,
// InspectSubtree selects a canonical JSON Pointer reporting location from a
// failed load's available frozen snapshot. Equivalent key and index spellings
// select the same scope; an absent location is valid. Nil or zero errors,
// unavailable snapshots, and invalid paths cannot produce a view.
func (e *LoadError) InspectSubtree(path Path) (Inspection, bool) {
if e == nil || e.value == nil {
@@ -71,7 +75,7 @@ func (e *LoadError) InspectSubtree(path Path) (Inspection, bool) {
return Inspection{view: view}, ok
}
// Metadata returns the unfiltered metadata of the completed load.
// Metadata returns the unfiltered metadata of the represented checkpoint.
func (i Inspection) Metadata() Metadata { return Metadata{value: i.view.Inspection().Metadata()} }
// HistoricalPaths returns observed paths at or beneath the reporting scope.
@@ -92,7 +96,8 @@ func (i Inspection) WriteEffective(output io.Writer) error { return i.view.Write
// Diff compares frozen views at the same canonical scope, including differences
// at an ancestor when the existing comparison treats that ancestor atomically.
// Views may come from different root Go types. Unavailable or mismatched views
// return an error without records.
// return an error without records. Comparison is independent of checkpoint and
// load outcome and does not compare diagnostics.
func (i Inspection) Diff(other Inspection) ([]Difference, error) {
values, err := i.view.Diff(other.view)
if err != nil {