Skip to content

perf(checks): bound earlier error context selection - #20208

Closed
OrcaWin wants to merge 1 commit into
mainfrom
OrcaWin/codex-perf-09-11
Closed

OrcaWin wants to merge 1 commit into
mainfrom
OrcaWin/codex-perf-09-11

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​99

ELI5

Failed CI logs can contain thousands of errors, but Orca shows only the latest 30 lines of earlier error context. Find those lines from the end and stop as soon as the excerpt is full.

What Changed

Scan earlier log lines backwards, deduplicate overlapping context windows in a set capped at 30 entries, then restore chronological order. Preserve the existing error patterns, two-line context, recent tail, UTF-8 byte budget, and exact excerpt text.

Why

The old implementation scans every earlier line and stores/sorts every matching context index before discarding almost all of them. GitHub job logs can reach the existing 64 MiB download cap; this code runs synchronously when showing failed check details. GitLab uses the same excerpt function after its existing trace normalization.

Measured actual baseline and candidate functions on synthetic 100,000-line logs (~9 MB), macOS arm64, Node 26.6.0. Eight counterbalanced before/after pairs per workload; medians per call:

Log shape Before After
Dense earlier errors 8.9 ms 1.7 ms
Earlier errors every 100 lines 14.0 ms 1.8 ms
No errors 13.9 ms 14.0 ms
One error near the beginning 13.9 ms 13.8 ms

These measure excerpt generation, not network downloads or app-wide latency. The existing full-log split remains. No output is truncated differently and no new cache or state is introduced.

Linked Issue

Refs #20206. Performance audit PR 1; the broader audit remains open.

Visual Proof

N/A — the excerpt text and interactions are unchanged.

Testing

  • Automated verification on macOS; no visible Electron windows launched.
  • 37 tests pass across excerpt selection, GitLab trace normalization, and GitHub check details/checks.
  • Regression test fails on the baseline: 10,000 regex evaluations, versus at most 30 after the change. Boundary and overlapping-window tests preserve exact text.
  • 2,000 seeded differential inputs match the baseline exactly, including CRLF, Unicode, overlapping errors and byte-capped output. Benchmarks also cover 200 and 10,000 lines.
  • ORCA_BACKGROUND_LAUNCH=1 pnpm tc and changed-code quality checks pass.

Reproduce measurements from the repository root:

git show 20ab99506541:src/shared/check-job-log-tail-slice.ts | node config/scripts/check-job-log-tail-benchmark.mjs

Review

Descending error positions have descending context endpoints, so once the most recent 30 unique lines are selected, earlier errors cannot contribute a newer line. Both Git providers use the same pure function; no path, platform, Git command, SSH execution boundary, or wire format changes.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • Small, focused change with measured benefit.
  • Exact output and compatibility considered.
  • Self-reviewed; targeted tests, full typecheck and changed-file lint pass.
  • Full lint, full test suite and build: CI coverage pending.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: eda49d7e-cfb9-4a94-ac29-baf0ec8bce4d

📥 Commits

Reviewing files that changed from the base of the PR and between 20ab995 and 9a2e71f.

📒 Files selected for processing (3)
  • config/scripts/check-job-log-tail-benchmark.mjs
  • src/shared/check-job-log-tail-slice.test.ts
  • src/shared/check-job-log-tail-slice.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

sliceCheckLogTail now scans earlier error contexts from newest to oldest and stops when the configured earlier-line limit is reached. Tests cover scan limits, overlapping windows, and boundary clipping. A benchmark script builds the current implementation, compares it with a baseline across randomized and shaped inputs, and reports timing results.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 9a2e7

The optimized log-tail extraction preserves existing excerpts while reducing work for dense logs; no actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary performance change: bounding earlier error-context selection.
Description check ✅ Passed The description is detailed, focused, and covers the change, rationale, linked issue, testing, visual proof, review notes, and checklist. It also states that full lint, test, and build checks remain p…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — behavior-preserving perf refactor of earlier-error context selection, plus a benchmark and regression tests.

  • Backward scan with early stop — collectEarlierErrorLineIndexes now walks earlier lines from recentStart - 1 down to 0 and fills each error's context window from contextEnd downward, breaking once the Set hits PR_CHECK_LOG_TAIL_MAX_EARLIER_LINES (30).
  • Cap moved into collection — the earlierIndexes.slice(-30) at the call site is dropped; the 30-line cap is enforced while collecting.
  • New benchmark script — config/scripts/check-job-log-tail-benchmark.mjs loads the baseline via stdin with esbuild, asserts a 2000-case differential, and reports counterbalanced timings.
  • New tests — early-stop scan bound, overlapping-window dedup with oldest-window clipping, and first-line/boundary clipping.

The equivalence claim holds: since descending error positions have non-increasing contextEnd, any index an earlier error could contribute above the running minimum is already covered by a previously added contiguous window, so the first 30 collected indexes are exactly the 30 largest unique indexes the old sort().slice(-30) produced. I confirmed this three ways — pnpm test src/shared/check-job-log-tail-slice.test.ts (7 passed), pnpm tc (clean), and an independent 200,000-case differential fuzz against the baseline (all match) — alongside re-running the PR's own 2000-case differential benchmark. The measured speedups reproduce (dense 19.2 → 3.9 ms, spaced 24.3 → 4.2 ms on 100k lines).

No wire, path, platform, or shared-contract change — the same pure function serves the GitHub and GitLab paths.

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor

Closing as a functional duplicate of #20211. Both make the same optimization to src/shared/check-job-log-tail-slice.ts — reverse the earlier-context scan to newest-first and stop at PR_CHECK_LOG_TAIL_MAX_EARLIER_LINES instead of collecting everything and slicing .slice(-30). #20211 does it in +31/-2 versus +161/-5 here, and the two conflict, so only one can land. Keeping #20211.

@nwparker nwparker closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants