Skip to content

fix(logs): preserve log tails across short reads#105066

Merged
steipete merged 5 commits into
openclaw:mainfrom
qingminglong:codex/fix-log-tail-short-reads
Jul 14, 2026
Merged

fix(logs): preserve log tails across short reads#105066
steipete merged 5 commits into
openclaw:mainfrom
qingminglong:codex/fix-log-tail-short-reads

Conversation

@qingminglong

@qingminglong qingminglong commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users reading OpenClaw logs through the CLI, Gateway logs method, or diagnostic support export could receive an incomplete log tail when the filesystem returns a short positional read for the bounded tail window.

Why This Change Was Made

The shared log-tail reader now fills the requested bounded read window before decoding and splitting lines, matching the existing gateway diagnostic tail-reader invariant. This stays local to log-tail read completeness and does not change cursor, reset, truncation, schema, CLI, or UI behavior.

User Impact

Log views and support bundles now preserve the recent log lines available within the configured byte budget even when the underlying file read completes in smaller chunks.

Evidence

  • Claim proved at current head 024c90fd60070ba0cf2ecef21c1b9d0e07c43c63: readConfiguredLogTail, Gateway logs.tail, and diagnostic support export preserve the complete tail while the underlying real log-file reads repeatedly return only four bytes.
  • Command/action proof: node --import tsx --input-type=module - wrote a real temporary JSONL log file, wrapped fs.promises.open only for that file to force four-byte positional reads, imported the current branch modules, called readConfiguredLogTail, called Gateway logsHandlers["logs.tail"], wrote a diagnostic support zip with writeDiagnosticSupportExport, and inspected logs/openclaw-sanitized.jsonl from the zip with jszip.
{
  "head": "024c90fd60070ba0cf2ecef21c1b9d0e07c43c63",
  "fileBytes": 254,
  "readStats": {
    "totalReads": 192,
    "shortReads": 189,
    "examples": [
      { "requested": 254, "actual": 4, "position": 0 },
      { "requested": 250, "actual": 4, "position": 4 },
      { "requested": 246, "actual": 4, "position": 8 }
    ]
  },
  "readConfiguredLogTail": {
    "lineCount": 4,
    "cursor": 254,
    "size": 254,
    "completeTail": true
  },
  "gatewayLogsTail": {
    "ok": true,
    "lineCount": 4,
    "cursor": 254,
    "size": 254,
    "completeTail": true
  },
  "diagnosticSupportExport": {
    "files": [
      "diagnostics.json",
      "logs/openclaw-sanitized.jsonl",
      "manifest.json",
      "summary.md"
    ],
    "sanitizedLogMessages": [
      { "omitted": "unparsed", "bytes": 11 },
      "proof-short-read-one",
      "proof-short-read-two",
      "proof-short-read-three"
    ],
    "completeTail": true
  }
}
  • Focused regression after merge refresh: node scripts/run-vitest.mjs src/logging/log-tail.test.ts passed with 1 file and 2 tests.
  • Diff hygiene after merge refresh: git diff --check upstream/main...HEAD passed.
  • PR diff after merge refresh remains limited to src/logging/log-tail.ts and src/logging/log-tail.test.ts.

AI-assisted: yes. I reviewed the shared reader, Gateway logs handler, diagnostic support export path, focused test, current-head proof, and diff hygiene before refreshing this PR.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 12, 2026, 6:26 AM ET / 10:26 UTC.

Summary
The PR changes the shared log-tail reader to accumulate short positional reads and adds regression coverage using four-byte reads.

PR surface: Source +21, Tests +32. Total +53 across 2 files.

Reproducibility: yes. Current main performs one positional read, while the exact-head real-file proof forces repeated four-byte reads and demonstrates complete output from the shared reader, Gateway handler, and diagnostic export after the fix.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/logging/log-tail.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • [P2] No repair lane is needed; the exact head is clean and ready for routine maintainer merge handling.

Security
Cleared: The diff only changes bounded local file reads and regression tests, with no dependency, permission, secret, workflow, package, or supply-chain surface change.

Review details

Best possible solution:

Merge the exact-head shared-reader loop and real-file regression test after routine maintainer review; no alternate implementation, migration, or repair branch is needed.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main performs one positional read, while the exact-head real-file proof forces repeated four-byte reads and demonstrates complete output from the shared reader, Gateway handler, and diagnostic export after the fix.

Is this the best way to solve the issue?

Yes. Accumulating reads in the shared bounded reader is the narrowest owner-aligned fix, matches Node's EOF contract and existing repository helpers, and avoids duplicating behavior in each consumer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0350b87f069b.

Label changes

Label justifications:

  • P2: The PR fixes incomplete bounded log tails across CLI, Gateway, and support-export paths with limited blast radius and no outage or data-loss evidence.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Exact-head terminal proof uses a real temporary JSONL file and repeated four-byte reads to show the complete improved result through the shared reader, Gateway logs method, and diagnostic support export.
  • proof: sufficient: Contributor real behavior proof is sufficient. Exact-head terminal proof uses a real temporary JSONL file and repeated four-byte reads to show the complete improved result through the shared reader, Gateway logs method, and diagnostic support export.
Evidence reviewed

PR surface:

Source +21, Tests +32. Total +53 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 24 3 +21
Tests 1 32 0 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 56 3 +53

What I checked:

  • Current-main defect path: Current main allocates the bounded tail buffer, performs one positional read, and decodes only that call's bytesRead, so a valid short read produces an incomplete tail. (src/logging/log-tail.ts:127, 0350b87f069b)
  • Proposed implementation: The branch advances the buffer offset and file position until the requested window is filled or a zero-byte read indicates EOF. (src/logging/log-tail.ts:29, 024c90fd6007)
  • Focused regression coverage: The test wraps a real file handle with four-byte positional reads, verifies that all log lines survive, restores mocks, and removes its temporary directory. (src/logging/log-tail.test.ts:61, 024c90fd6007)
  • Shared owner boundary: The Gateway handler delegates cursor, byte-limit, source-selection, and tail-reading semantics to readConfiguredLogTail, making the shared reader the correct repair boundary. (src/gateway/server-methods/logs.ts:26, 0350b87f069b)
  • Sibling implementation precedent: The diagnostic tail reader already uses the same fill-until-EOF positional-read pattern, and the session file-range helper independently follows that invariant. (src/daemon/diagnostics.ts:19, 0350b87f069b)
  • Node dependency contract: Node 24 documentation states that zero bytes read indicates EOF for an unmodified file, supporting the loop's stop condition rather than treating the first short read as completion. (024c90fd6007)

Likely related people:

  • steipete: Commit 306fe84 moved Gateway log-tail behavior into the shared helper, and later work documented the logging helper surface. (role: introduced shared log-tail owner boundary and recent area contributor; confidence: high; commits: 306fe841f54b, add135d2381f; files: src/logging/log-tail.ts, src/gateway/server-methods/logs.ts)
  • eleqtrizit: Commit 8512941 added configured log-tail redaction behavior and the adjacent test suite. (role: major log-tail behavior contributor; confidence: high; commits: 851294126b30; files: src/logging/log-tail.ts, src/logging/log-tail.test.ts)
  • ethanclaw: Commit 492e2a3 maintained rolling-log resolution across date boundaries in the same helper and CLI path. (role: recent log-tail maintenance contributor; confidence: medium; commits: 492e2a3060db; files: src/logging/log-tail.ts, src/commands/channels/logs.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (3 earlier review cycles)
  • reviewed 2026-07-12T06:28:46.898Z sha 0ca736b :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-12T08:24:41.422Z sha 0ca736b :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-12T10:18:02.311Z sha 024c90f :: needs maintainer review before merge. :: none

@qingminglong

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@qingminglong

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 12, 2026
@qingminglong

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 12, 2026
@steipete steipete self-assigned this Jul 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui scripts Repository scripts commands Command implementations channel: qqbot extensions: qa-lab channel: reef Channel integration: reef size: XL and removed size: S labels Jul 14, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Jul 14, 2026
@steipete

Copy link
Copy Markdown
Contributor

Land-ready maintainer proof for exact head 7ffaa0b594e4ed80728aaf44767deb65a55c878a.

  • Improved the fix at the logging owner boundary: one complete positional-read helper now serves both configured log tails and channels logs, with forced short-read regressions for both callers.
  • Migrated the new test temp directories to the repo auto-cleanup tracker.
  • Exact-head Testbox: focused logging/channel tests passed 10/10 (run 29370281379).
  • pnpm check:changed passed for the four-file surface; format, core/test types, lint, architecture, dependency, and temp-dir checks passed.
  • Fresh exact-head autoreview: no actionable findings (0.98 confidence).
  • Exact-head hosted CI passed (CI 29370191262); Workflow Sanity, CodeQL, Critical Quality, and Opengrep also passed.

Known proof gaps: none for this bounded reliability fix.

@steipete
steipete merged commit c94da0d into openclaw:main Jul 14, 2026
115 of 119 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 15, 2026
* fix(logs): preserve log tails across short reads

* test(logging): track log-tail temp files

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants