9.9 KiB
Inspect configuration independently of validation outcome
Status: implemented and validated. The configuration contract
owns current behavior.
Baseline: commit 4a7ae66, following the typed-value and inspection-view work.
Purpose and user intent
Operators need to inspect invalid configurations at least as easily as valid ones. A failed load must report its error; failure is not a reason to withhold configuration evidence that ConfigKit has already produced.
Narratio's motivating workflow is config validate, followed by config show
or config explain for the same selected inputs. For example, an unsupported
storage.backend value should be inspectable together with the import, overlay,
or override that contributed it. The application's CommandKit/ckconfig adapter
should use ConfigKit's native reporting interface rather than reload the input
with validation disabled or reconstruct provenance itself.
Success or failure describes the outcome of processing and validation. Inspection describes the available configuration evidence. These are separate facts; access to a report does not imply that configuration passed validation.
Current baseline
LoadError exposes diagnostics and sanitized source records. Both loading entry points currently return a nil Result on error. A successful Result provides current typed values and a separately frozen Inspection view with effective rendering, history, explanations, metadata, source contexts, and comparison.
Internally, history and the resolved document are retained before secret lookup and final validation. However, sensitivity, source records, resource contexts, and secret-reference reporting are finalized on the success path in load_result.go. Error construction drops that inspection state. Simply attaching the unfinished state to LoadError would not provide existing redaction and reporting behavior.
The final validator is expected to be read-only. Its existing mutation audit can reject value, sensitivity, or resolved-secret changes. A retained snapshot from before that callback remains useful even if the callback violates its contract.
Target end state
One inspection experience
An invalid resolved configuration supports the same reporting operations and public Inspection type as a valid one:
- Whole-configuration and selected-subtree effective output with existing redaction.
- Native-path explanations, rendered explanations, effective presence/origins, chronological history, and historical-path enumeration.
- Original source IDs, source catalogs, locations, and passive resource contexts.
- Existing structural comparison and paired redaction at matching scopes, including comparisons between accepted and rejected configuration snapshots.
Preserve canonical reporting scopes, explicit query path intent, absent/null behavior, ancestor evidence, sequence-atomic differences, and ordinary writer failure behavior. Scoping remains a reporting focus. The error's sources and the view's sources should refer consistently to the same load and evidence, using the existing sanitization rules.
Add an optional inspection accessor on LoadError, mirroring Result's scope selection:
func (e *LoadError) InspectSubtree(path Path) (Inspection, bool)
The root Path requests whole-configuration inspection; other scopes follow the existing rules. Reporting adapters can accept Result and LoadError through the same inspection-acquisition interface. The Boolean concerns snapshot availability and path validity, not validation success or presence of the selected scope. A valid absent scope behaves as it does today.
Ordinary semantic rejection must not leave consumers with a reduced reporting interface. Callers handle the non-nil error and retrieve inspection through their normal reporting adapter. Preserve existing load signatures and nil Result returns on error as a compatibility choice, not a rule that rejected configurations must be inaccessible.
This addition concerns reporting data. It does not require typed execution access through an error, and does not establish a general prohibition on such access.
Evidence from the failing invocation
A view is backed by retained evidence from that invocation. Reading it does not reload sources, rerun callbacks, repeat secret lookup, or consult changed inputs. The evidence is frozen independently of caller-owned objects and subsequent loads. Existing detached-record and passive resource-context ownership applies; resource contents themselves are still read only when the application requests access, under the existing resource contract.
When source assembly, typed decoding, overrides, and recorded resolution have produced the resolved snapshot, preserve it on later reported failure. This includes semantic validation errors, final registered-identity failures, and secret lookup failures when the retained snapshot is available. Secret references can still be reported by name without retaining credential contents. Validation success is not an admission condition for inspection.
Use the candidate presented to the final validator as the inspection snapshot for errors reported during that callback, including mutation errors. Identify it as the pre-validation candidate; do not silently replace it with unrecorded callback mutations or invent origins for those mutations. The existing mutation diagnostic remains available alongside the snapshot. A callback failure must not automatically erase previously retained evidence.
When processing stops earlier, keep diagnostics and available source evidence, and expose the latest coherent checkpoint already produced by the pipeline whose values, history, and sensitivity can be reported faithfully. Identify its processing stage and limitations using lightweight snapshot-stage information alongside the acquired Inspection. This can include an earlier decoded candidate when a later CLI assignment fails, or a resolver's entry candidate when resolution fails. Availability follows the actual processing completed in that invocation.
The implementation plan specifies the checkpoint inventory, public stage representation, failure-exit selection and execution order. Earlier acquisition and parsing failures may have diagnostics/source evidence alone. This approach reuses existing checkpoints; it does not require snapshots after every phase or a new partial-decoding or recovery framework. Do not label an earlier or incomplete snapshot as fully resolved, or fabricate omitted values and history. Absence of an inspection view means there is no supported configuration snapshot for that failure, not that an invalid configuration is categorically uninspectable.
Snapshot stage identifies completed processing, not a second success flag or a new validation policy. Where a view is available, the same reporting semantics apply to the evidence it actually contains. A failed load remains an error; inspection does not turn it into a successful load or continue startup for the application.
Existing safety and lifecycle behavior
Reuse current sensitivity classification and historical/paired redaction for both successful and failed loads. Credential contents remain outside inspection, and application-authored messages retain their existing responsibility boundary. No additional confidentiality or isolation guarantee is introduced.
Keep the existing processing order, callback contracts, error classifications, composition rules, and resource cleanup. Error inspection does not require a second validation pass or a special load mode. A snapshot unavailable because of an existing history/resource limit does not authorize bypassing that limit. Snapshot retention should reuse already produced evidence where possible rather than duplicate complete trees or introduce a global cache.
Changes needed from the baseline
The engine needs a shared inspection-finalization boundary used by success and eligible error returns. It must complete classification and source/context reporting before exposing a view, preserve the candidate represented by its history, and carry that evidence through engine and root LoadError wrappers. The ordinary result-publication path should reuse that owner.
The public facade needs error inspection acquisition, scope selection, and a clear account of snapshot availability/stage. Existing consumers of LoadError and Result should continue to work. Downstream adapters can then share reporting logic across outcomes; Narratio and ckconfig integration changes remain owned by those projects rather than implemented inside ConfigKit.
Current architecture and configuration documentation must distinguish error status from inspectability. Revise wording about failure and inspection where it currently assumes only successful loads have reports, including comparison eligibility. Record the architectural decision in an ADR, with references to the existing lifecycle and inspection decisions. Keep implemented-behavior claims unchanged until implementation lands; this pass creates no ADR or policy changes.
Behavioral coverage should establish same-invocation values and provenance after semantic rejection, defaults/layers/CLI/resolution agreement, earlier-failure availability, validator-mutation snapshot identity, and sensitive current and historical output. Include typed secrets, final identity failure, accepted versus rejected snapshot comparison, scoped reports, and independent loads. A maintained consumer example should demonstrate rendering and explanation after an error without a second load. Reuse existing mechanisms and tests where they already protect unchanged behavior; avoid private-call-count or performance thresholds.
Completion means a consumer can investigate rejected resolved settings through the ordinary inspection interface, see the stage and limits of any earlier snapshot, and continue to receive the original failure diagnostics. The implementation plan owns sequencing and verification.