Skip to content

test: time linear-time checks on the calling thread's CPU only - #1126

Merged
HugoRCD merged 2 commits into
v3from
fix/redact-linear-time-flake
Nov 17, 2026
Merged

HugoRCD merged 2 commits into
v3from
fix/redact-linear-time-flake

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Written by an AI agent on behalf of @HugoRCD. @HugoRCD has not reviewed it yet.

expectLinearTime now times each run with process.threadCpuUsage() instead of process.cpuUsage(). Process CPU time also counts V8's background threads (concurrent GC marking, JIT compilation). When that work lands on the long run alone, a linear input fails the 24x ratio. That is how "masks tokens in linear time on long attacker-controlled input" failed on #1121's Test (24) job and then passed on rerun.

Before and after

The CI failure on e5a2b385 (job). The short run measured close to local speed, and the long run about 4x slower:

FAIL   evlog  test/core/redact-integration.test.ts > credentials detected by value > masks tokens in linear time on long attacker-controlled input
AssertionError: a.a.a.a.a.a.a.a. (1.3ms / 0.0ms): expected 27.19803921568302 to be less than 24

The same input measured in this orb is linear: 40.2 µs at 8,163 characters and 302.7 µs at 65,038, a ratio of 7.5.

To reproduce it, a scratch test, not committed, runs expectLinearTime on a plain character scan, with three worker threads spinning only while the long input is timed:

Helper Results
v3 (process.cpuUsage()) linear (0.7ms / 0.0ms): expected 52.22989076464701 to be less than 24, linear (0.8ms / 0.0ms): expected 69.21068249258211 to be less than 24 (2 of 3 runs failed)
this branch (process.threadCpuUsage()) pass in 6 of 6 runs

Neither external CPU load (6 busy processes on 4 cores, 480 checks) nor a 442 MB heap failed the check on v3. Only CPU from threads inside the test process did.

New test in test/helpers/timers.test.ts, "ignores CPU time other threads use while the long input runs". It reports 4x process CPU during the long call. On v3's helper:

AssertionError: 32.8ms / 1.0ms: expected 32 to be less than 24
      Tests  1 failed | 8 skipped (9)

With this branch: Tests 9 passed (9).

Fallback for Node before 22.19

Added in 00543c8. engines allows Node 22.0, which has no process.threadCpuUsage(). There, cpuMs() uses process CPU time, as before this PR, instead of throwing:

const { user, system } = process.threadCpuUsage?.() ?? process.cpuUsage()

"times on process CPU time where Node has no threadCpuUsage" deletes process.threadCpuUsage and expects quadratic work timed on a mocked cpuUsage to be rejected. Without the fallback it fails with "process.threadCpuUsage is not a function". The 4 test files that use expectLinearTime pass with it (Tests 112 passed (112)), and lint is clean. The same change is in #1127 for main.

Validation

  • pnpm --filter evlog exec vitest run: 2674 passed
  • pnpm --filter evlog run lint and typecheck: pass
  • process.threadCpuUsage() exists on both CI versions (checked on Node 22.23.5 and 24.22.2). It was added in Node 22.19, so below that the helper falls back to process.cpuUsage() (see below).
  • I couldn't reproduce the original CI failure in this orb (4 full-suite runs, 0 failures), so this PR's own CI is the first run on real CI hardware.

Test-only, so no changeset.

ELI5

A test checks that hiding secrets in a long string doesn't get disproportionately slow. It timed the whole program, so when Node's background helpers happened to work during the long measurement, the long string looked slower than it was. The test now times only the thread doing the work.

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
evi Ready Ready Preview Nov 17, 2026 8:35pm UTC
evlog-telemetry Ready Ready Preview Nov 17, 2026 8:35pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
evlog-docs Skipped Skipped Nov 17, 2026 8:35pm UTC
evlog-render-lab Skipped Skipped Nov 17, 2026 8:35pm UTC
just-use-evlog Skipped Skipped Nov 17, 2026 8:35pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 843533a8-83c5-4672-8429-827d461b6070

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Risk score: Low (1/4)

Assessed at 00543c8 from the changed files and the title, by scripts/risk-score. A new push replaces this score.

  • On merge: nothing ships or deploys
  • 3 files changed (49 lines), 3 of them tests
Area Level Why
evlog core Low Tests only: test/README.md, helpers/timers.test.ts, helpers/timers.ts

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
@evlog/cli

npm i https://pkg.pr.new/@evlog/cli@1126

evlog

npm i https://pkg.pr.new/evlog@1126

@evlog/nuxthub

npm i https://pkg.pr.new/@evlog/nuxthub@1126

@evlog/signals

npm i https://pkg.pr.new/@evlog/signals@1126

@evlog/telemetry

npm i https://pkg.pr.new/@evlog/telemetry@1126

commit: 00543c8

@vercel
vercel Bot temporarily deployed to Preview – evlog-docs November 17, 2026 20:33 Inactive
@vercel
vercel Bot temporarily deployed to Preview – just-use-evlog November 17, 2026 20:33 Inactive
@vercel
vercel Bot temporarily deployed to Preview – evlog-render-lab November 17, 2026 20:33 Inactive
@HugoRCD
HugoRCD merged commit 62c54f1 into v3 Nov 17, 2026
28 checks passed
@HugoRCD
HugoRCD deleted the fix/redact-linear-time-flake branch November 17, 2026 20:54

This branch was successfully deployed

2 active and 3 inactive deployments
Preview – evlog-telemetry — 00543c8c Deployed Nov 17, 2026 by vercel[bot]
Preview – evi — 00543c8c Deployed Nov 17, 2026 by vercel[bot]
Preview – evlog-docs — 00543c8c Deployed Nov 17, 2026 by vercel[bot]
Preview – just-use-evlog — 00543c8c Deployed Nov 17, 2026 by vercel[bot]
Preview – evlog-render-lab — 00543c8c Deployed Nov 17, 2026 by vercel[bot]
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.

1 participant