Record algorithmic audit findings

This commit is contained in:
2026-12-06 02:39:19 +00:00
parent fad1567e54
commit 633df7a02b

View File

@@ -29,6 +29,16 @@ Existing focused CLI tests for calendar delivery, diagnostic delivery, build
readiness, and selector mapping pass. These probes used no external services;
their expected-behavior assertions fail on the identified integration gaps.
An algorithmic audit at `fad1567` reviewed Stages 1–15 in order against the
same production baseline. Findings 12–14 identify avoidable membership scans,
package-input enumeration, and log buffering. Their bounds follow from the
implemented loops, Git arguments, and the local Go 1.27.4 standard library;
no workload measurements or benchmarks were needed. Existing offline tests for
release identity, version contracts, readiness, Woodpecker, and rehearsal pass.
The review preserves the selected sequential polling, complete pagination,
record snapshots, and in-job content comparison, together with the resource
work explicitly deferred in [the earlier assessment](deferred-resources.md).
### Stage coverage
| Stage | Evidence reviewed | Related findings |
@@ -39,13 +49,13 @@ their expected-behavior assertions fail on the identified integration gaps.
| 4 | Working and committed build/delivery identities, managed/prebuilt verification, tagged preparation | 6, 10 |
| 5 | Publication record versions and exact bytes, receipt schema 2, explicit recovery and durable entry points | — |
| 6 | Local file and CI variable selection, migration errors, operation-specific credential loading | 1 |
| 7 | Readiness defaults, narrowing, offline scope, input readers and error aggregation | 1, 2, 3, 11 |
| 7 | Readiness defaults, narrowing, offline scope, input readers and error aggregation | 1, 2, 3, 11, 13 |
| 8 | Source-only pin, host installer, local/CI selection and recovery fixtures | — |
| 9 | Committed profiles, tag manifests, identity binding, private record lifecycle | 4, 6 |
| 10 | Woodpecker API pagination/correlation and diagnostic Git/forge effects | 4, 5, 6, 8 |
| 11 | Shared builds/uploads, in-job read-back, framed verification evidence | 6, 7, 10 |
| 12 | Start, dispatch reconciliation, observation and partial results | 2, 3, 4, 7, 8, 11 |
| 13 | Quiescence, ownership checks, partial deletion, resume and cleanup | 4, 5, 7 |
| 11 | Shared builds/uploads, in-job read-back, framed verification evidence | 6, 7, 10, 14 |
| 12 | Start, dispatch reconciliation, observation and partial results | 2, 3, 4, 7, 8, 11, 12, 13, 14 |
| 13 | Quiescence, ownership checks, partial deletion, resume and cleanup | 4, 5, 7, 12 |
| 14 | CLI/configuration mapping, reporting, exit classes and maintained workflow dispatch | 1, 6, 7, 10 |
| 15 | Assembled fixtures, canonical references and migration guidance | 9; regression gaps identified below |
@@ -438,3 +448,111 @@ preflight reaching dispatch with that profile. Pair at least one case with an
actual shared-builder success. Retain failures for missing literal directories
and keep pattern-resolution limits explicit rather than certifying a future
build.
## 12. CI run bookkeeping performs quadratic membership scans
**Priority:** P3. **Stages:** 12, 13.
**Relevant code:** `observe` and `containsID` in the
[rehearsal coordinator](../../internal/rehearsal/coordinator.go), and
`quiescent` in [cleanup](../../internal/rehearsal/cleanup.go).
Each pass iterates matching pipelines and calls `containsID` on the growing
`attempt.PipelineIDs` slice. With `R` distinct runs and no recorded IDs, a
complete pass makes `R(R-1)/2` unsuccessful ID comparisons while inserting
them. A complete subsequent pass over the same recorded runs makes
`R(R+1)/2` comparisons. Thus local membership
bookkeeping takes O(R²) time per observation or quiescence pass, independently
of the required linear API traversal and workflow inspection. Repeated polling
repeats this cost; reruns increase `R` for the same saved attempt.
**Recommended remediation:** build a transient map from recorded pipeline ID
to its recorded number once per operation, update it as new runs are observed,
and use it for membership checks. Rebuild it from the saved slices on recovery.
Keep the slices as the ordered encoded evidence and preserve ID/number
consistency checks. Expected membership work becomes O(R) per pass with O(R)
additional indexing space; the overall evidence already occupies O(R) space.
This change preserves complete matching-run observation and the selected
cleanup quiescence rules.
**Regression coverage:** initial and repeated observations of several paginated
runs, newly discovered reruns, ordered ID/number evidence after recovery, and
missing or mismatched previously observed runs. Preserve existing active-run
and deletion guards. Verify the loop uses indexed membership; elapsed-time
thresholds are unnecessary.
## 13. Package readiness enumerates more metadata than its check needs
**Priority:** P3. **Stages:** 7, 12.
**Relevant code:** `inspectCommittedBuild` in
[committed readiness](../../internal/readiness/committed.go),
[`git.ReadTree`](../../internal/git/source.go), and `inspectBuild` in
[working readiness](../../internal/readiness/readiness.go).
Both readers need to establish that the selected literal package directory
contains a readable non-test Go input. The current implementations do extra
work before they can return the first acceptable input:
- Committed readiness calls `git.ReadTree`, which runs recursive
`ls-tree -r --full-tree` for the entire commit, then filters entries by the
resolved package directory. For `N` repository entries and `G` immediate
package entries, metadata enumeration and allocation are O(N), even when
`G` stays small as unrelated repository content grows. This runs during
rehearsal preflight as well as committed input inspection.
- Working readiness uses `os.ReadDir(path)`. That helper reads all `G` entries
and sorts them before inspection, adding worst-case O(G log G) sorting and
O(G) metadata space. This existence/readability check requires neither a
complete sorted list nor a particular successful filename.
**Recommended remediation:** after resolving the committed directory, list
that directory's immediate entries through the Git boundary, using its tree
object or a literal directory selection. Preserve captured-commit and symlink
resolution semantics. Metadata work can then depend on O(G), plus the existing
path-resolution cost, instead of the entire repository. For working inputs,
iterate an open directory with batched `File.ReadDir` calls and stop on a
readable input; this gives O(G) worst-case scanning with bounded batch storage.
Actual source-blob reading costs are separate from these metadata bounds.
Coordinate this refactor with finding 11 so package patterns retain their
supported interpretation.
**Regression coverage:** root and nested literal packages, a small package
beside unrelated committed subtrees, readable and unreadable input candidates,
symlinked inputs, and no eligible Go files. Retain the tests that distinguish
committed inputs from a changed working checkout. Confirm scoped Git listing
and unsorted directory iteration by reviewing their respective boundaries;
no runtime threshold or public directory-size limit is needed.
## 14. Result parsing buffers ordinary log lines that it discards
**Priority:** P3. **Stages:** 11, 12.
**Relevant code:** `ReadResult` in the
[rehearsal result parser](../../internal/rehearsal/result.go).
The parser uses `bufio.Reader.ReadString('\n')` for every log line before
checking `ResultPrefix`. `ReadString` accumulates and copies all fragments of
an arbitrarily long line. An ordinary CI output line therefore requires memory
proportional to its entire length even though the parser immediately discards
it. The existing long/chunked-log test demonstrates that these lines are valid
inputs but does not constrain their buffering strategy.
For `L` bytes in the longest ordinary line and `E` bytes of retained or candidate
result evidence, peak parser storage includes O(L + E). Large single-line
diagnostics can dominate memory even when the actual rehearsal result is small.
Processing time is already linear in the total log bytes.
**Recommended remediation:** inspect the fixed prefix at each line start and
consume ordinary lines through reusable `ReadSlice` fragments, discarding them
as they arrive. Accumulate only candidate result lines for the existing JSON
decoder and canonical comparison. This reduces buffering to O(B + E), where
`B` is the reader buffer, while retaining linear processing time and support
for arbitrarily long result lines. Preserve framing across reads, final lines
without a newline, CRLF handling, identity checks, equivalent retransmission,
and conflicting-result rejection.
**Regression coverage:** retain the current long/chunked-log and result-conflict
cases; exercise long ordinary lines before and between results, partial prefixes
across reader fragments, and final unterminated lines. Review that discarded
fragments are not accumulated. This needs neither a new log-line limit nor
workload measurements.