Record source history scaling finding

This commit is contained in:
2026-12-05 16:52:55 +00:00
parent a675d3ab50
commit 57c943a156

View File

@@ -183,6 +183,57 @@ regardless of load outcome. Preserve the implemented error accessor and
inspection behavior; this calls for documentation clarification, not another
restriction on inspecting rejected configuration.
## Finding 4 — Avoid repeated scans of source observations during history construction
**Status:** Open. **Priority:** P2. **Affected stages:** 3, 4 and 6 through
their shared source-history construction.
### Relevant code and complexity
[observeSourcePrefix](../../internal/engine/override_context.go) calls
[observeSourceEvidence](../../internal/engine/history_source.go). That producer
first records every source application's contributions, then processes overlay
records. For each displaced definition it calls
`sourceOriginRepresentedByOperation` in the same file (around line 194).
The helper scans every observation at the path, filtering out contributions,
definitions and operations that cannot represent the requested origin.
Let `K` source applications contribute the same scalar path and let `R` overlay
records displace that path. Every helper call must scan past the initial `K`
contribution observations before reaching any eligible operation. The displaced
definition loop alone therefore requires at least `K * R` observation visits.
With `K` ordered underlay tiers repeatedly replacing `setting`, `R = K - 1`,
giving quadratic work even though this path's retained contributions and
replacement evidence have linear size. Later operation observations also
accumulate and are rescanned. Final-tree summary construction performs further
calls to the same helper.
This is an existing shared-helper inefficiency, now also used to construct
earlier failure views. It can increase the cost of reporting a decode or
resolver failure after many tier replacements. The selected design explicitly
reuses the producer; it does not prescribe this internal lookup algorithm.
The finding does not challenge chronological history, ownership copies,
checkpoint fallback, or the expressly selected whole-snapshot diff.
### Refactoring opportunity
Maintain an incremental index of eligible after-operation evidence by concrete
path and attribution rather than searching the general observation list for
each query. Narrow candidates using layer, operation and source/location
identity, retaining `originRepresentedByChange` semantics for composite origins
and ancestor replacements. Singleton-origin scalar replacements can then use
expected constant-time indexed lookups, making the repeated-scalar fixture
linear in its history size. A separate list containing only operations would
remove irrelevant contribution scans but would still leave repeated scans of
earlier operations; address both costs.
Preserve semantic key/index shapes, subset attribution, deduplication and
chronological output. Composite-origin matching may require additional work
proportional to attribution size; no general public performance guarantee is
proposed. Existing source/history cases should verify behavior after refactoring,
with a focused repeated-tier fixture covering the affected deduplication.
No timing thresholds or benchmarks are required to establish this static finding.
## Review coverage and validation
The review followed all ten implementation stages in order:
@@ -216,3 +267,28 @@ resolver-entry metadata, late secret/validation failures, scoped comparison,
passive contexts, nil/zero facade behavior and the one-invocation example.
No production code or permanent tests were changed during either review. No
further actionable integration gaps were identified.
## Algorithmic follow-up audit
Reviewed `a675d3ab50b9c6c2659e22bb4b8210a6004c5dc4`, with the same production
baseline as the prior audits. Finding 4 is additional; Findings 1–3 remain open.
The analysis followed the implementation stages in order:
| Stage | Algorithmic review |
| --- | --- |
| 1 | ADR 0025 establishes checkpoint semantics, without an additional executable algorithm to assess. |
| 2 | Shared finalization retains classification and source handling; extracting it adds no input-sized nested loop. Existing selected sensitivity/comparison mechanisms were preserved. |
| 3 | Source-tree traversal and origin copying scale with visited paths and attribution payloads. Finding 4 identifies avoidable repeated history scans in the shared producer. |
| 4 | Prefix construction reuses that producer, so Finding 4 also applies here. CLI application lists and source-ID deduplication otherwise use sequential walks and maps. |
| 5 | Late failures reuse the already-frozen resolved history rather than rebuilding it. No additional suboptimal algorithm was identified. |
| 6 | The number of checkpoint candidates is fixed by the lifecycle. Retrying a fixed number of prefixes does not itself make traversal quadratic in configuration size. Retained-node counting and document lookup construction memoize node identity. Ownership cloning remains as selected in the plan. |
| 7 | Stage conversion is constant-time and scope normalization scales with path length. Whole-snapshot comparison followed by scope filtering is expressly selected and was not reconsidered. |
| 8 | Reviewed the exercised construction/query paths without introducing performance assertions or changing selected comparison and redaction algorithms. |
| 9 | The maintained example acquires views from the same retained inspection and does not reload inputs. |
| 10 | Documentation and validation add no production algorithm; prior correctness/documentation findings were preserved rather than duplicated. |
Finding 4 follows directly from loop ordering and lookup contents; no empirical
performance data was collected. Production code and tests remain unchanged.
The prior successful checks apply to the unchanged runtime; this pass validates
the report's links and whitespace. No further algorithmic findings were identified
within the reviewed feature scope.