Skip to content

fix(logs): find active log file across date boundaries#42904

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
ethanclaw:fix/logs-follow-date
Apr 29, 2026
Merged

fix(logs): find active log file across date boundaries#42904
vincentkoc merged 2 commits into
openclaw:mainfrom
ethanclaw:fix/logs-follow-date

Conversation

@ethanclaw

Copy link
Copy Markdown
Contributor

Summary

  • Fixes issue where openclaw channels logs could not find logs when gateway runs across midnight
  • When today's log file doesn't exist, fall back to the most recently modified log file

Test plan

  • pnpm build 成功

Fixes #42875

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations size: S labels Mar 11, 2026

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

Copy link
Copy Markdown

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: 1b9bf1e8d0

ℹ️ 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 src/commands/channels/logs.ts Outdated
Comment thread src/commands/channels/logs.ts Outdated
@greptile-apps

greptile-apps Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a real-world bug where openclaw channels logs fails to find the active log file when the gateway process runs across midnight (the log file for "today" doesn't exist yet, but yesterday's file is still being written to). The fix in src/commands/channels/logs.ts adds a findActiveLogFile() helper that falls back to the most recently modified log file in the log directory.

Key issue found:

  • .slice(0, 10) ordering bug in findActiveLogFile() — The slice is applied to the filesystem-order list before mtime sorting. If log pruning is disabled and more than 10 log files accumulate, the function could return an older file instead of the most recently modified one. The slice should be removed (pruning normally keeps ≤2 files) or applied after sorting.

The PR also bundles a secondary feature in src/cli/cron-cli/register.cron-add.ts: a UX warning when cron add --message is invoked without --agent, along with three new tests.

Confidence Score: 3/5

  • Safe to merge for the common case, but contains a latent ordering bug in candidate selection.
  • The core fix correctly handles the midnight-crossing scenario where today's log file doesn't exist yet. However, the slice-before-sort pattern in findActiveLogFile() is a latent bug: if log pruning ever fails or is disabled and more than 10 log files accumulate, the function could silently return a stale file instead of the most recently modified one. Under normal conditions (pruning keeps ≤2 files), this bug doesn't manifest.
  • src/commands/channels/logs.ts — specifically the findActiveLogFile() function's candidate selection (lines 58–60). The .slice(0, 10) should be removed or applied after sorting by mtime.

Last reviewed commit: 1b9bf1e

Comment thread src/commands/channels/logs.ts Outdated
@ethanclaw ethanclaw force-pushed the fix/logs-follow-date branch from 1b9bf1e to 2ec87cc Compare March 11, 2026 07:46
@ethanclaw

Copy link
Copy Markdown
Contributor Author

Thank you for the review @chatgpt-codex-connector @greptile-apps! I've addressed both concerns:

  1. Use configured log directory - Fixed! Now uses path.dirname(getResolvedLoggerSettings().file) instead of DEFAULT_LOG_DIR for fallback lookup.

  2. Remove slice before sort - Fixed! Removed the .slice(0, 10) limit so all log files are considered before sorting by mtime.

Build passes. Let me know if there are any other concerns!

@greptile-apps

greptile-apps Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Perfect! Both concerns are addressed:

Configured log directory - Now correctly uses path.dirname(configuredFile)
All files considered - Removed the slice, now all log files are sorted by mtime

The implementation looks good. Nice work!

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ 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".

@ethanclaw ethanclaw force-pushed the fix/logs-follow-date branch from 2ec87cc to d1af73d Compare March 11, 2026 09:44
@ethanclaw

Copy link
Copy Markdown
Contributor Author

Thank you for the review @greptile-apps! Fixed:

  1. Removed unused import - Removed DEFAULT_LOG_DIR import
  2. Fixed misleading fallback - Changed to direct array access since filesWithMtime[0] is guaranteed to exist (due to the early return guard)

All tests pass.

@greptile-apps

greptile-apps Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Looks great! Both fixes are solid:

  1. Unused import removed - DEFAULT_LOG_DIR is no longer imported
  2. Direct array access - filesWithMtime[0] is safe because of the early return when logFiles.length === 0

The logic is clean and the guard ensures we'll never hit an undefined access. Nice work! 🎯

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

Copy link
Copy Markdown

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: d1af73d68f

ℹ️ 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 src/commands/channels/logs.ts Outdated
@ethanclaw ethanclaw force-pushed the fix/logs-follow-date branch from d1af73d to a3c7715 Compare March 12, 2026 01:52
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 27, 2026
@clawsweeper

clawsweeper Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

Keep this PR open. Current main still makes openclaw channels logs read the exact configured log file and return no lines when that dated file is missing, while the shared rolling-log fallback is only used by logs.tail. The latest PR context is a focused fix candidate with tests and no obvious supply-chain-sensitive file changes.

Best possible solution:

Keep this PR open for maintainer review. The best path is to land the narrow branch if CI remains green: export the shared rolling-log resolver, call it from channelsLogsCommand, keep regression coverage for rolling fallback and custom non-rolling paths, and preserve the contributor credits. If maintainers do not want channel-log fallback parity with logs.tail, that should be an explicit product decision rather than automated cleanup.

What I checked:

  • Current channel logs reads the exact configured file: channelsLogsCommand assigns file = getResolvedLoggerSettings().file and passes that path directly to readTailLines; it does not call the shared rolling-log resolver. (src/commands/channels/logs.ts:106, 79159f11f695)
  • Missing channel log file returns empty lines: readTailLines catches a missing fs.stat(file) and returns [], so a missing current-day rolling file produces no channel log output on current main. (src/commands/channels/logs.ts:63, 79159f11f695)
  • Shared rolling fallback exists only on generic log tailing: resolveLogFile falls back from a missing rolling openclaw-YYYY-MM-DD.log to the newest matching file, but it is private and only called by readConfiguredLogTail. (src/logging/log-tail.ts:26, 79159f11f695)
  • Generic logs.tail has fallback regression coverage: The logs.tail test sets the configured file to a missing current-day rolling log and expects the handler to return the newer existing rolling log file. (src/gateway/server-methods/server-methods.test.ts:1910, 79159f11f695)
  • Channel logs tests lack this regression on main: The current channel-log test covers plugin-channel filtering, but no missing rolling-file fallback case is present on main. (src/commands/channels.logs.test.ts:60, 79159f11f695)
  • Docs identify both affected surfaces: The logging docs describe the default rolling log path and separately point users to openclaw channels logs --channel whatsapp for channel-only logs, matching the PR’s channel-log surface. Public docs: docs/logging.md. (docs/logging.md:20, 79159f11f695)

Likely related people:

  • vincentkoc: The provided timeline shows Vincent Koc force-pushed the latest narrow repair commits to this branch, temporarily labeled it for human review/merge readiness, assigned himself, and commented with validation for pnpm check:changed plus the targeted channel-log Vitest command. (role: recent maintainer and likely follow-up owner; confidence: high; commits: ee87397a4323, f6c8e1b6cfd3; files: src/commands/channels/logs.ts, src/logging/log-tail.ts, src/commands/channels.logs.test.ts)
  • Peter Steinberger steipete@gmail.com: Local current-main blame and git show --stat attribute the relevant channel-log command, shared log-tail resolver, and current channel-log test file to grafted commit a0f0c964fd40afc57b832fb313f4275c7406f360. This is weaker routing evidence because the commit is a broad snapshot with an unrelated subject. (role: current-main snapshot/blame owner; confidence: low; commits: a0f0c964fd40; files: src/commands/channels/logs.ts, src/logging/log-tail.ts, src/commands/channels.logs.test.ts)

Remaining risk / open question:

  • Closing this PR now would leave openclaw channels logs without the missing rolling-file fallback that generic logs.tail already has.
  • This read-only review did not execute tests; the provided maintainer comment reports targeted validation, but normal maintainer and CI review are still needed before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 79159f11f695.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 28, 2026
@vincentkoc vincentkoc force-pushed the fix/logs-follow-date branch from a3c7715 to ee87397 Compare April 28, 2026 18:53
@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #42904
Validation: pnpm check:changed; pnpm -s vitest run src/commands/channels/logs.test.ts
Contributor credit is preserved in the branch history and PR context.

@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Apr 28, 2026
@vincentkoc vincentkoc added clawsweeper Tracked by ClawSweeper automation and removed clownfish:merge-ready labels Apr 28, 2026
@vincentkoc vincentkoc self-assigned this Apr 29, 2026
@vincentkoc vincentkoc force-pushed the fix/logs-follow-date branch 2 times, most recently from c76265d to f6c8e1b Compare April 29, 2026 01:58
ethanclaw and others added 2 commits April 28, 2026 19:05
Fixes openclaw#42875

When gateway runs across midnight, openclaw channels logs was looking
for today's log file instead of the active one. This change makes
the CLI find the most recently modified log file as a fallback.

(cherry picked from commit fba6b88e8644365360f82802cbe25039a091409d)
(cherry picked from commit ee87397a4323f04fdd37a2fc136de02e648a92d5)
@vincentkoc vincentkoc force-pushed the fix/logs-follow-date branch from f6c8e1b to 2da6c56 Compare April 29, 2026 02:07
@vincentkoc vincentkoc merged commit 492e2a3 into openclaw:main Apr 29, 2026
69 checks passed
YoshiaKefasu added a commit to YoshiaKefasu/DennouAibou that referenced this pull request Apr 30, 2026
Previously, buildLogger() resolved the rolling log file path once at
logger construction time. When midnight passed, all writes continued
hitting the previous day's file despite the new date. Upstream
openclaw#42904 introduced resolveActiveLogFile() for this.

Fix: add resolveActiveLogFile() that re-derives the date-specific path
every write. On date boundary detection, the transport re-initializes
its file pointer. Also fix resolveLogFile() in log-tail.ts to prefer
the latest-mtime rolling file regardless of the original config path.

Test: new 'writes rolling logs to the current date after midnight' case.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* fix(logs): find active log file across date boundaries

Fixes openclaw#42875

When gateway runs across midnight, openclaw channels logs was looking
for today's log file instead of the active one. This change makes
the CLI find the most recently modified log file as a fallback.

(cherry picked from commit fba6b88e8644365360f82802cbe25039a091409d)

* fix(channels): resolve active log file for channel logs

(cherry picked from commit ee87397a4323f04fdd37a2fc136de02e648a92d5)

---------

Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix(logs): find active log file across date boundaries

Fixes openclaw#42875

When gateway runs across midnight, openclaw channels logs was looking
for today's log file instead of the active one. This change makes
the CLI find the most recently modified log file as a fallback.

(cherry picked from commit fba6b88e8644365360f82802cbe25039a091409d)

* fix(channels): resolve active log file for channel logs

(cherry picked from commit ee87397a4323f04fdd37a2fc136de02e648a92d5)

---------

Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix(logs): find active log file across date boundaries

Fixes openclaw#42875

When gateway runs across midnight, openclaw channels logs was looking
for today's log file instead of the active one. This change makes
the CLI find the most recently modified log file as a fallback.

(cherry picked from commit fba6b88e8644365360f82802cbe25039a091409d)

* fix(channels): resolve active log file for channel logs

(cherry picked from commit ee87397a4323f04fdd37a2fc136de02e648a92d5)

---------

Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix(logs): find active log file across date boundaries

Fixes openclaw#42875

When gateway runs across midnight, openclaw channels logs was looking
for today's log file instead of the active one. This change makes
the CLI find the most recently modified log file as a fallback.

(cherry picked from commit fba6b88e8644365360f82802cbe25039a091409d)

* fix(channels): resolve active log file for channel logs

(cherry picked from commit ee87397a4323f04fdd37a2fc136de02e648a92d5)

---------

Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper Tracked by ClawSweeper automation commands Command implementations size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openclaw logs --follow Cannot View Gateway Real-time Logs

2 participants