Skip to content

feat: introduce log directory size limit (unbounded disk usage prevention)#9234

Open
markolazic01 wants to merge 6 commits intoChainSafe:unstablefrom
markolazic01:feat/limit-log-dir-size
Open

feat: introduce log directory size limit (unbounded disk usage prevention)#9234
markolazic01 wants to merge 6 commits intoChainSafe:unstablefrom
markolazic01:feat/limit-log-dir-size

Conversation

@markolazic01
Copy link
Copy Markdown
Contributor

Motivation

Introduce a CLI flag that sets a log directory size limit, preventing unbounded disk usage during error storms (as seen in #7561 where daily logs reached 50-60GB).

Description

Adds a new CLI flag --logFileDirMaxSize (default 2048MB) that caps the total size of the log directory by computing a per-file size limit and passing it to winston-daily-rotate-file.
The per-file limit is calculated as logFileDirMaxSize / maxFiles, ensuring the total across all rotated files stays within the budget. maxFiles is forced to a minimum of 2 so there is always at least one backup file available for diagnosis when the current file rotates.
This feature only applies when daily rotation is enabled (the default). When rotation is disabled (--logFileDailyRotate 0), the size limit is not enforced because winston.transports.File does not properly support maxFiles — it either keeps a single file that grows indefinitely, or deletes the only file when it reaches the limit, leaving no logs to diagnose issues.
Tested using scripts that directly exercise the logger rotation and size limit behavior.

Closes #7561

AI Assistance Disclosure

Used Claude to ping-pong on a solution, discover potential edge-cases, for code validation.

@markolazic01 markolazic01 requested a review from a team as a code owner April 18, 2026 12:02
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 969a83db34

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/cli/src/util/logger.ts
handleExceptions: true,
maxFiles: opts.file.dailyRotate,
// ensure that there are always at least 2 files in rotation.
maxFiles: maxFileSizeInBytes != null ? Math.max(opts.file.dailyRotate || 2, 2) : opts.file.dailyRotate,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Align startup cleanup with forced two-file rotation

This change forces maxFiles to at least 2 when size limiting is enabled, but startup cleanup still prunes using the raw args.logFileDailyRotate value (cleanOldLogFiles in the same module). With --logFileDailyRotate 1 (and default size cap enabled), runtime rotation keeps 2 files while restart cleanup can delete anything older than 1 day, removing the backup file the new logic is explicitly trying to preserve.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This behavior seems reasonable to me, as it happens per user specific choice. Choosing --logFileDailyRotate 1 will still provide additional protection during the day, the deletion afterwards can be considered to be what the user wants.
Will keep as is but also remain open for further discussion.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new configuration option, logFileDirMaxSize, to limit the total size of rotated log files by calculating a per-file size limit. Feedback highlights that the total size limit might not be strictly enforced if a very high number of rotation files are configured due to the 1MB minimum per file. Additionally, a suggestion was made to simplify the logic that ensures at least two files are kept in rotation when a size limit is applied.

Comment thread packages/cli/src/util/logger.ts
Comment thread packages/logger/src/node.ts
@markolazic01
Copy link
Copy Markdown
Contributor Author

Resolved a lint error from previous action run

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.

Limit log file size or total log directory size

1 participant