From 729724debab789ffb0e91147a134283bb2e236fa Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sat, 5 Dec 2026 16:15:33 +0000 Subject: [PATCH] Document failed-load inspection behavior --- README.md | 4 ++- diagnostic.go | 2 ++ diff.go | 2 +- docs/config.md | 38 ++++++++++++++++++++++++-- docs/consumers/README.md | 14 ++++++++++ docs/development.md | 2 ++ docs/internal/overview.md | 12 ++++++++ docs/policy/architecture.md | 13 +++++---- docs/roadmap/failed-load-inspection.md | 4 +-- docs/roadmap/implementation.md | 4 ++- inspection_view.go | 23 ++++++++++------ 11 files changed, 96 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 5f1ead7..23ed6dd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/diagnostic.go b/diagnostic.go index 7b895cd..20d95bc 100644 --- a/diagnostic.go +++ b/diagnostic.go @@ -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 } diff --git a/diff.go b/diff.go index 70ece25..30ffb02 100644 --- a/diff.go +++ b/diff.go @@ -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 diff --git a/docs/config.md b/docs/config.md index 924759f..f0bf193 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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 diff --git a/docs/consumers/README.md b/docs/consumers/README.md index 5c65c3d..de9abc5 100644 --- a/docs/consumers/README.md +++ b/docs/consumers/README.md @@ -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 diff --git a/docs/development.md b/docs/development.md index fb62924..2319197 100644 --- a/docs/development.md +++ b/docs/development.md @@ -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'` | diff --git a/docs/internal/overview.md b/docs/internal/overview.md index 8318548..ef88660 100644 --- a/docs/internal/overview.md +++ b/docs/internal/overview.md @@ -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 diff --git a/docs/policy/architecture.md b/docs/policy/architecture.md index ea77847..09bd11b 100644 --- a/docs/policy/architecture.md +++ b/docs/policy/architecture.md @@ -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 diff --git a/docs/roadmap/failed-load-inspection.md b/docs/roadmap/failed-load-inspection.md index 253f449..fde67ed 100644 --- a/docs/roadmap/failed-load-inspection.md +++ b/docs/roadmap/failed-load-inspection.md @@ -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 diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 8fff7ab..d931424 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -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 diff --git a/inspection_view.go b/inspection_view.go index 139b646..f9896cd 100644 --- a/inspection_view.go +++ b/inspection_view.go @@ -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 {