Skip to content

Conversation

@BioPhoton
Copy link
Collaborator

@BioPhoton BioPhoton commented Jan 9, 2026

Related: #1197

This PR includes:

  • types for source sink flows
  • wal.ts - general WriteAheadLog and sharded WAL inc format and filenames
  • wal-trace-json.ts traceEvent specific login for a WAL
  • profiler constants to control WAL leader
  • moved trace utils into profiler

Note

This PR addresses a comment related to logging.
It could also be used as file output for the logger

Warning

All filesystem operations in WAL—and indirectly in the profiler—are synchronous by design.
The eslint rules are disables over file name pattern

Why synchronous fs is used for WAL code?

  • Profilers are side-channels, not business logic
  • Data must never be lost, reordered, or partially written
  • process.on('exit') cannot safely run async I/O
  • Sync writes guarantee ordering + durability
  • Profiler I/O volume is small → overhead is negligible
  • Crash-safety > throughput

@nx-cloud
Copy link

nx-cloud bot commented Jan 9, 2026

View your CI Pipeline Execution ↗ for commit a3641d3

Command Status Duration Result
nx run ci:code-pushup -- merge-diffs --files=/h... ✅ Succeeded 5s View ↗
nx run-many --targets=code-pushup --parallel=fa... ✅ Succeeded 1m 28s View ↗
nx run-many --targets=code-pushup --parallel=fa... ✅ Succeeded 12m 53s View ↗
nx run-many -t unit-test,int-test ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-18 23:17:23 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 9, 2026

Open in StackBlitz

@code-pushup/ci

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/ci@1210

@code-pushup/cli

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/cli@1210

@code-pushup/core

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/core@1210

@code-pushup/create-cli

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/create-cli@1210

@code-pushup/models

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/models@1210

@code-pushup/nx-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/nx-plugin@1210

@code-pushup/axe-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/axe-plugin@1210

@code-pushup/coverage-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/coverage-plugin@1210

@code-pushup/eslint-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/eslint-plugin@1210

@code-pushup/js-packages-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/js-packages-plugin@1210

@code-pushup/jsdocs-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/jsdocs-plugin@1210

@code-pushup/lighthouse-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/lighthouse-plugin@1210

@code-pushup/typescript-plugin

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/typescript-plugin@1210

@code-pushup/utils

npm i https://pkg.pr.new/code-pushup/cli/@code-pushup/utils@1210

commit: a3641d3

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Code PushUp

🤨 Code PushUp report has both improvements and regressions – compared current commit f5a0e21 with previous commit 270b474.

🕵️ See full comparison in Code PushUp portal 🔍

🏷️ Categories

🏷️ Category ⭐ Previous score ⭐ Current score 🔄 Score change
Documentation 🔴 42 🔴 46 ↑ +3.5
Code coverage 🟢 93 🟢 93 ↑ +0.2
Bug prevention 🟡 75 🟡 75 ↓ −0.1
Axe Accessibility 🟡 88 🟡 88 ↓ −0.1
Code style 🟢 99 🟢 99
Security 🟡 51 🟡 51
Updates 🟡 78 🟡 78
Type Safety 🟡 67 🟡 67
Miscellaneous 🟡 67 🟡 67
Performance 🔴 37 🔴 37
Accessibility 🟢 92 🟢 92
Best Practices 🟢 100 🟢 100
SEO 🟢 92 🟢 92
👍 2 groups improved, 👍 12 audits improved, 👎 1 audit regressed, 14 audits changed without impacting score

🗃️ Groups

🔌 Plugin 🗃️ Group ⭐ Previous score ⭐ Current score 🔄 Score change
JSDocs coverage Documentation coverage 🔴 42 🔴 46 ↑ +3.5
Code coverage Code coverage metrics 🟢 93 🟢 93 ↑ +0.2

32 other groups are unchanged.

🛡️ Audits

🔌 Plugin 🛡️ Audit 📏 Previous value 📏 Current value 🔄 Value change
JSDocs coverage Classes coverage 🟥 6 undocumented classes 🟨 6 undocumented classes  +0 %
JSDocs coverage Properties coverage 🟥 30 undocumented properties 🟥 40 undocumented properties ↑ +33.3 %
Lighthouse Speed Index 🟥 6.0 s 🟨 5.7 s ↓ −5 %
Lighthouse Time to Interactive 🟥 13.0 s 🟥 12.5 s ↓ −4.2 %
Lighthouse Total Blocking Time 🟥 1,890 ms 🟥 2,080 ms ↑ +10.5 %
JSDocs coverage Functions coverage 🟥 577 undocumented functions 🟥 580 undocumented functions ↑ +0.5 %
JSDocs coverage Types coverage 🟥 268 undocumented types 🟥 258 undocumented types ↓ −3.7 %
JSDocs coverage Variables coverage 🟥 268 undocumented variables 🟥 276 undocumented variables ↑ +3 %
Lighthouse First Contentful Paint 🟥 3.1 s 🟥 3.1 s ↓ −0.3 %
JSDocs coverage Methods coverage 🟨 13 undocumented methods 🟨 15 undocumented methods ↑ +15.4 %
Code coverage Function coverage 🟩 94.4 % 🟩 94.6 % ↑ +0.3 %
Code coverage Line coverage 🟩 92.7 % 🟩 92.9 % ↑ +0.2 %
Code coverage Branch coverage 🟨 89 % 🟨 89.2 % ↑ +0.3 %
Lighthouse Avoids enormous network payloads 🟩 Total size was 2,104 KiB 🟩 Total size was 2,102 KiB ↓ −0.1 %
Lighthouse Largest Contentful Paint 🟥 11.5 s 🟥 10.6 s ↓ −7.9 %
Lighthouse Uses efficient cache policy on static assets 🟨 31 resources found 🟨 31 resources found ↑ +0.1 %
Lighthouse Metrics 🟩 100% 🟩 100% ↓ −4.2 %
Lighthouse Minimizes main-thread work 🟥 9.2 s 🟥 8.8 s ↓ −4.3 %
Lighthouse Reduce unused CSS 🟥 Potential savings of 95 KiB 🟥 Potential savings of 95 KiB ↓ −49.2 %
Lighthouse Reduce unused JavaScript 🟥 Potential savings of 224 KiB 🟥 Potential savings of 225 KiB ↓ −21.2 %
Lighthouse Server Backend Latencies 🟩 1,200 ms 🟩 930 ms ↓ −22.4 %
Lighthouse Remove duplicate modules in JavaScript bundles 🟥 Potential savings of 93 KiB 🟥 Potential savings of 93 KiB ↓ −32.6 %
Lighthouse Initial server response time was short 🟩 Root document took 540 ms 🟩 Root document took 390 ms ↓ −27.9 %
Lighthouse Max Potential First Input Delay 🟥 980 ms 🟥 900 ms ↓ −8.2 %
Lighthouse JavaScript execution time 🟥 4.3 s 🟥 4.3 s ↑ +0.7 %
TypeScript Semantic errors 🟥 25 errors 🟥 26 errors ↑ +4 %
Lighthouse Network Round Trip Times 🟩 10 ms 🟩 10 ms ↓ −11.1 %

652 other audits are unchanged.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2026

Code PushUp

🥳 Code PushUp report has improved – compared current commit f5a0e21 with previous commit 270b474.

💼 Project utils

🥳 Code PushUp report has improved.

🕵️ See full comparison in Code PushUp portal 🔍

🏷️ Category ⭐ Previous score ⭐ Current score 🔄 Score change
Documentation 🔴 45 🟡 51 ↑ +5.4
Code coverage 🟢 95 🟢 95 ↑ +0.4

4 other categories are unchanged.

👍 2 groups improved, 👍 9 audits improved

🗃️ Groups

🔌 Plugin 🗃️ Group ⭐ Previous score ⭐ Current score 🔄 Score change
JSDocs coverage Documentation coverage 🔴 45 🟡 51 ↑ +5.4
Code coverage Code coverage metrics 🟢 95 🟢 95 ↑ +0.4

13 other groups are unchanged.

🛡️ Audits

🔌 Plugin 🛡️ Audit 📏 Previous value 📏 Current value 🔄 Value change
JSDocs coverage Classes coverage 🟨 3 undocumented classes 🟨 3 undocumented classes  +0 %
JSDocs coverage Properties coverage 🟥 27 undocumented properties 🟥 37 undocumented properties ↑ +37 %
JSDocs coverage Types coverage 🟥 66 undocumented types 🟨 56 undocumented types ↓ −15.2 %
JSDocs coverage Functions coverage 🟥 239 undocumented functions 🟥 242 undocumented functions ↑ +1.3 %
JSDocs coverage Variables coverage 🟥 49 undocumented variables 🟥 57 undocumented variables ↑ +16.3 %
JSDocs coverage Methods coverage 🟨 13 undocumented methods 🟨 15 undocumented methods ↑ +15.4 %
Code coverage Function coverage 🟩 96.2 % 🟩 96.6 % ↑ +0.5 %
Code coverage Branch coverage 🟩 91.8 % 🟩 92.2 % ↑ +0.4 %
Code coverage Line coverage 🟩 97.8 % 🟩 98 % ↑ +0.2 %

435 other audits are unchanged.


13 other projects are unchanged.

@BioPhoton BioPhoton marked this pull request as ready for review January 17, 2026 21:44
@BioPhoton BioPhoton requested a review from hanna-skryl January 17, 2026 21:44
@BioPhoton BioPhoton requested a review from matejchalk January 17, 2026 22:34
@BioPhoton BioPhoton changed the title feat(utils): add file sink classes feat(utils): add WriteAheadLog classes Jan 18, 2026
Copy link
Collaborator

@hanna-skryl hanna-skryl left a comment

Choose a reason for hiding this comment

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

The justification for sync file operations is well-reasoned 👍 I've added a few minor suggestions and comments.

SHARD_ID: /^\d{8}-\d{6}-\d{3}(?:\.\d+){3}$/,
} as const;

export function soratebleReadableDateString(timestampMs: string): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export function soratebleReadableDateString(timestampMs: string): string {
export function sortableReadableDateString(timestampMs: string): string {

Comment on lines +188 to +190
* @throws Error if recovery encounters decode errors
*/
repack(out = this.#file) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The JSDoc says that repack() throws if recovery encounters decode errors, but the implementation logs to the console and continues without throwing. Am I missing something?

import type { Codec } from '../src/lib/wal.js';

export class MockSink implements Sink<string, string> {
export class MockFileSink implements WriteAheadLogFile<string> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The TypeScript plugin reports an error here. Maybe MockFileSink should implement AppendableSink<string> instead?

Comment on lines +234 to +248
it('should create WAL format with custom directory', () => {
const format = traceEventWalFormat({ dir: '/custom/path' });

expect(format.baseName).toBe('trace');
expect(format.walExtension).toBe('.jsonl');
expect(format.finalExtension).toBe('.json');
});

it('should create WAL format with groupId', () => {
const format = traceEventWalFormat({ groupId: 'session-123' });

expect(format.baseName).toBe('trace');
expect(format.walExtension).toBe('.jsonl');
expect(format.finalExtension).toBe('.json');
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

traceEventWalFormat doesn't take any parameters 🤔

const recordsToWrite = hasInvalidEntries
? (r.records as T[])
: filterValidRecords(r.records);
fs.mkdirSync(path.dirname(out), { recursive: true });
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's an existing ensureDirectoryExists utility, but it's async. Maybe worth adding a sync variant (ensureDirectoryExistsSync) since this pattern repeats multiple times?

Comment on lines +455 to +457
* @throws Error if any shard contains decode errors
*/
finalize(opt?: Record<string, unknown>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question as in repack() - the JSDoc says it throws on decode errors, but there is no explicit Error.

format: Partial<WalFormat<T>>,
): WalFormat<T> {
const {
baseName = 'trace',
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a mismatch between the JSDoc and the actual implementation - should baseName default to 'trace' or Date.now().toString()?

/**
* Initialize the origin PID environment variable if not already set.
* This must be done as early as possible before any user code runs.
* Set's envVarName to the current process PID if not already defined.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Set's envVarName to the current process PID if not already defined.
* Sets envVarName to the current process ID if not already defined.

/**
* Pure helper function to recover records from WAL file content.
* @param content - Raw file content as string
* @param decode - function fo decoding records
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @param decode - function fo decoding records
* @param decode - function for decoding records

Comment on lines +365 to +368
* @param dir - The directory to store the shard file
* @param format - The WalFormat to use for the shard file
* @param groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
* @param shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @param dir - The directory to store the shard file
* @param format - The WalFormat to use for the shard file
* @param groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
* @param shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)
* @param opt.dir - The directory to store the shard file
* @param opt.format - The WalFormat to use for the shard file
* @param opt.groupId - The human-readable group ID (yyyymmdd-hhmmss-ms format)
* @param opt.shardId - The human-readable shard ID (readable-timestamp.pid.threadId.count format)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants