From e42031f2f6b9e8f29562a02a792dcbc59064bd7e Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Tue, 24 Nov 2026 14:24:17 +0000 Subject: [PATCH] Record functional correctness audit findings --- docs/roadmap/audit/01-correctness.md | 178 +++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 docs/roadmap/audit/01-correctness.md diff --git a/docs/roadmap/audit/01-correctness.md b/docs/roadmap/audit/01-correctness.md new file mode 100644 index 00000000..d55ffd6d --- /dev/null +++ b/docs/roadmap/audit/01-correctness.md @@ -0,0 +1,178 @@ +# Functional Correctness Audit + +## Baseline And Scope + +Reviewed revision `3887d89b763b7040efc866d4a57eb910d8778730` on 2026-11-24. +This is an audit of current behavior, not only the recent ReleaseKit changes. +Production code and repository tests were not modified. + +The review followed the implemented boundaries and their established contracts: + +| Area | Correctness concerns examined | +| --- | --- | +| CLI and configuration | Native loading/engine handoff, path origins and identifier normalization, reference overrides/unbinds, session/run composition, output and debug completion. | +| Source and chunk planning | Seriatim decoding and timestamps, source identity, document-position references, chunk materialization, accepted-plan reuse. | +| Pipeline orchestration | Complete assessment, initial/correction/fallback transitions, cancellation, ready-job dispatch and result ordering, merge/normalize execution, generated handoffs and reuse eligibility. | +| Domain transformations | Representative registry reconciliation and application, contextual identity resolution, spell/combat/item/location/enemy ordering and exact deduplication, scene normalization. | +| Output and state | Evidence-window union, JSON file naming and collisions, accepted-artifact codecs/cache I/O, confined atomic writes, partial publication and requested capture. | +| Release integration | Reused the immediately preceding stage-by-stage ReleaseKit review and its native build/version, profile, launcher, CI-template, and documentation checks; the subsequent cleanup changed documentation only. | + +Three reproducible numerical boundary defects warrant follow-up. No additional +ordinary-path correctness defect was substantiated in the inspected paths. +The scope is risk-directed rather than an exhaustive proof of every function or +every supported composition. Green tests do not cover the three cases below. + +## Finding 1: A Valid Large Generic Chunk Size Causes A Panic + +**Priority:** P2 — accepted module options can panic during ordinary planning. + +**Relevant code:** +[Chunker.Plan](../../../internal/modules/generic/chunk/units/chunker.go#L65), +especially the capacity expression at line 66; +[DecodeOptions](../../../internal/modules/generic/chunk/units/chunker.go#L108) +accepts positive `max_units` and non-negative overlap smaller than that maximum. + +**Circumstances and reproduction:** Parse a valid three-unit Seriatim document. +Decode the generic chunker options using +`map[string]any{"max_units": int64(math.MaxInt)}`, leaving overlap at zero, +construct the chunker with those options, and call `Plan`. On the reviewed +64-bit host the option is `9223372036854775807` and passes option decoding and +the checks at the beginning of `Plan`. + +**Expected:** A single range covering the whole three-unit document. A maximum +chunk size larger than the input should not require a large allocation. + +**Actual:** The ceiling-division numerator `len(units) + step - 1` overflows. +The resulting capacity is negative, and `make` panics with +`runtime error: makeslice: cap out of range` instead of returning a plan or an +error. The diagnostic harness recovered this panic only to record the result; +the production function does not recover it. A control with `max_units = 3` +returns the correct single range. + +**Reachability:** Unlike Finding 3's radius, `max_units` is a supported generic +chunker option. `pipeline.IntOption` admits the `int64` representation used by +ConfigKit dynamic option maps on the supported 64-bit platform. This is not a +claim that the default size of 50 is defective. + +**Potential remediation:** Use overflow-safe ceiling division for non-empty +input, such as `1 + (len(units)-1)/step`, or omit the optional preallocation. +Review endpoint arithmetic at the same boundary using remaining-length +comparisons rather than unchecked addition. No arbitrary new chunk-size limit +is needed. Follow-up tests should cover a small document with a maximum integer +chunk size, ordinary sizes, and overlap behavior. + +## Finding 2: Negative Timestamp Underflow Bypasses Non-Negativity Validation + +**Priority:** P2 — input-contract violation on an extreme numeric value. + +**Relevant code:** +[validTimestamp](../../../internal/modules/seriatim/input/transcript/adapter.go#L174), +especially the floating-point sign check at line 186 and exact rational parsing +at line 189. `sourceUnit` uses the returned rationals for start/end ordering. + +**Established contract:** The +[Seriatim input contract](../../integrations/seriatim.md#accepted-shape) +requires finite, non-negative start and end timestamps. Original numeric values +are retained in source-unit metadata. + +**Circumstances:** A negative timestamp has sufficiently small magnitude to +underflow `float64`, for example `-1e-1000`. `strconv.ParseFloat` returns negative +zero without an error. The expression `parsed < 0` is then false. Subsequent +`big.Rat.SetString` correctly recovers a genuinely negative value but its sign +is not checked. + +**Reproduction:** Call the production `transcript.New().Parse` with: + +```json +{ + "metadata": {}, + "segments": [ + {"id": 1, "start": -1e-1000, "end": 1, "speaker": "A", "text": "test"} + ] +} +``` + +**Expected:** Reject the negative start timestamp. + +**Actual:** Parsing succeeds and retains the negative timestamp in the document. +An ordinary `-1` start is correctly rejected; zero and a tiny positive value +are accepted. These controls and the defective case were executed against the +real adapter using a temporary diagnostic executable. + +**Potential remediation:** Check the exact parsed rational's sign with +`rat.Sign() < 0` before returning it, retaining the existing numeric/finiteness +handling unless a separate contract change is intended. This fixes the +underflow case without imposing a new magnitude restriction. Follow-up regression +coverage should include tiny negative/positive values, zero/negative zero, and +the existing high-precision start/end ordering case. + +## Finding 3: Context-Radius Addition Can Overflow And Omit All Evidence + +**Priority:** P3 — latent internal API defect; not reached by the current fixed +production defaults. + +**Relevant code:** +[Limits.Validate](../../../internal/framework/semanticreconcile/preparation.go#L42) +accepts every non-negative radius; +[Prepare](../../../internal/framework/semanticreconcile/preparation.go#L222) +adds that radius to each cited interval's ending position before applying `min`. + +**Established contract:** `Prepare` constructs bounded source-backed model +materials, and `Ready` means those materials are complete. `Limits` is an +explicit package input; no upper radius bound is established. The separate +byte budget already controls whether the resulting materials can be emitted. + +**Circumstances and reproduction:** Parse a valid three-unit document with IDs +1, 2, and 3. Supply two candidates citing unit 2 and unit 3, respectively. Take +`DefaultLimits()` and set `ContextRadius = math.MaxInt`, leaving the candidate +and byte budgets unchanged. On the reviewed 64-bit host the radius is +`9223372036854775807` and passes `Validate()`. + +**Expected:** Clamp the expanded context to the whole three-unit document. Since +that fits the existing byte budget, return `Ready` with all three units, marking +units 2 and 3 as cited. More generally, return the ordinary limit-exceeded +disposition if complete material exceeds the byte budget. + +**Actual:** `interval.end + limits.ContextRadius` wraps to a negative integer +before `min` can clamp it. Preparation returns `Ready`, no error, and: + +```json +{"windows":[{"units":[]},{"units":[]}]} +``` + +The same production function with radius 2 returns the expected three-unit +window. This was reproduced through the real `Prepare` API, not a copied +arithmetic example. A caller using the extreme accepted value could consequently +send a semantic reconciliation request without its supporting transcript text. + +**Current reachability:** The implemented D&D registry normalizers call +`DefaultLimits()` with radius 2 and expose no operator radius option. This is +therefore a package-boundary correctness issue, not evidence of missing context +in ordinary deployed runs. + +**Potential remediation:** Use overflow-safe clamping before addition: compare +the radius with the remaining distance to the last source position, and add +only when safe. The existing evidence-context builder's `expandEnd` demonstrates +this approach. Preserve the byte budget and accepted non-negative radius domain; +an arbitrary new maximum is unnecessary. A follow-up regression should exercise +an extreme radius, a normal radius, and existing byte-limit behavior. + +## Verification Performed + +Using Go 1.27.0, `GOWORK=off`, and `GOPROXY=off`: + +- `go test -mod=readonly ./...` passed, including cached results for unchanged + package inputs. +- `go vet -mod=readonly ./...` passed. +- Fresh focused tests (`-count=1`) passed for Seriatim input, semantic + reconciliation, evidence context, core configuration, and module integration. +- Race-enabled tests passed for pipeline, CLI, shared registry resolver, and + debug recorder. +- A temporary diagnostic executable, selected through a Go source overlay of + the CLI entry point, reproduced all three findings against the actual adapter, + reconciliation core, and generic chunker. It added no + repository tests or production edits. + +No model-quality evaluation, production inference, real API credential use, +source release publication, or hosted artifact delivery was performed. Upstream +kit internals were not independently audited as part of this application audit.