diff --git a/docs/roadmap/audit/01-correctness.md b/docs/roadmap/audit/01-correctness.md new file mode 100644 index 0000000..999e00b --- /dev/null +++ b/docs/roadmap/audit/01-correctness.md @@ -0,0 +1,157 @@ +# Functional Correctness Audit + +Reviewed on 2026-11-24 at source revision +`90f80ef2b7e93fcd83b22b880fb450e969949941`. + +## Scope And Results + +Reviewed local production functions and their interactions across the process +entrypoint, native CLI composition, configuration discovery/resolution handoff, +request mapping, result/report delivery, HTTP decoding and responses, artifact +reading, terminal observations, and server cancellation. Checked behavior +against the configuration, CLI, HTTP, operations, and architectural contracts. +Also checked the small ReleaseKit launcher/profile and adopted workflow wiring. +This is an application audit, not an exhaustive audit of upstream libraries. + +Three reproducible findings warrant remediation consideration. Ordinary +configuration, execution, report delivery, error mapping, and shared-server +tests passed; passing tests do not cover the boundary cases below. + +## 1. HTTP Provider Parameters Lose Large Integer Precision (P2) + +**Relevant code:** `Handler.ServeHTTP` in +[handler.go](../../../internal/adapter/http/handler.go), lines 58–60, and +`modelOverrideRequestDTO.ExtraParams` in +[dto.go](../../../internal/adapter/http/dto.go), line 38. + +**Circumstances:** An HTTP request supplies a provider-specific integer that +is not exactly representable as a `float64` inside `model.extra_params`. +Nested maps and arrays have the same issue. The +[HTTP contract](../../api.md) accepts these provider parameters using +PromptKit's JSON-compatible value semantics. + +For example, a request to a configured prompt includes: + +```json +{"prompt_id":"selected","model":{"extra_params":{"seed":9007199254740993}}} +``` + +**Expected:** The provider receives the supplied integer unchanged, provided +it is supported by the selected provider. PromptKit accepts this value through +its public API as either `int64` or `json.Number` and preserves it on the wire. + +**Actual:** The request decoder does not use `UseNumber`, so decoding into +`map[string]any` first converts the number to `float64`. The handler returns +HTTP 200, but the local OpenAI-compatible provider receives +`9007199254740992`. This silently changes a provider setting such as a seed; +the later request mapping cannot recover the original value. + +**Evidence:** A temporary diagnostic used the real HTTP handler, ConfigKit +load, PromptKit engine, and a loopback provider. The HTTP path produced the +rounded value. Direct calls to the same engine with `int64(9007199254740993)` +and `json.Number("9007199254740993")` both sent the exact original integer. +Existing `TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams` exercises +only small exactly representable numbers, so it passes despite this defect. + +**Potential remediation:** Enable `UseNumber` on the existing request decoder +before decoding the DTO. The selected PromptKit version accepts `json.Number`, +so the HTTP adapter can preserve the number without a new numeric-conversion +layer. Alternatively, retain raw JSON for provider parameters and decode it +losslessly before handoff. Preserve strict unknown-field handling, typed +numeric-field validation, and trailing-token rejection. Regression coverage +should include large integers in nested provider values and the outgoing +provider request, not just the intermediate Go map's concrete types. + +## 2. File-Reference Whitespace Can Select A Different Artifact (P3) + +**Relevant code:** `restrictedArtifactReader.resolveLexicalPath` in +[artifact_reader.go](../../../internal/adapter/http/artifact_reader.go), +line 101. + +**Circumstances:** An HTTP file reference names a valid file whose pathname +begins or ends with whitespace. The reader applies `strings.TrimSpace` to +the request URI before lexical path resolution. Filename whitespace is +significant; cleaning path components does not require removing it. + +**Expected:** Resolve the requested pathname beneath the artifact root while +preserving its identity, or report a read failure if that file does not exist. +The [HTTP file-reference contract](../../api.md) specifies lexical containment, +not a whitespace-stripping filename convention. Configuration's documented +artifact-root normalization is a separate operation. + +**Actual:** With both ` padded.txt` and `padded.txt` beneath the configured +root, requesting ` padded.txt` reads `padded.txt` successfully. The resulting +body, URI, size, and hash describe the wrong input. If only the whitespace- +named file exists, the otherwise valid reference fails instead. + +**Evidence:** A temporary diagnostic created the two files with distinct +contents and invoked the real restricted reader. The requested +`" padded.txt"` contained `selected-content`, but the returned body was +`different-content` from `padded.txt`. PromptKit's ordinary file reader uses +the supplied URI without this trimming. + +**Potential remediation:** Preserve `rawPath` when applying `filepath.Clean` +and the existing lexical containment checks. Keep configured-root +normalization and the existing empty-URI handling separate. Verify file +identity with distinct whitespace/non-whitespace names; this needs no new +symlink-resolution or filesystem-sandbox policy. + +## 3. Restricted File Reads Discard Cancellation And Can Stall On FIFOs (P2) + +**Relevant code:** `restrictedArtifactReader.Read`, `readFileArtifact`, and +`readArtifactFile` in +[artifact_reader.go](../../../internal/adapter/http/artifact_reader.go), +lines 52–64, 84–96, and 123–148. + +**Circumstances:** Cancellation or an operation deadline occurs after the +reader's initial context check. The context is not passed into either file +helper. `os.Open` and `io.ReadAll` then run without further cancellation checks +or file-kind validation. On Linux, an existing FIFO beneath an allowed root +blocks in `os.Open` until a writer connects, even with a positive byte limit. +No symlink race, privileged filesystem modification, or real provider is +needed to encounter this case. + +**Expected:** File acquisition participates in cooperative cancellation and +does not remain indefinitely pending on an unsupported input source. The +[source internals](../../internal/sources.md) say reads honor cancellation; +the [HTTP contract](../../api.md) includes artifact preparation within the +engine operation budget. This does not require forced interruption of every +synchronous filesystem operation or an immediate-stop guarantee. + +**Actual:** Canceling an in-flight FIFO read leaves it blocked. After an +external writer supplies data and closes, the reader returns a successful +artifact with a nil error despite the canceled context. In the actual engine +path, a 30 ms operation budget remained pending at 150 ms and completed with +an operation-timeout error only after the diagnostic connected a writer. +Without that external action, the request can remain stuck. + +**Evidence:** Reproduced directly through the restricted reader and through +`Engine.Run` with `WithArtifactReader`, a FIFO input, and an operation budget. +Both diagnostic goroutines were released after observation. Existing +`TestRestrictedArtifactReaderRejectsCanceledAndMalformedReferences` checks an +already-canceled context, not cancellation during acquisition. The selected +PromptKit ordinary reader already checks regular-file status before opening +and checks context between read chunks; replacing it loses those behaviors. + +**Potential remediation:** Pass the context through file acquisition and +perform cooperative checks during reading and before returning the artifact. +Align unsupported-file handling with the upstream regular-file reader, which +avoids opening an existing FIFO, while retaining the application's lexical +root and byte-limit behavior. If streaming/non-regular inputs are intended, +they need an explicit cancellation-aware acquisition design instead. Do not +introduce an unrelated symlink sandbox, a forced-interruption promise, or a +goroutine wrapper that merely abandons a permanently blocked read. + +## Validation And Limits + +- Go 1.27.4: uncached `go test ./...` and `go test -race ./...` passed. +- `go vet ./...`, a temporary application build, launcher version/shell checks, + and whitespace checks passed. The copied delivery workflow still matches + the selected upstream template. +- Used temporary standalone Go diagnostics and synthetic files/FIFOs with a + loopback provider to substantiate all three findings. No new repository + tests or production code were introduced; no paid APIs, real credentials, + production releases, or external publication were used. +- No additional substantiated functional defect was found in the reviewed + CLI/configuration/reporting/lifecycle paths. This is not a guarantee that + other defects do not exist or that production hosted delivery was tested.