Skip to content

chore(code): add chromium logs#1974

Merged
adboio merged 1 commit intomainfrom
05-01-chore_code_add_chromium_logs
May 1, 2026
Merged

chore(code): add chromium logs#1974
adboio merged 1 commit intomainfrom
05-01-chore_code_add_chromium_logs

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented May 1, 2026

Problem

https://posthog.slack.com/archives/C09G8Q32R6F/p1777640468457519

Changes

adds chromium logs to ~/.posthog-code/logs{-dev}/chromium.logand pushes a tail to posthog sometimes

How did you test this?

manually

Publish to changelog?

no

Copy link
Copy Markdown
Contributor Author

adboio commented May 1, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@adboio adboio requested a review from a team May 1, 2026 16:48
@adboio adboio marked this pull request as ready for review May 1, 2026 16:48
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
apps/code/src/main/utils/logger.ts:82-106
**Chromium log file grows unboundedly**

`chromium.log` has no size limit or rotation, unlike `main.log` which is capped at 10 MB with 3 archives. With `--log-level=0` (VERBOSE), Chromium is extremely chatty during normal operation and can produce several megabytes per session. Over time this will silently consume disk space with no cleanup mechanism. The same log directory already implements rotation for the main log — the same approach (or at least a `maxSize` guard that truncates the file at startup) should be applied here.

### Issue 2 of 3
apps/code/src/main/utils/logger.ts:93-94
**`readSync` return value not used to bound `toString`**

`readSync` returns the number of bytes actually read, which may be less than `length` (e.g. if the file was truncated between the `fstatSync` and `readSync` calls). Since `Buffer.alloc` zero-fills, any unread bytes at the end become null bytes in the UTF-8 string. Using `bytesRead` to slice the buffer is safer:

```suggestion
    const bytesRead = readSync(fd, buf, 0, length, size - length);
    return buf.subarray(0, bytesRead).toString("utf8");
```

### Issue 3 of 3
apps/code/src/main/bootstrap.ts:47-51
**Log directory path duplicated (OnceAndOnlyOnce)**

The same expression — `join(os.homedir(), ".posthog-code", isDev ? "logs-dev" : "logs")` — already appears verbatim in `logger.ts` as `LOG_DIR`. If the log directory ever changes, both sites need updating in sync. Consider extracting a shared helper (e.g. a small `utils/paths.ts` exporting `getLogDir(isDev)`) that both `bootstrap.ts` and `logger.ts` can import without creating a circular dependency.

Reviews (1): Last reviewed commit: "chore(code): add chromium logs" | Re-trigger Greptile

Comment on lines +82 to +106
export function readChromiumLogTail(): string | undefined {
const path = getChromiumLogFilePath();
if (!path) return undefined;

let fd: number | undefined;
try {
fd = openSync(path, "r");
const { size } = fstatSync(fd);
if (size === 0) return undefined;
const length = Math.min(size, CHROMIUM_LOG_TAIL_BYTES);
const buf = Buffer.alloc(length);
readSync(fd, buf, 0, length, size - length);
return buf.toString("utf8");
} catch {
return undefined;
} finally {
if (fd !== undefined) {
try {
closeSync(fd);
} catch {
// Best-effort close
}
}
}
}
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.

P1 Chromium log file grows unboundedly

chromium.log has no size limit or rotation, unlike main.log which is capped at 10 MB with 3 archives. With --log-level=0 (VERBOSE), Chromium is extremely chatty during normal operation and can produce several megabytes per session. Over time this will silently consume disk space with no cleanup mechanism. The same log directory already implements rotation for the main log — the same approach (or at least a maxSize guard that truncates the file at startup) should be applied here.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/main/utils/logger.ts
Line: 82-106

Comment:
**Chromium log file grows unboundedly**

`chromium.log` has no size limit or rotation, unlike `main.log` which is capped at 10 MB with 3 archives. With `--log-level=0` (VERBOSE), Chromium is extremely chatty during normal operation and can produce several megabytes per session. Over time this will silently consume disk space with no cleanup mechanism. The same log directory already implements rotation for the main log — the same approach (or at least a `maxSize` guard that truncates the file at startup) should be applied here.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +93 to +94
readSync(fd, buf, 0, length, size - length);
return buf.toString("utf8");
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.

P2 readSync return value not used to bound toString

readSync returns the number of bytes actually read, which may be less than length (e.g. if the file was truncated between the fstatSync and readSync calls). Since Buffer.alloc zero-fills, any unread bytes at the end become null bytes in the UTF-8 string. Using bytesRead to slice the buffer is safer:

Suggested change
readSync(fd, buf, 0, length, size - length);
return buf.toString("utf8");
const bytesRead = readSync(fd, buf, 0, length, size - length);
return buf.subarray(0, bytesRead).toString("utf8");
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/main/utils/logger.ts
Line: 93-94

Comment:
**`readSync` return value not used to bound `toString`**

`readSync` returns the number of bytes actually read, which may be less than `length` (e.g. if the file was truncated between the `fstatSync` and `readSync` calls). Since `Buffer.alloc` zero-fills, any unread bytes at the end become null bytes in the UTF-8 string. Using `bytesRead` to slice the buffer is safer:

```suggestion
    const bytesRead = readSync(fd, buf, 0, length, size - length);
    return buf.subarray(0, bytesRead).toString("utf8");
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +47 to +51
const chromiumLogDir = path.join(
os.homedir(),
".posthog-code",
isDev ? "logs-dev" : "logs",
);
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.

P2 Log directory path duplicated (OnceAndOnlyOnce)

The same expression — join(os.homedir(), ".posthog-code", isDev ? "logs-dev" : "logs") — already appears verbatim in logger.ts as LOG_DIR. If the log directory ever changes, both sites need updating in sync. Consider extracting a shared helper (e.g. a small utils/paths.ts exporting getLogDir(isDev)) that both bootstrap.ts and logger.ts can import without creating a circular dependency.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/main/bootstrap.ts
Line: 47-51

Comment:
**Log directory path duplicated (OnceAndOnlyOnce)**

The same expression — `join(os.homedir(), ".posthog-code", isDev ? "logs-dev" : "logs")` — already appears verbatim in `logger.ts` as `LOG_DIR`. If the log directory ever changes, both sites need updating in sync. Consider extracting a shared helper (e.g. a small `utils/paths.ts` exporting `getLogDir(isDev)`) that both `bootstrap.ts` and `logger.ts` can import without creating a circular dependency.

How can I resolve this? If you propose a fix, please make it concise.

@adboio adboio requested review from a team and removed request for a team May 1, 2026 17:34
@adboio adboio merged commit 2060c7c into main May 1, 2026
16 checks passed
@adboio adboio deleted the 05-01-chore_code_add_chromium_logs branch May 1, 2026 17:37
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