diff --git a/docs/roadmap/audit-remediation.md b/docs/roadmap/audit-remediation.md new file mode 100644 index 0000000..906ea1e --- /dev/null +++ b/docs/roadmap/audit-remediation.md @@ -0,0 +1,261 @@ +# Audit Remediation Roadmap + +Prepared 2026-11-25. Status: planned; implementation has not started. +Baseline: `f040f6906ca14cdfea4162ae31f9dfb18e7667e1`. + +This roadmap implements the accepted [audit discussion](audit/discussion.md). +The [catalog](audit/catalog.md) and original reports retain the detailed evidence +and reproductions. This document owns the target state, work sequence, and +implementation status; it does not introduce new runtime contracts. + +## Baseline And Target + +The baseline retains all audited production and test findings. Application and +tool sources have not changed since the correctness audit. Dependencies remain +those in [go.mod](../../go.mod): PromptKit v0.25.0, ConfigKit v1.4.0, +CommandKit v0.8.0, ckconfig v0.11.0, ckprompt v0.12.0, and ReleaseKit v0.10.0. +No dependency upgrade is selected by this roadmap. + +The target is a thin application with corrected HTTP input handling, effective +tests at application-owned boundaries, useful startup diagnostics from the +appropriate owner, and HTTP-specific reporting consolidated within its adapter. +ConfigKit, PromptKit, and CommandKit retain the responsibilities established by +[ADR 0006](../adr/0006-adopt-commandkit-native-operator-interfaces.md) and the +[architecture policy](../policy/architecture.md). + +HTTP stays in maintenance mode, suitable only for exposure to trusted hosts on +a trusted network. The rest of the application remains actively developed. +Maintenance work includes the accepted report relocation because it makes that +boundary clearer; it does not expand HTTP reporting or deployment capabilities. + +At completion of the local work: + +- Provider parameters reach PromptKit without numeric precision loss, and file + references retain their pathname identity. +- Restricted acquisition uses ordinary regular-file semantics, cooperatively + observes cancellation, and preserves the existing lexical and byte limits. +- Tests detect the demonstrated application regressions without pinning + incidental representations or error prose. +- HTTP terminal reporting and its focused tests live within the HTTP adapter; + CLI reporting continues to use native upstream results and presentation. +- Listener failures carry useful native explanations. Framework capture + diagnostics follow the supported upstream route or remain explicitly tracked + pending upstream support, as specified in stage 4. +- Current contracts and internal documentation reflect the delivered changes, + and deferred HTTP work remains visible in [future.md](future.md). + +## Scope And Disposition + +Numbers refer to the [audit catalog](audit/catalog.md). Status for every stage +below is **not started**. + +| Catalog entries | Disposition | Stage | +| --- | --- | --- | +| 1–3 | Correct cancellation/non-regular acquisition, numeric precision, and pathname identity. | 1 | +| 9 | Replace self-referential artifact-hash expectations alongside reader work. | 1 | +| 4, 7, 11–13 | Strengthen server lifetime/failure coverage, test cleanup, removed-flag rejection, and error assertions. | 2 | +| 10, 16 | Move HTTP report implementation and tests into the adapter; strengthen accounting assertions. | 3 | +| 8 | Improve listener explanations; verify native capture-diagnostic support and integrate or prepare an upstream request. | 4 | +| 15 | Consolidate the small CLI diagnostic bridge where it reduces maintenance effort. | 4 | +| 5, 6 | Retain existing transport and capacity controls; document limitations and defer additional controls. | 5 | +| 14 | Defer standalone handler decomposition; permit a small useful extraction beside corrective work. | 1, 5 | +| 17 | Permit the nil-aware mapping simplification beside request changes; leaving current correct behavior is acceptable. | 1, 5 | + +## Stage 1: Correct HTTP Input Handling + +Work primarily in +[artifact_reader.go](../../internal/adapter/http/artifact_reader.go), +[handler.go](../../internal/adapter/http/handler.go), and their existing tests. + +1. Enable the request decoder's `UseNumber` capability. Preserve strict unknown + field handling, typed numeric validation, and trailing-token rejection. + Replace the concrete-float64 test expectation with lossless behavior checks. + Use a representative HTTP-to-real-engine-to-loopback-provider case with a + large integer and nested values; do not decode expected and actual values + through float64. Consolidate the old mapping scenario only after retaining + its meaningful JSON-shape protection. +2. Remove request-path whitespace trimming while retaining lexical cleaning + and containment. Keep configured artifact-root normalization separate. + Verify padded and unpadded filenames with distinct contents and preserve + body and metadata identity checks. +3. Pass context through file acquisition. Reject unsupported non-regular input + before opening; align opened-file checks with ordinary upstream semantics. + Check cancellation during reading and before successful return. Preserve + the configured byte limit during acquisition, including oversize detection, + and retain causes through the existing artifact-error mapping. +4. Replace hash expectations derived from the production helper with independent + expected digests for fixed, differing contents. A suitable public upstream + comparison is an alternative when checking interoperability. + +Cover cancellation after acquisition starts and unsupported non-regular input +with deterministic, bounded, platform-appropriate tests and reliable cleanup. +Retain a representative real-engine or HTTP path. A small controlled read seam +may be used where needed; no general fault-injection framework is required. + +These changes do not add streaming input support, resolve symlinks for +containment, promise immediate interruption of synchronous filesystem calls, +or abandon blocked reads in background goroutines. Existing symlink behavior +remains unchanged. Ordinary CLI artifact loading remains upstream-owned. + +If request mapping is touched, calling the existing nil-aware model converter +unconditionally is permitted. Preserve omitted/null versus explicit-empty +objects and numeric presence. Do not turn this into a standalone cleanup task +or a broad handler rewrite. + +**Completion evidence:** focused regressions establish lossless provider values, +correct file identity, cooperative cancellation and non-regular handling, and +independently checked hashes while existing containment and size tests pass. + +## Stage 2: Protect Server Composition And Failure Boundaries + +Use the existing CLI server harness in +[lifecycle_test.go](../../internal/adapter/cli/lifecycle_test.go) and the relevant +HTTP/CLI test owners. + +- Consolidate the shared-capacity scenario at actual server composition. + Configure capacity one with no queue, hold the first provider call, and + verify rejection of a second request without a second provider dispatch. + Release the first request and check completion. The test must exercise the + server's engine lifetime rather than inject the lifetime it intends to prove. +- Register cancellation, release, and worker joining before launching work; + bound the second request and retain one owner of channel closure. Test bounds + are cleanup mechanisms, not production deadlines. Remove the lower-level + duplicate only after equivalent protection exists; retain distinct privacy + and retry checks. +- Cover a resolved configuration that fails engine construction on a missing + message file or malformed template. Assert the typed cause, nonzero outcome, + and absence of a listen attempt. Do not require new diagnostic wording or + move message capture into configuration inspection. +- Give removed-flag tests otherwise-valid invocations. Distinguish rejection + of the removed flag using native typed evidence where available or a minimal + flag-specific fragment. Keep hard-cutover protection. +- Replace exact noncontractual HTTP error sentences with status/code/precedence, + usable nonempty-message, and private-cause exclusion assertions. Retain exact + wording only where expressly contractual. + +**Completion evidence:** tests protect server-owned shared admission and startup +ordering, fail for the intended invalid flag, and tolerate harmless error +rewording. Concurrency-test failure paths release and join their owned work. + +## Stage 3: Consolidate HTTP Terminal Reporting + +Move [internal/report](../../internal/report/report.go) and its focused tests +into dedicated files in `internal/adapter/http`. Make implementation names +private where practical, update handler/DTO references, and remove the obsolete +package. Package reduction is a consequence; the purpose is to place HTTP-only +functionality behind the maintenance-mode adapter boundary. + +Carry the accounting-test correction with the move: use distinct cached-token +and cache-write-token values and meaningful known/complete combinations. Assert +the required JSON member names and values instead of only counting members. + +Preserve existing wire shapes, opt-in and absence semantics, success/error +attachment, terminal-only observation, detached snapshots, unknown/incomplete +counts, request isolation, and response-limit handling. Retain representative +real-engine observation coverage. This work does not add accounting fields, +change CLI reports, or create a shared reporting framework. + +**Completion evidence:** existing HTTP report behavior and strengthened projection +tests pass from the new location; production imports no longer reference the +removed package. Update the component inventory and adapter documentation with +the move. This stage is required, not deferred HTTP work. + +## Stage 4: Improve Startup Diagnostics And CLI Maintenance + +In [server.go](../../internal/adapter/cli/server.go), add a deliberate native +CommandKit explanation identifying the selected listen address and a useful +failure category from typed error information where available. Preserve the +cause and existing status. Cover representative operator-correctable failures +without making the entire error sentence contractual. + +Consolidate the genuinely shared run/serve ConfigKit evidence selection and +adaptation into a small private CLI helper where useful. Preserve successful +result versus wrapped load-error evidence selection, distinct headings and +explanations, bootstrap reporting, and timeout/configuration precedence. +Flatten nested failure selection when clearer. Retain short duplication if +sharing would require extra options or abstractions. Native inspection already +owns its presentation and must not receive duplicate application diagnostics. + +Handle PromptKit capture diagnostics as a separate workstream: + +1. Verify the selected public PromptKit and ckprompt APIs against missing-file + and malformed-template cases. Determine whether they supply safe structured + resource identity/configuration location and a useful explanation. +2. Where supported, use the native integration for application and native + PromptKit commands. Preserve typed causes, statuses, and capture lifecycle. +3. If support is missing, prepare an upstream feature request covering both + diagnostic evidence and native presentation, and record the dependency and + deferred adoption explicitly. Do not invent an API or select an unreleased + dependency in this roadmap. A later supported release can enable adoption. + +Do not parse formatted errors, print arbitrary causes, import upstream internals, +or construct an application-owned framework-error interpreter. These capture +errors are not repaired merely by sharing the ConfigKit diagnostic helper. + +**Completion evidence:** local listener explanations and existing diagnostic +precedence/privacy tests pass. The capture workstream has either verified native +delivery with representative coverage or a concrete upstream request and tracked +deferral. In the latter case, report capture presentation as deferred, not fixed. +That dependency does not block stages 1–3 or local listener improvements. + +## Stage 5: Align Documentation And Preserve Deferred Work + +Update canonical documents with delivered behavior rather than duplicating their +contracts here: + +- [Operations](../operations.md) and, where applicable, the + [architecture policy](../policy/architecture.md): make the selected trusted-host, + trusted-network maintenance scope clear. Do not imply that a gateway makes + broader exposure supported by this remediation or require one for current use. +- [HTTP API](../api.md) and [source internals](../internal/sources.md): describe + corrected input behavior and regular-file acquisition without stronger + cancellation or filesystem guarantees. +- [Component overview](../internal/overview.md) and + [adapter internals](../internal/adapters.md): reflect report ownership and + delivered diagnostic handling. Preserve upstream ownership and CLI reporting. +- Operations: briefly clarify that existing transport deadlines and per-file, + request, response, and backend controls are not aggregate-memory or + whole-HTTP-request lifetime guarantees. Retain the operation-budget and + shutdown contracts. No new resource controls are part of this work. + +Maintain the already-started **Deferred HTTP Adapter Work** entry in +[future.md](future.md). It must retain every HTTP deferral from this review: +additional body-read/idle/response-delivery deadlines; aggregate input/memory +controls; standalone handler decomposition; and optional model-mapping cleanup +if left unchanged. Revisit controls only when workloads or operating needs +justify them; no benchmark project or memory-control feature request is required. + +Keep possible public upstream artifact-reader reuse there as separate follow-up. +Investigate whether it can remove ordinary reading/metadata duplication while +preserving access policy and byte enforcement during acquisition. Neither this +investigation nor an upstream release delays the local reader correction. +Report-package relocation must not appear as deferred. Preserve other existing +future directions, including broader HTTP review and additional accounting. + +**Completion evidence:** current documentation matches the implemented scope; +every deferred HTTP item has a durable disposition in future.md. Record any +pending framework-diagnostic dependency separately so it is not mistaken for +HTTP-only work or an implemented fix. + +## Validation And Completion + +Follow the [development baseline](../development.md#baseline-validation) and +[testing policy](../policy/testing.md) for implementation changes: ordinary and +race-enabled tests, vet, build, formatting, whitespace, and affected documentation +and example checks. Use real internal collaborators and controlled local providers; +the default suite remains offline and independent of live credentials. + +Focused tests should extend or replace the existing behavior owners. Preserve +meaningful protection before removing duplicate scenarios. Do not add coverage +quotas, exhaustive upstream matrices, mandatory mutation-testing infrastructure, +or new release gates. The audit's experiments guide regression selection; they +do not require a new ongoing test platform. + +Track each stage's actual completion and any upstream-dependent deferral. Local +remediation is complete when stages 1–5 have their stated evidence, including +documentation and future-work tracking. Do not mark upstream capture presentation +delivered if only its feature request is complete. + +All seven scope decisions are settled. Remaining API investigation and conditional +deferral follow the accepted ownership decision; they do not reopen application +policy. No additional significant open decision is identified at this baseline.