Skip to content

fix(plugin): cap the daemon start log that grows unbounded - #2644

Open
syzsunshine219 wants to merge 2 commits into
mainfrom
codex/maintainer-edit-pr-2608-20261119
Open

syzsunshine219 wants to merge 2 commits into
mainfrom
codex/maintainer-edit-pr-2608-20261119

Conversation

@syzsunshine219

Copy link
Copy Markdown
Collaborator

The source branch for the change proposed in #2608 now lives in MemTensor/MemOS, so repository writers can contribute fixes through the normal upstream branch permissions.

The code and commit authors are unchanged. This PR retains target branch main and exact source head 31d93c64a90185f222f70c21245431e3e62754bc from #2608.

Previous discussion and review remain in #2608. Review and checks must be re-evaluated for this replacement PR; no previous approval or new test result is asserted by this migration.

Previous PR description and implementation details

Restores the proposal from #2508 as an open PR against main; its former base branch, dev-v2.0.36, is no longer available. This proposal still needs its implementation revised before merging.

Source head: 31d93c64a90185f222f70c21245431e3e62754bc. No new source-code changes are introduced by restoring this proposal. Earlier discussion and evidence remain in #2508; validation claims in the original description refer to the earlier snapshot.

Outstanding review scope

主干daemon-start.log确有直接stdout重定向/追加路径,但旧PR只在安装或启动时截断保留历史,并不能限制长期运行daemon的当前日志增长;不能将其作为#2379运行期无界增长的完整修复直接恢复,应明确范围并补运行期轮转或单独拆成历史保留功能。


Original proposal

Description

daemon-start.log grows without bound for the whole life of an install. Both installers launch the bridge daemon with an uncapped shell redirect, and no truncation or rotation ever runs on it:

  • apps/memos-local-plugin/install.sh — the Hermes bridge daemon: nohup … > "${daemon_log}" 2>&1 & (launch now at install.sh:1389, the log path is logs/daemon-start.log)
  • apps/memos-local-plugin/install.sh:774 — the OpenClaw gateway fallback: nohup … >/tmp/openclaw-memos-gateway.log 2>&1 &
  • apps/memos-local-plugin/install.ps1:884 — Start-Process -RedirectStandardOutput $DaemonLog -RedirectStandardError $DaemonLogErr

Measured in the field (issue #2379): 59.3 MB / 287,895 lines on the oldest install, still growing and actively written. The plugin's rotating file logger never sees this stream — it is a plain process stdout/stderr redirect that bypasses the plugin entirely — so the cap has to live in the installers themselves.

Related Issue (Required): Fixes #2379 (ask 1 — rotate/cap daemon-start.log. Ask 2 — retryable fetch failed / transient=false — is covered by #2468.)

The fix

Add a size cap and route all three launch points through it:

  • rotate_oversized_log (install.sh:483) / Reset-OversizedLog (install.ps1:526) — called before every daemon launch: if the active start log exceeds the cap (default 10 MB, DAEMON_LOG_MAX_BYTES / -MaxBytes 10MB), roll it to a single .1 generation, so the active log + retained generation stay bounded at 2× the cap. An unparsable or unreadable size is a safe no-op (never blocks a daemon start).
  • The Hermes bridge redirect (install.sh:1387), the OpenClaw gateway fallback redirect (install.sh:773), and both Start-Process redirects in install.ps1 (daemon-start.log and daemon-start-err.log, install.ps1:880-881) all go through the cap.
  • Portability: BSD wc -c pads its output with spaces (GNU wc does not); the size is whitespace-stripped before the numeric guard so the check holds on both Linux and macOS — the test suite caught this on a real macOS host and the fix was verified there.

No new dependencies.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test
  • Test Script Or Test Steps (please provide)

New regression suite apps/memos-local-plugin/tests/unit/install/daemon-start-log-cap.test.ts (9 tests): rotation behavior extracted verbatim from install.sh (over-cap rolls to .1; at-cap, missing, and unreadable files are no-ops; exactly one generation kept; BSD-wc space padding handled) plus structural assertions that the Hermes bridge redirect, the OpenClaw gateway fallback redirect, and both install.ps1 Start-Process redirects route through the cap.

Red → green:

  • Red: 9/9 FAILED on the unfixed installers (git stash), then 9/9 PASSED after the fix — npx vitest run tests/unit/install/daemon-start-log-cap.test.ts
  • Related subset npx vitest run tests/unit/install: 74/75 — the 1 failure is a host-load flake (load avg 119): a different DSH fixture test exceeded its 10 s spawnSync timeout on each run, and it passes in isolation on both the clean checkout and with this change (an earlier subset run failed a different test than the later file run, which is what identified it as load flake, not a regression).
  • npm run lint (tsc -p tsconfig.json --noEmit) — clean
  • bash -n install.sh — clean

Re-verified on 2026-10-17 at this branch's HEAD (18f703d): npx vitest run tests/unit/install/daemon-start-log-cap.test.ts → 9 passed (9); lint clean; bash -n clean.

Note: the install.ps1 helper is covered by the structural assertions only — no PowerShell runtime on the test host, so it was not executed.

Checklist

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

AI assistance disclosure

This change was produced with AI assistance (agentic coding session by the account owner): code, tests, and this description were drafted by the AI and reviewed/verified by the account owner, who ran all the test, lint, and syntax checks above locally. No repo requirement specified a disclosure format; this statement is included for transparency.

Reviewer Checklist

akushonkamen and others added 2 commits October 17, 2026 08:14
install.sh launched the bridge daemon with a plain nohup redirect to
logs/daemon-start.log (and the OpenClaw gateway fallback to
/tmp/openclaw-memos-gateway.log) with no size cap or rotation anywhere,
so the file grew for the whole life of the install - 59 MB / 287,895
lines measured in the field. The plugin's rotating file logger never
sees this stream, so the cap has to live in the installers.

Add rotate_oversized_log (install.sh) / Reset-OversizedLog (install.ps1):
before every daemon launch, roll an over-cap start log to a single .1
generation, bounding the pair at 2x the 10 MB default cap. An unparsable
or unreadable size is a safe no-op; BSD wc's space-padded output is
stripped so the numeric guard holds on both Linux and macOS.

Tested: new tests/unit/install/daemon-start-log-cap.test.ts (9 tests):
rotation behavior extracted verbatim from install.sh (over-cap rolls to
.1; at-cap, missing, and unreadable files are no-ops; exactly one
generation kept) plus structural checks that the Hermes bridge redirect,
the OpenClaw gateway fallback redirect, and both install.ps1
Start-Process redirects route through the cap. Red: 9/9 failed on the
unfixed installers; green: 9/9 passed after the fix. tests/unit/install
subset: 74/75 - the one failure is a load flake on this host (load avg
119): a different DSH fixture test hangs past its 10s spawn timeout on
each run and passes in isolation on both the clean checkout and with
this change. npm run lint (tsc --noEmit): clean. The install.ps1 helper
is covered by structural assertions only (no PowerShell runtime on this
host to execute it).

Fixes #2379 (ask 1; ask 2 - retryable fetch failures - is covered by
#2468)
@syzsunshine219 syzsunshine219 added the area:plugin OpenClaw & Hermes label Nov 19, 2026
@Memtensor-AI Memtensor-AI added the status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 label Nov 19, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2644
Task: a1910e5de0857e09
Base: main
Head: codex/maintainer-edit-pr-2608-20261119
Head SHA: 31d93c64a90185f222f70c21245431e3e62754bc

🔍 OpenCodeReview found 3 issue(s) in this PR.


1. apps/memos-local-plugin/install.ps1 (L553-L554)

FileStream.Read is allowed to return fewer bytes than requested (short reads are reachable on network/synced volumes), and the count is ignored. A short read leaves the remainder of $Tail zero-filled, so the rotated .1 would end with a block of NUL bytes instead of the real log tail. Read in a loop and trim the buffer to what was actually read.

💡 Suggested Change

Before:

                $Tail = New-Object byte[] $MaxBytes
                [void]$Stream.Read($Tail, 0, $MaxBytes)

After:

                $Tail = New-Object byte[] $MaxBytes
                $Offset = 0
                while ($Offset -lt $MaxBytes) {
                    $Chunk = $Stream.Read($Tail, $Offset, [int]($MaxBytes - $Offset))
                    if ($Chunk -le 0) { break }
                    $Offset += $Chunk
                }
                if ($Offset -lt $Tail.Length) { [array]::Resize([ref]$Tail, $Offset) }

2. apps/memos-local-plugin/install.sh (L498)

Rotation failures here are completely silent (mv failure returns 0, wc failure returns 0, the tail/mv chain also swallows errors). The PowerShell counterpart reports the problem via Write-Warn, so on a locked/unwritable log the operator gets no hint that the cap was not applied and the file may keep growing. Emit a warn on the failure paths instead of a bare return 0.

💡 Suggested Change

Before:

  mv "${log_path}" "${log_path}.1" 2>/dev/null || return 0

After:

  mv "${log_path}" "${log_path}.1" 2>/dev/null || { warn "Could not rotate oversized log: ${log_path}"; return 0; }

3. apps/memos-local-plugin/install.sh (L480-L481)

The header comment is accurate, and it highlights the gap: since the launch redirect already truncates the active log, this code only preserves the tail of the previous session's log. The reported symptom (a single long-lived daemon session growing the active log to 59 MB) is unchanged — the file still grows without limit until the next install. Please either add an in-session bound (e.g. launch the daemon through a size-limited wrapper/rotatelogs, or a small periodic truncation watchdog) or state explicitly in the PR/issue that this only bounds retained history and the in-session growth is tracked separately.

Generated by cloud-assistant via Open Code Review.

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

Labels

area:plugin OpenClaw & Hermes status:in-progress Someone or AI is working on it | 人工或 AI 正在处理

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memos-local-plugin daemon log grows unbounded (no rotation); most of its volume is unretried http.exception errors

5 participants