Record algorithmic follow-up audit findings
This commit is contained in:
@@ -157,3 +157,193 @@ additional cancellation/capture overlay failed as described. No API credentials,
|
||||
production inference, application fixes, or permanent test edits were used.
|
||||
Local link checks found no missing targets among 199 distinct paths referenced
|
||||
by the 15 changed canonical documentation files inspected.
|
||||
|
||||
## Algorithmic Follow-Up Audit
|
||||
|
||||
Reviewed the 36 stages of [implementation.md](implementation.md) at
|
||||
`5ffe22f5ac9dfb096f80670645e54f547b9ffec9` on 2026-11-26. The earlier cancellation/
|
||||
capture finding above is resolved. This additional review identifies three
|
||||
efficiency opportunities for consideration, not three newly introduced bugs or
|
||||
three failures to implement the accepted plan. No further functional correctness
|
||||
defect was confirmed.
|
||||
|
||||
The fixed typed pipeline remains coherent. Core owns operation execution,
|
||||
assessment, reuse, and ready-job coordination; capture has a shared owner;
|
||||
families own semantic rules, evidence identity, and canonical ordering. One run
|
||||
index serves extraction and cache decoding. Completed diagnostics survive lane
|
||||
failure and aggregate once, while obsolete extraction intermediates are released.
|
||||
The CLI owns invocation, publication, and reporting; the executable owns signals.
|
||||
|
||||
This pass inspected production paths and relevant tests in stage order, using
|
||||
graph discovery and current source. It excludes reconsideration of selected
|
||||
algorithms: sorted/coalesced citation intervals, bounded lazy scheduling, complete
|
||||
assessment, detached validator inputs, stable domain ordering, genuine evidence
|
||||
tie comparisons, item duplicate buckets with exact equality, native conversation
|
||||
capture, and accepted-result caching. CAT-033's deferred token matcher stays
|
||||
deferred. Required data copies and emitted overlapping chunk content are not
|
||||
treated as defects merely because they cost time or space.
|
||||
|
||||
### ALG-001 — Validators Still Rebuild The Whole-Source Index
|
||||
|
||||
**Priority:** Medium efficiency opportunity; adjacent follow-up to Stages 5–9,
|
||||
not a regression or reopening of their completed extraction/cache scope.
|
||||
|
||||
**Evidence:** [NewDocumentIndex](../../internal/core/source/validation.go#L17)
|
||||
allocates and fills a map over every source unit. Although extraction now borrows
|
||||
the runner's index, [TypedValidationRequest](../../internal/framework/contracts/typed_pipeline.go#L59)
|
||||
has no corresponding borrowed index. Validators construct it again for each
|
||||
assessment, for example [spell citations](../../internal/modules/dnd/validate/spells/source_refs/validator.go#L38),
|
||||
[NPC citations](../../internal/modules/dnd/validate/npcregistry/source_refs/validator.go#L39),
|
||||
and [scene citations](../../internal/modules/dnd/validate/scenedescriptions/source_refs/validator.go#L40).
|
||||
All ten source-relatedness adapters also construct a
|
||||
[CitationResolver](../../internal/modules/dnd/shared/citations.go#L19), whose
|
||||
constructor builds another whole-source index. These validators appear in the
|
||||
[production chains](../../internal/modules/dnd/register/chains.go).
|
||||
|
||||
**Complexity:** Let `D` be source units and `A` the total applicable validator
|
||||
invocations across delivered candidates. Index construction alone still costs
|
||||
`Theta(A * D)` time and cumulative map allocation. With fixed-size chunks,
|
||||
fixed lane/validator counts, no cache hits, and one candidate per job,
|
||||
`A = Theta(D)`, making this indexing component quadratic in transcript length.
|
||||
Concurrent assessments can also hold multiple equivalent `O(D)` maps.
|
||||
|
||||
**Potential refactoring:** Carry the existing run-owned immutable index through
|
||||
the validation target and typed request, with an optional-index citation resolver
|
||||
constructor. Reuse it in source-reference and relatedness validators, and other
|
||||
applicable validation consumers. Keep local construction when a standalone caller
|
||||
omits it. This reduces the indexing component to `O(D + A)` work and one shared
|
||||
`O(D)` map, excluding the actual citation checks and returned text.
|
||||
|
||||
The index is valid for detached source copies with unchanged IDs/order; preserve
|
||||
the selected per-validator source, artifact, reference, and metadata isolation.
|
||||
In particular, [isolatedValidationTarget](../../internal/framework/pipeline/candidate_assessment.go#L132)
|
||||
still intentionally clones source units per validator. That copying remains
|
||||
source-scale, so sharing indexes does **not** make the whole validation pipeline
|
||||
linear. This is a narrower allocation/work reduction, not permission to remove
|
||||
isolation, assessment, or source checks. Add no process-global cache or mandatory
|
||||
new argument for standalone callers.
|
||||
|
||||
**Verification:** Retain literal valid/invalid/containment/relatedness cases;
|
||||
exercise supplied and omitted indexes, concurrent readers, and separate runs
|
||||
with the same source ID but changed layouts. Inspect the construction paths to
|
||||
establish the cost reduction. Do not use elapsed-time or allocation ceilings as
|
||||
new public contracts.
|
||||
|
||||
### ALG-002 — Reference Collision Checks Compare Every Pair Of Keys
|
||||
|
||||
**Priority:** Low; configuration-resolution cost, not per-model-call work.
|
||||
|
||||
**Evidence:** [referenceSourceMapsConflict](../../internal/framework/pipeline/reference_resolution.go#L34)
|
||||
scans every override key for every base key, trimming override keys repeatedly.
|
||||
The resolver calls it for pipeline/step defaults and lane/extractor references.
|
||||
It is unchanged logic relocated during Stage 26, not a newly introduced defect;
|
||||
the plan selected responsibility separation, not this all-pairs algorithm.
|
||||
|
||||
**Complexity:** For `P` base entries and `Q` override entries, a nonconflicting
|
||||
case performs `P * Q` pair comparisons, including repeated string trimming.
|
||||
For comparable map sizes this is quadratic even though the operation is an
|
||||
exact, whitespace-normalized key lookup. Extra storage is currently constant.
|
||||
|
||||
**Potential refactoring:** Index trimmed keys and their generated/external source
|
||||
kind from one side, then probe from the other: expected `O(P + Q)` map work,
|
||||
plus processing key bytes once, using `O(P)` or `O(Q)` temporary entries. Preserve
|
||||
the existing predicate, including raw keys that trim to the same name. If the
|
||||
helper continues accepting unnormalized maps, retain both observed source kinds
|
||||
per trimmed key rather than overwriting one arbitrarily. Leave duplicate-name
|
||||
validation and error context with their existing owners; add no new key restriction.
|
||||
|
||||
**Verification:** Compare same-kind, opposite-kind, disjoint, whitespace-equivalent,
|
||||
and repeated-trimmed-key cases against the current simple pairwise predicate.
|
||||
Retain resolver collision and generated-binding regressions. A temporary reference
|
||||
oracle is sufficient; no benchmark or framework is needed.
|
||||
|
||||
### ALG-003 — Chunk Range Capacity Can Scale With Source Size For One Range
|
||||
|
||||
**Priority:** Low; avoidable space/zeroing cost for valid high-overlap settings.
|
||||
Stage 1's overflow defect is fixed; this concerns the retained upper-bound capacity.
|
||||
|
||||
**Evidence:** [PrepareChunk](../../internal/modules/generic/chunk/units/chunker.go#L65)
|
||||
reserves `ceil(D / step)` range entries, where `step = max_units - overlap_units`,
|
||||
but stops as soon as a range reaches the end. With `max_units = D` and
|
||||
`overlap_units = D - 1`, it reserves `D` entries while returning one range.
|
||||
A temporary offline Go overlay reproduced capacities 4 and 40 for sources of
|
||||
4 and 40 units respectively; both produced exactly one range. No production
|
||||
measurement or large-memory experiment was needed.
|
||||
|
||||
**Complexity:** The range slice uses `Theta(D)` extra reserved storage in that
|
||||
case, although its output has size one. More generally, for `C` emitted ranges,
|
||||
the desired range-storage cost is `O(C)`, not an arbitrarily loose `O(D / step)`
|
||||
bound. Source validation remains `O(D)` regardless; this is not an end-to-end
|
||||
linear-time-to-constant-time claim.
|
||||
|
||||
**Potential refactoring:** Reserve the actual range count using remaining-length
|
||||
arithmetic: one when `D <= max_units`, otherwise
|
||||
`1 + ceil((D - max_units) / step)`. Compute the ceiling by quotient/remainder,
|
||||
not overflowing addition. Alternatively omit the optional capacity estimate and
|
||||
let append grow with the actual output. Both retain the accepted option domain,
|
||||
range endpoints, overlap, early exit, and Stage 1's overflow safety.
|
||||
|
||||
**Verification:** Preserve literal ordinary overlap and maximum-integer option
|
||||
tests; include the one-range/high-overlap case. Inspect the resulting allocation
|
||||
formula rather than freezing an exact slice capacity or production allocation
|
||||
ceiling in permanent tests. The temporary capacity diagnostic is not a proposed
|
||||
durable behavior contract.
|
||||
|
||||
### Stage-By-Stage Algorithmic Coverage
|
||||
|
||||
| Stage | Inspected result |
|
||||
| --- | --- |
|
||||
| 1 | Range endpoint/loop arithmetic and reconciliation window bounds are safe; range capacity has ALG-003. |
|
||||
| 2 | Exact rational sign rejects underflowed negatives; finite-number and precision behavior remain. |
|
||||
| 3 | Producer insertion/lookup uses structured keys; no separator ambiguity or repeated producer search. |
|
||||
| 4 | Active slice identity includes visible length; finite views remain distinct from genuine cycles. Required recursive copying remains output-proportional, with deterministic map-key sorting. |
|
||||
| 5 | Citation text validates in input order, sorts/coalesces intervals, and visits only their union: `O(R log R + U + B)` after index setup. Constructor repetition is covered by ALG-001. |
|
||||
| 6 | Runner constructs and passes one read-only index; standalone cache decoding retains lazy construction. Validation is the additional scope in ALG-001. |
|
||||
| 7 | All three registry extraction paths use the supplied index, retaining local fallback. |
|
||||
| 8 | Occurrence extraction reuses the index, including location grounding; no additional index hidden in that grounding path. |
|
||||
| 9 | Spell, combat, enemy, and scene paths reuse it; combat gating still precedes unnecessary work; scene cache/fallback shares the same snapshot. |
|
||||
| 10 | Worker tests establish overlap/order with controlled handshakes rather than performance assumptions. |
|
||||
| 11 | Shared capture does work proportional to requested evidence, retains prepared ownership, and keeps writing outside native admission. |
|
||||
| 12 | Debug-only envelopes are constructed behind effective-sink guards, including deferred chunk outcomes. |
|
||||
| 13 | Source capture has one effective sink and shared original/parsed records; operation references are constant-size. Inline chunk/native evidence remains selected behavior. |
|
||||
| 14 | Diagnostic maps group by identity, with constant bounded sample scans and checked occurrence arithmetic; no growing all-group search. |
|
||||
| 15 | Public output excludes private working accumulators; intermediate copies have explicit stage boundaries. |
|
||||
| 16 | Completed diagnostic collection/assembly is linear in jobs plus emitted groups, independent of lane acceptance. |
|
||||
| 17 | One aggregation pass retains the valid prefix and joined causes; the composed cancellation/capture fix above remains present. |
|
||||
| 18 | Reorder maps and completed extraction values are released after consumers; diagnostics and required normalized bytes survive. |
|
||||
| 19 | Source/chunk/output phases retain explicit boundaries; their required encoding/copying work tracks selected data. |
|
||||
| 20 | Invocation-local lifecycle avoids declaration-shared mutable run state; finalization retains causes and published locations. |
|
||||
| 21 | Standard-library signal context stops dispatch and drains work; subsequent-signal restoration adds no per-job scheduling layer. |
|
||||
| 22 | Pure copies traverse supported container trees and preserve omission/ownership; no serialization round trip. |
|
||||
| 23 | Layout traverses steps/lanes once plus selected deterministic sorting; duplicate identities use maps. |
|
||||
| 24 | Inventory traverses configured targets/slots with keyed catalog selection; nested loops reflect distinct input dimensions. |
|
||||
| 25 | CLI reuses inventory; broad selectors enumerate their actual target matches. No second module interpreter remains. |
|
||||
| 26 | Generated producer/slot checks are indexed; reference-source collision checking retains the all-pairs scan in ALG-002. |
|
||||
| 27 | Family scene checks are linear in scenes/field text; adapters retain their separate acceptance responsibilities. |
|
||||
| 28 | Shared NPC/location grouping is expected linear in records and complete identity bytes; removed-index output is linear in removed records. |
|
||||
| 29 | Combat/spell grouping shares that mechanism while retaining no-change behavior; selected item exact-equality buckets remain untouched. |
|
||||
| 30 | NPC/location earliest-position keys are prepared once; actual evidence ties retain their selected linear comparisons. |
|
||||
| 31 | Item/enemy scalar/evidence keys are prepared once; enemy validation uses the fast path only after canonical evidence checks. |
|
||||
| 32 | Prompt test changes affect test resilience, not production algorithms or prompt content. |
|
||||
| 33 | Example fixtures are independent; private run-ID formatting is no longer frozen. No production algorithm changed. |
|
||||
| 34 | Comments describe actual sharing/lifetimes, without blanket locking or per-job construction. |
|
||||
| 35 | Confirmed dead metadata/helpers are removed; live identity and cache behavior remain. |
|
||||
| 36 | Existing completion checks and canonical docs agree with the selected architecture; this pass adds efficiency follow-ups only. |
|
||||
|
||||
### Validation And Limits
|
||||
|
||||
The focused offline package check passed (Go reused cached results where valid):
|
||||
|
||||
```sh
|
||||
go test ./internal/modules/generic/chunk/units ./internal/modules/seriatim/input/transcript ./internal/core/source ./internal/modules/dnd/shared ./internal/framework/diagnostics ./internal/framework/pipeline ./internal/modules/dnd/normalize/... ./internal/modules/dnd/validate/...
|
||||
```
|
||||
|
||||
The temporary overlay ran the real chunker's preparation on small synthetic
|
||||
sources and inspected its output length/capacity. It changed no tracked test or
|
||||
production file. The repository-wide tests, vet, build, targeted race suite,
|
||||
and repeated cancellation checks from the immediately preceding remediation
|
||||
remain applicable to this unchanged production revision. This pass gathered no
|
||||
real-world performance data, used no provider credentials, and changes only this
|
||||
report. Complexity claims concern the named components, not measured application
|
||||
speedups. None of these opportunities authorizes removing chosen ownership or
|
||||
validation boundaries, changing accepted inputs, or introducing a new runtime cap.
|
||||
|
||||
Reference in New Issue
Block a user