Record the algorithm audit findings

This commit is contained in:
2026-11-23 16:33:22 +00:00
parent a020d155f4
commit deec32cd4c

View File

@@ -1,12 +1,14 @@
# Library Adoption Remediation
**Status:** Findings from the implementation and follow-up integration reviews;
remediation has not begun.
**Status:** Findings from the implementation, integration, and algorithm
reviews; remediation has not begun.
**Reviewed source:** `338e93a7ebda9a86593069d63f9d5a7fe23ccaf5`
(`Complete library adoption validation and cleanup`).
The follow-up review used `ca06f7c4e34d5702d2234a56c84250c31435fcf2`, which
adds the initial findings without changing application code or dependencies.
The algorithm review used `a020d155f4f2b4270745a2e4ccf9c3565ea129e2`, which
adds the integration finding and also leaves application code unchanged.
The review covered Stages 1–10 of the [implementation plan](implementation.md)
against the [feature roadmap](library-upgrades.md), including implementation,
@@ -14,6 +16,8 @@ tests, maintained documentation, migration guidance, and release preparation.
The intended architecture is substantially in place. The initial review found
test-maintenance and documentation gaps; the follow-up integration review also
confirmed an output-safety gap involving operator-owned schema files.
The algorithm review adds a debug-assembly memory opportunity and a diagnostic
ordering defect. R1–R3 remain outstanding.
## R1: Remove the Test Fixtures' Implicit YAML Layout Requirement
@@ -155,6 +159,102 @@ Cover source-local origin selection at the source-tracking boundary and both
output-collision outcomes at an assembled boundary, reusing existing collision
semantics rather than duplicating their complete filesystem test matrix.
## R4: Build Per-Call Summaries Without a Second Event Inventory
**Priority:** P3 — optional debug-memory improvement.
**Affected code:**
- [Debug execution assembly](../../internal/framework/processreport/llm.go):
`BuildLLMExecution`, especially the `eventsByCall` construction and replay.
- [Native aggregation handoff](../../internal/framework/llm/observations.go):
`Summarize` replays each selected event sequence into an `ExecutionGroup`.
**Finding:** The builder copies the event slice for the returned artifact, then
copies every complete observation again into per-call slices in `eventsByCall`.
Those extra slices exist solely to replay their contents into native groups.
The grouping pattern predates this upgrade, but the revised builder carries it
forward with the richer native event values. The plan requires native per-call
aggregation and retained events; it does not require a second event inventory.
**Complexity:** Let `E` be observations, `C` logical calls, and `R` distinct
call/run memberships. Current assembly takes expected `O(E + C + R)` time, with
`Theta(E + C)` additional storage for event grouping. A map of call IDs to native
`*ExecutionGroup` instances can observe events directly in one pass, retaining
`O(C + R)` grouping state instead. This helps when attempts and repair activity
produce many events for each run. Required snapshot/artifact storage remains
linear in the retained evidence, and processing time remains linear; this is
an auxiliary-memory improvement, not a quadratic-time defect or a claim of
measured performance impact.
**Evidence:** Inspection of the selected native group shows that it retains
run membership and aggregate facts, rather than event history. A temporary
synthetic probe matched the existing per-call summaries using direct native
group accumulation for 40 events, four logical calls, and three observed runs,
including duplicate terminal events, incomplete coverage, and a call without
events. No benchmark or real-provider workload was used.
**Recommended change:** If undertaking this cleanup, accumulate native groups
by call ID while traversing the retained events, then snapshot those groups
when constructing calls. Preserve the returned event sequence and call order,
including for unsorted supplied snapshots. Continue delegating terminal
deduplication, coverage, usage, and cost to PromptKit. Retain the existing
invocation summary handoff; do not introduce copied metric DTOs or a second
accounting algorithm.
**Acceptance:** Per-call summaries retain their current meaning, including
pre-execution calls and incomplete runs, without allocating a second full
event inventory for grouping. Reuse existing reporting tests with a focused
multi-event case where needed. This opportunity does not require a new runtime
limit, benchmark gate, or change to the debug artifact schema.
## R5: Order Native Group Members at the Debug Presentation Boundary
**Priority:** P3 — deterministic diagnostic presentation.
**Affected code:**
- [Collector snapshots and summaries](../../internal/framework/llm/observations.go):
`Snapshot` and `Summarize`.
- [Debug execution assembly](../../internal/framework/processreport/llm.go):
top-level and per-call `promptkit` group summaries.
**Finding:** The selected PromptKit group enumerates its membership map when
creating `ExecutionGroupSummary.Members`. Audita now includes that slice in
debug output without ordering it. Sorting the surrounding calls and events
does not order the summary's members. An unchanged completed collector can
therefore produce different serialized membership orders across snapshots.
The previous metric projection did not expose this new slice.
Stage 5 explicitly retains deterministic presentation ordering. This is an
incomplete adaptation of native evidence to that selected presentation
requirement. Counts, correction decisions, and ordinary reports are unaffected;
the defect is confined to optional diagnostic presentation.
**Complexity:** Enumerating `R` members is linear. Canonical presentation adds
`O(R log R)` string comparisons for the invocation summary, plus
`sum O(R_i log R_i)` for per-call member lists. A detached copy costs `O(R)`
storage where an existing owned copy cannot be reused. This is a correctness
tradeoff for the already selected ordering requirement, not a speed optimization.
**Evidence:** A temporary overlay-only test populated one collector with 32
completed calls and fixed timestamps, then serialized 32 snapshots without
changing any records. It observed multiple distinct membership orders in the
top-level summary. The test file remained outside the repository.
**Recommended change:** At one Audita diagnostic-presentation boundary, order
detached native `Members` slices by run ID for the top-level and per-call
summaries. Preserve native values, attribution, and the existing call/event
sequence. Keep aggregation upstream and avoid changing shared snapshot slices
as a side effect of rendering. No upstream ordering guarantee or new ordering
of model execution is required.
**Acceptance:** A fixed captured membership set has a consistent displayed
order, regardless of native map enumeration. Use a small deterministic
serialization regression with deliberately permuted member inputs; do not
retain the audit probe's probabilistic map-order check. Native totals,
availability, coverage, and run identities remain intact.
## Follow-Up Integration Coverage
The review revisited the numbered implementation stages in order:
@@ -168,6 +268,27 @@ The review revisited the numbered implementation stages in order:
| 8–9 | Maintained examples, migration guidance, canonical contracts, attribution, and prepared release documentation. | Existing R2 remains; no additional gap identified. |
| 10 | Cleanup and assembled workflows, including failure, cancellation, partial success, and output publication. | Existing tests pass; the schema-collision probes expose R3 beyond their coverage. |
## Algorithm Review Coverage
The algorithm review examined the implementation stages in their numbered
order. It did not reconsider the explicitly retained repair-history sharing,
native retry/repair/admission and aggregation algorithms, or presentation
ordering. No additional avoidable quadratic-time algorithm was identified in
the reviewed changes.
| Stage | Algorithm review result |
| --- | --- |
| 1 | Source composition and domain callback lifting delegate loading to the selected libraries; no additional local superlinear algorithm identified. |
| 2 | Bootstrap forwarding and diagnostic buffering are linear in their supplied evidence; the retained invocation-local capture is not a growing processing cache. |
| 3 | Source tracking uses maps for source identity, path deduplication, and native metadata lookup, followed by sorting unique paths. No repeated full metadata scan occurs per message. |
| 4 | Removal of contract overrides and registry copying simplifies the call path; response decoding is linear in response size. Existing domain algorithms are preserved. |
| 5 | Collection uses map updates and append operations; snapshot sorting follows the selected presentation design. Native membership ordering needs R5. |
| 6 | Report assembly is linear in calls/events but has the avoidable grouping storage in R4. R5 also applies to its native summary presentation. Planned message-prefix sharing is retained. |
| 7 | Context propagation and native invocation reporting add no separate local accounting algorithm. |
| 8 | Documentation and maintained-example updates introduce no additional production algorithm. |
| 9 | Attribution and release preparation introduce no additional production algorithm. |
| 10 | Cleanup and final wiring introduce no additional algorithm beyond those reviewed above. |
## Review Validation
With Go 1.27.4, the complete `go test -race ./...` suite, `go vet ./...`,
@@ -182,3 +303,11 @@ For the follow-up, uncached race-enabled tests passed for `internal/appconfig`,
`internal/framework/processreport`, and `cmd/audita`. The two controlled schema
collision probes confirmed R3. The follow-up changes only this remediation
document; it does not implement the fixes or publish a release.
The algorithm review used source-level complexity analysis and two temporary
synthetic tests through a Go overlay. The membership-order probe confirmed R5;
the single-pass native-group comparison supports R4. It gathered no real-world
performance data and made no application-code changes. Existing tests for
`internal/framework/llm`, `internal/framework/processreport`, and
`internal/framework/runner` passed; remediation links and whitespace checks
also passed.