Record preflight scalability improvements
This commit is contained in:
@@ -8,6 +8,9 @@ Reviewed implementation commit `c08e5ab` against all eleven stages of
|
||||
A follow-up integration audit at `ab44543` reviewed those stages against the
|
||||
existing run, configuration, source, reference, cache, capture, and reporting
|
||||
paths. Findings 1 and 2 remain open; Finding 3 records the additional result.
|
||||
An algorithmic audit at `3df1a53` adds Findings 4 and 5. It preserves algorithms
|
||||
explicitly selected during planning and uses source-level complexity analysis,
|
||||
not production measurements or latency estimates.
|
||||
|
||||
The intended architecture is in place. Run and explicit preflight share local
|
||||
selection and construction; prepared adapters own source parsing; domain owners
|
||||
@@ -17,9 +20,10 @@ capture, and native readiness reporting. Offline pipeline validation remains
|
||||
offline. Preflight neither executes the substantive pipeline nor initializes
|
||||
an accepted-result cache store.
|
||||
|
||||
Three follow-ups are warranted: consistent error propagation at the smoke observer
|
||||
boundary, narrow documentation corrections, and consistent handling of marked
|
||||
sensitive runtime parameters in invocation capture. No unintended strengthening of
|
||||
Five follow-ups are warranted: consistent error propagation at the smoke observer
|
||||
boundary, narrow documentation corrections, consistent handling of marked
|
||||
sensitive runtime parameters in invocation capture, linear target association
|
||||
building, and avoiding disabled-capture work. No unintended strengthening of
|
||||
permissions policy, provider capability requirements, retry budgets, or readiness
|
||||
guarantees was found. Keep the accepted scope unchanged while remediating.
|
||||
|
||||
@@ -166,6 +170,98 @@ early preparation failure as well as successful execution, since early capture
|
||||
must not depend on later native evidence becoming available. Prefer content and
|
||||
immutability assertions over full snapshots of the private capture layout.
|
||||
|
||||
## Finding 4: Build Target Associations With Ordered Sets
|
||||
|
||||
**Priority:** P2 — scalability; plan Stage 3.
|
||||
|
||||
**Owner:** [Target discovery](../../internal/preflight/targets.go), especially
|
||||
`DiscoverTargets` and `appendScope`.
|
||||
|
||||
Let `A` be the number of selected role/initial-prompt associations visited by
|
||||
discovery, `P` the distinct selected profiles, and `K` the distinct access scopes.
|
||||
The outer profile/backend lookup maps are appropriate, but `appendScope` scans
|
||||
the complete accumulated binding slice on every insertion. For `B` distinct
|
||||
bindings sharing one profile and backend, each slice performs
|
||||
`0 + 1 + ... + (B-1)` comparisons. The two slices together perform `B(B-1)`
|
||||
comparisons: **Theta(B²)** even though there are only Theta(B) associations to
|
||||
return. The same backend-list problem exists when many distinct profiles share
|
||||
one backend.
|
||||
|
||||
Discovery also calls native `InspectProfile` before consulting its existing
|
||||
profile map, so a shared profile is inspected once per association rather than
|
||||
once per profile. Repeated initial prompts without an explicit profile likewise
|
||||
repeat `InspectPrompt`. These return detached resource views; that repeated
|
||||
inspection/copy work is unnecessary for the invocation's fixed captured engine.
|
||||
|
||||
### Refactoring Opportunity
|
||||
|
||||
- Retain ordered result slices and companion membership sets keyed by the
|
||||
comparable `BindingScope` value for each profile/access target. Insert into
|
||||
the slice only when absent from its set. This gives expected **O(A)**
|
||||
association-building time and **O(A + P + K)** bookkeeping space, preserving
|
||||
exact deduplication and first-use ordering.
|
||||
- Reuse successful profile selection/backend association data once each profile
|
||||
is inspected. Memoize an initial prompt's default-profile lookup within this
|
||||
discovery call where it repeats. Native inspection calls can then be bounded
|
||||
by distinct selected resources rather than associations. Keep the small needed
|
||||
identities/indexes, not an application-owned replacement resource registry.
|
||||
- Preserve per-binding cancellation checks, error scope, endpoint-only behavior,
|
||||
and the native provider-check schedule. Do not introduce process-global caches,
|
||||
target fingerprints, altered profile equivalence, or different paid probes.
|
||||
|
||||
The roadmap specifies deduplicated targets and retained associations, not linear
|
||||
slice scans as the required implementation. This optimization preserves the
|
||||
accepted algorithmic policy. Native inspection's own cost is additional to the
|
||||
association bound above; no upstream cost or real-world speedup is assumed here.
|
||||
|
||||
### Verification
|
||||
|
||||
Use independent expected ordered associations for shared-profile,
|
||||
shared-backend/different-profile, and duplicate-binding/multiple-prompt cases.
|
||||
Retain the existing target and native probe-deduplication tests. Verify the
|
||||
complexity improvement by reviewing the map-based insertion path; wall-clock
|
||||
thresholds and production benchmarks are unnecessary.
|
||||
|
||||
## Finding 5: Skip Evidence Preparation When Capture Is Disabled
|
||||
|
||||
**Priority:** P3 — avoidable work; plan Stage 7.
|
||||
|
||||
**Owner:** [Preflight command](../../internal/cli/pipeline_preflight.go), lines
|
||||
180–190, and [evidence writer construction](../../internal/cli/run_capture.go).
|
||||
|
||||
`executePreflight` constructs `newRunEvidenceRecorder(capture, loaded.result)`
|
||||
and supplies its observation callback unconditionally. With capture disabled,
|
||||
the underlying recorder ultimately discards writes, but the work before that
|
||||
no-op boundary still happens:
|
||||
|
||||
- Construction enumerates all `H` historical configuration paths and all `R`
|
||||
configured profiles/backends, including unselected resources, to build masks.
|
||||
This entails at least **Omega(H + R)** capture-specific traversal work and
|
||||
temporary indexing, in addition to the native metadata API's own costs.
|
||||
- Every smoke report still passes through target masking, which can copy
|
||||
parameter maps for marked fields, even though none will be written. For `S`
|
||||
reports with `M` matching top-level marks over `E` parameter entries, that
|
||||
existing per-mark shallow-copy path can perform **O(S * M * E)** extra work.
|
||||
|
||||
The ordinary run path already avoids constructing this writer when capture is
|
||||
disabled. The new preflight call site bypasses that guard.
|
||||
|
||||
### Refactoring Opportunity And Verification
|
||||
|
||||
Construct the evidence writer and install its callback only when capture is
|
||||
enabled; otherwise pass a nil observer to `RunSmokeChecksObserved`. Its native
|
||||
observations still return normally for readiness interpretation. This reduces
|
||||
disabled-capture evidence preparation to **O(1)**, excluding required smoke
|
||||
execution, report construction, and the earlier configuration load.
|
||||
|
||||
Keep active capture's masks, failure propagation, and native usage separation
|
||||
unchanged, including Findings 1 and 3's required behavior. Do not change the
|
||||
shared helper merely to forbid existing standalone/test uses of a nil recorder.
|
||||
Use existing enabled/disabled preflight tests to verify identical readiness and
|
||||
provider-call behavior with no debug files when disabled. No performance threshold
|
||||
or new instrumentation framework is needed. This finding does not require
|
||||
redesigning the pre-existing active-capture masking algorithm.
|
||||
|
||||
## Stage-By-Stage Review Evidence
|
||||
|
||||
| Plan stage | Review result |
|
||||
@@ -180,7 +276,23 @@ immutability assertions over full snapshots of the private capture layout.
|
||||
| 8 — Assembled verification | Existing real-kit/local-provider tests pass. An additional temporary offline test exercised the unabridged maintained D&D pipeline, its ordinary transcript/reference inputs, generated handoffs, and selected target discovery; it passed with one shared-profile model call and no substantive execution. |
|
||||
| 9 — Public documentation | Command/report and subprocess workflows are documented, including fixture scope and process-status handling. Finding 2 corrects the Operations hierarchy. |
|
||||
| 10 — Internals and architecture | Native ownership, shared parsing, online versus offline boundaries, and smoke usage separation are documented. Finding 2 corrects the stale run-only capture sentence. No unrelated architecture restriction was introduced. |
|
||||
| 11 — Final verification | Tests, vet, build, both help routes, and offline validation succeed. The three findings above should be addressed before treating the reviewed work as complete. |
|
||||
| 11 — Final verification | Tests, vet, build, both help routes, and offline validation succeed. Correctness/documentation findings and the additional algorithmic opportunities above remain recorded for remediation. |
|
||||
|
||||
## Algorithmic Audit Coverage
|
||||
|
||||
| Plan stage | Algorithmic assessment |
|
||||
| --- | --- |
|
||||
| 1 — Shared preparation | The extraction preserves the prior configuration/selection/materialization algorithms; no additional nested scan was introduced by the shared handoff itself. These deliberately reused algorithms were not redesigned. |
|
||||
| 2 — Parsing | Parsing/document validation is shared without a duplicate run parse; source-index construction remains once per run. No new algorithmic defect identified. |
|
||||
| 3 — Discovery | Finding 4 identifies quadratic binding accumulation and repeated resource inspections; hash-indexed target lookup itself is appropriate. |
|
||||
| 4 — Smoke checks | Sequential iteration is O(P + K) orchestration, excluding native calls and returned evidence. The agreed once-per-access/once-per-profile schedule and native retries are retained, not reconsidered. Finding 1 already covers the callback error issue. |
|
||||
| 5 — Destinations | Cache-use detection is linear in selected lanes and temporary-file probes are bounded per destination. Repeated constant-count scans do not make this quadratic. The filesystem policy is unchanged. |
|
||||
| 6 — Readiness report | Check accumulation and rendering use linear passes; serializing associated bindings is proportional to emitted data. No additional asymptotic issue identified. |
|
||||
| 7 — Capture | Finding 5 removes work for disabled capture. Findings 1 and 3 retain the previously established correctness fixes; no new capture algorithm or security policy is proposed. |
|
||||
| 8 — Tests | Existing tests express native verdicts, scopes, and probe counts. Future verification should protect these behaviors without timing assertions. |
|
||||
| 9 — Public docs | No runtime algorithm introduced; the earlier documentation finding remains unchanged. |
|
||||
| 10 — Internal docs/policy | No runtime algorithm introduced and no reconsideration of accepted native ownership or capability policy. |
|
||||
| 11 — Verification | Source-level complexity analysis and focused tests suffice for these opportunities; no live-provider or real-world performance collection was needed. |
|
||||
|
||||
## Follow-Up Integration Audit Evidence
|
||||
|
||||
@@ -227,6 +339,9 @@ immutability assertions over full snapshots of the private capture layout.
|
||||
- Additional temporary integration tests passed the run/preflight/cache round
|
||||
trip and reproduced Finding 3 with a failing marked-context assertion in both
|
||||
command paths. They used synthetic placeholders, not actual credentials.
|
||||
- The algorithmic audit reran `go test ./internal/preflight ./internal/cli`
|
||||
successfully. Findings 4 and 5 follow from source-level operation counts and
|
||||
control flow; no benchmark or live-provider measurements were collected.
|
||||
|
||||
No live provider calls or real credentials were used. Artifacts and accepted cache
|
||||
entries exercised by the round-trip tests were synthetic temporary fixtures;
|
||||
|
||||
Reference in New Issue
Block a user