Skip to content

perf: materialize only the requested recent plugin audit lines - #19498

Merged
nwparker merged 2 commits into
mainfrom
OrcaWin/perf-split-57-plugin-audit
Sep 9, 2026
Merged

nwparker merged 2 commits into
mainfrom
OrcaWin/perf-split-57-plugin-audit

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23

ELI5

Orca keeps an audit log of everything a plugin does through the gated host API — one record per line, in a file that can grow to 10 MB before it rotates.

When something asks for "the last 200 entries", the old code chopped the whole file into every single line it contained — potentially tens of thousands of strings — and then threw away all but the last 200.

Now it walks backwards from the end of the file, stopping as soon as it has the 200 lines it was asked for. Nothing else is ever built.

It reads back from real line breaks, so a record can never come back cut in half, and the entries you get are exactly the entries the old code returned — checked against the old code over 7,500 randomly generated log files containing blank lines, half-written final lines, Windows line endings, non-JSON junk and accented text.

What Changed / Why

  • 10,000 records: full line splitting eliminated for a 200-row window; unusual limits and malformed records retain parity

This PR contains only this focused change and its regression coverage. It targets main independently of the other desktop audit PRs. Measurements describe operation/allocation reductions, not end-to-end latency gains.

Linked Issue

User-requested desktop performance audit; no issue supplied.

Visual Proof

N/A — no visual design change. Behavior and performance invariants are checked by automated regression tests.

Testing

  • 2 tests across 1 suite(s) passed on this isolated branch on macOS.
  • Full pnpm tc passed on this branch.
  • Commit hooks passed: oxlint, React Doctor lint and formatting; git diff --cached --check passed.
  • All tests ran with ORCA_BACKGROUND_LAUNCH=1. No visible test window was launched.
  • Full build and Windows/Linux/live SSH validation remain for CI; host/provider contracts are preserved.

Test files:

  • src/main/plugins/plugin-audit-log-scaling.test.ts

Agent skill upstream boundary

  • No upstream skill-installer material copied or translated.

Checklist

  • Focused change with regression evidence.
  • Typecheck and pre-commit checks passed independently.
  • Cross-platform, folder-workspace and SSH ownership considered.
  • Full CI build and repository checks pass.

@nwparker
nwparker marked this pull request as ready for review September 8, 2026 04:53
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 8b525353-8ca4-4ba1-a67c-09f57a57ab41

📥 Commits

Reviewing files that changed from the base of the PR and between 6642053 and f092707.

📒 Files selected for processing (2)
  • src/main/plugins/plugin-audit-log-scaling.test.ts
  • src/main/plugins/plugin-audit-log.ts

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

  • recentAuditLines backward scan — replaces the full split('\n').filter().slice(-limit) with a reverse walk over lastIndexOf('\n') that stops once limit non-empty lines are collected, falling back verbatim to the old path for non-finite or < 1 limits.
  • Parity regression coverage — a differential oracle plus a 1500-seed randomized corpus (blank, whitespace, CRLF, torn-final-append, non-JSON, multi-byte, escaped-newline shapes) and a split-boundary test pin the new selection to exactly the old one.

I traced the algorithm against the old split/filter/slice behavior and confirmed exact equivalence: the reverse walk emits the same non-empty segments in the same order, the start < end guard correctly skips empty/trailing-newline segments, Math.trunc(limit) matches slice(-limit)'s truncation for fractional limits, and the < 1 / non-finite fallback is the old code verbatim. toReversed() is safe here — the module runs in the Electron main process (Node 20+) and is only type-imported from the Node-18 relay bundle path (plugin-host-methods.ts:6), so the relay toReversed ratchet is unaffected. Tests and oxlint both pass locally.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 069bdae into main Sep 9, 2026
97 of 109 checks passed
@nwparker
nwparker deleted the OrcaWin/perf-split-57-plugin-audit branch September 9, 2026 10:23
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