Skip to content

fix(logging): preserve literal diagnostics export output paths - #181775

Merged
steipete merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/diagnostics-export-literal-output
Oct 27, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/diagnostics-export-literal-output

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Diagnostics export trims a quoted output path. An existing directory such as " quoted dir " can become a different file target, and an explicit filename can lose its trailing space.

User Impact

gateway diagnostics export --output and gateway stability --export --output honor literal nonblank, non-home output paths. Existing directories receive the generated ZIP; blank input still selects the default support directory.

Why This Change Was Made

The export writer uses the existing nonblank-string helper and sends non-home paths directly to path.resolve, avoiding a second trim inside the home-path helper. Existing ~ handling stays with that helper. Both CLI commands already share this writer.

The trailing-space directory regression now skips Windows, matching the file-path case: Windows normalizes those names. The CLI reference documents the destination behavior.

Thanks @wangmiao0668000666 for the fix and original CLI reproduction.

Evidence

  • Fresh base run: both literal-path regressions fail by selecting the trimmed destination; the blank-path control passes.
  • Fixed run: 21/21 tests pass in src/logging/diagnostic-support-export.test.ts with node scripts/run-vitest.mjs ... --maxWorkers=1. Wall time: 30.10s, dominated by transform startup (94%); actual test work is under one second. The tests create real ZIP files and assert their filesystem destinations.
  • Typed oxlint, oxfmt, and git diff --check pass.
  • Production +3/-5 (net -2); tests +36/-0; docs +1/-0 against main. The existing path owner is retained without new options or expansion rules.
  • Reused contributor source-CLI proof on the same production edit: gateway diagnostics export --output "…/ quoted dir " writes inside that directory after the fix; the base writes the trimmed sibling file. A normal-file control passes.
  • No fresh packaged CLI run was performed on the loaded host; the focused real-filesystem proof and existing CLI trace cover the changed owner, while exact-head PR CI supplies broad proof.

Independent P0–P2 review of the final staged candidate: no actionable findings. The prior index-only Windows test finding is resolved.

Retained contributor runtime evidence

The following is the contributor’s recorded trace, retained for inspection. It was not rerun on the latest merged head; the production path change is unchanged, and the fresh regression results above cover the integrated source.

Inspectable RED -> GREEN terminal trace

Unit RED (base 571040c3104 = old owner + new regression tests), Docker
node scripts/run-vitest.mjs run src/logging/diagnostic-support-export.test.ts --maxWorkers=1:

× diagnostic support export > preserves a quoted output directory name instead of trimming its whitespace
→ AssertionError: expected '/tmp/oc-vt-9jSLrD/openclaw-support-ex…' to be '/tmp/oc-vt-9jSLrD/openclaw-support-ex…'
× diagnostic support export > preserves leading and trailing whitespace in an explicit output file path
→ AssertionError: expected '/tmp/oc-vt-9jSLrD/openclaw-support-ex…' to be '/tmp/oc-vt-9jSLrD/openclaw-support-ex…'
✓ diagnostic support export > treats a blank output path as omitted and writes to the default support directory
Tests  2 failed | 16 passed (18)   [test] FAILED (exit 1)

Unit GREEN (candidate = base + this PR, fresh compile after cache clear, same command):

✓ diagnostic support export > preserves a quoted output directory name instead of trimming its whitespace
✓ diagnostic support export > preserves leading and trailing whitespace in an explicit output file path
✓ diagnostic support export > treats a blank output path as omitted and writes to the default support directory
Tests  18 passed (18)   [test] passed 1 Vitest shard in 95.82s

Real-CLI RED (base, Docker, HOME=/tmp/oc-diag-proof-state,
OPENCLAW_STATE_DIR=/tmp/oc-diag-proof-state,
OPENCLAW_CONFIG_PATH=/tmp/oc-diag-proof-state/openclaw.json,
literal directory /tmp/oc-diag-proof-out/ quoted base pre-created):

$ node --import ./scripts/tsx.mjs src/entry.ts gateway diagnostics export --output "/tmp/oc-diag-proof-out/ quoted base " --json
CLI-EXIT:0
---OUTDIR---
-rw-------. 1 root root 4295 Oct 23 17:07  quoted base        ← ZIP written to the TRIMMED FILE
drwxr-xr-x. 2 root root    6 Oct 23 17:07  quoted base        ← literal directory EMPTY

Real-CLI GREEN (candidate, same isolated env shape, literal directory
/tmp/oc-diag-proof-out/ quoted cand pre-created):

$ node --import ./scripts/tsx.mjs src/entry.ts gateway diagnostics export --output "/tmp/oc-diag-proof-out/ quoted cand " --json
LITERAL-EXIT:0
---LITERAL-DIR---
-rw-------. 1 root root 4294 Oct 23 17:09 openclaw-diagnostics-2026-10-23T17-08-40-718Z-30.zip
---ANY-TRIMMED-FILE---
(only the literal directory exists; no trimmed file created)

Legal control (candidate, normal path):

$ node --import ./scripts/tsx.mjs src/entry.ts gateway diagnostics export --output "/tmp/oc-diag-proof-out/normal/bundle.zip" --json
CONTROL-EXIT:0
---CONTROL---
-rw-------. 1 root root 4297 Oct 23 17:09 bundle.zip        ← exact path preserved

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves whitespace in explicit non-home diagnostics export paths and documents destination handling.

Example: Export diagnostics to the existing directory "/tmp/ quoted dir ".

  • Before: Writes a ZIP as the sibling file "/tmp/ quoted dir", leaving the requested directory empty.
  • After: Writes an automatically named ZIP inside "/tmp/ quoted dir ".

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, source-verified repair with relevant CLI evidence, distinct filesystem regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Recorded isolated Docker CLI runs exercise diagnostics export with an existing whitespace-bearing directory and a normal-file control; the candidate writes to the requested destinations, with the same production resolution change retained at the reviewed head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An explicitly quoted output destination can silently become a different filesystem target.
Reason: Literal CLI paths should identify the requested destination, and this repair adds no option, state, or competing owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete bug still present on current main with a focused shared-owner change; no actionable findings remain.

Priority: P2
Reviewed head: 836c7a8a9df02851dbb08973417a41ca0757c546

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway diagnostics and stability CLI commands pass output paths to a shared exporter, which collects sanitized diagnostics and publishes a private ZIP archive.

flowchart LR
A[Diagnostics export CLI] --> C[Shared support exporter]
B[Stability export CLI] --> C
C --> D[Resolve destination]
D --> E[Build sanitized ZIP]
E --> F[Atomic file publisher]
Loading

Technical review

Best possible solution:

Merge the focused shared-exporter fix after the existing exact-head checks pass.

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

Current-main source directly shows the trimming mechanism, and the contributor supplied matching CLI red/green output; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete fix: preserve nonblank input in the existing destination owner and avoid its second trimming path for non-home destinations.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 388b7e4523b6.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -2, Tests +36, Docs +1. Total +35 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 5 -2
Tests 1 36 0 +36
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 40 5 +35

Review metrics

Metric Value Why it matters
Production versus test changes Production +3/-5; tests +36/-0 Production logic shrinks while filesystem tests cover directory, filename, and blank-input behavior.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Explicit whitespace-bearing export destinations can select the wrong file, with limited impact on an advanced CLI workflow.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-23T17:31:42.779Z sha 637da49ccb1593e184bd82391a10ec3dae6c3972 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-24T18:04:00.098Z sha 6d581da :: needs maintainer review before merge. :: none

Reviewed October 26, 2026, 5:25 PM ET / 21:25 UTC (Revision 3).

Trim the configured path only to detect an omitted value, then resolve
non-home paths without resolveHomeRelativePath, which trims input, so
quoted directories and file names keep their literal whitespace.
Absolute paths must go through path.resolve for the same reason:
resolveHomeRelativePath trims internally, and its base-directory branch
is a no-op for absolute input.
@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/diagnostics-export-literal-output branch from 637da49 to 6d581da Compare October 24, 2026 17:40
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (a4bbfad4b). The branch was written against 637da49c, before #182130/#182379 inlined resolveOutputPath into writeDiagnosticSupportExport and dropped the injected now — that refactor, not the behaviour, was the whole conflict. The fix is re-expressed against the inlined code and the tests now use the suite's existing frozen clock (vi.useFakeTimers/vi.setSystemTime) instead of the removed now option.

Production change is 1 import + 2 lines:

  • const raw = configuredOutputPath?.trim() → readNonBlankString(configuredOutputPath) (shared helper; blank still falls back to the default support dir).
  • absolute paths resolve with path.resolve instead of resolveHomeRelativePath, because that helper also trims (src/infra/home-dir.ts:91) and would silently drop the whitespace this PR is about; ~ paths keep using it, and for absolute input its base-directory branch is a no-op, so only literal whitespace changes.

Verification on a remote runner (Node 24.22.1), same files on base and head so the diff is the only variable:

node_modules/.bin/vitest run --config vitest.config.ts src/logging/diagnostic-support-export.test.ts --maxWorkers=1
head:  Tests 23 passed (23)
base (production file reverted only):
       Tests 2 failed | 21 passed (23)
  ✗ preserves a quoted output directory name instead of trimming its whitespace
  ✗ preserves leading and trailing whitespace in an explicit output file path

The third case (blank output path → default support dir) passes on base as well — it is a regression guard for the readNonBlankString swap, not a red-on-base case, which is why only two go red. The trailing-space case is it.skipIf(process.platform === "win32"), with a comment, since Win32 cannot represent that filename.

@clawsweeper re-review — the standing verdict was authored against 637da49c, where resolveOutputPath still existed.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 26, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete
steipete merged commit bfb988f into openclaw:main Oct 27, 2026
139 of 141 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 Oct 27, 2026
…law#181775)

Preserve literal non-home diagnostics export destinations instead of trimming them through the home-path resolver. Retain blank defaults and existing home-path behavior; account for Windows trailing-space path semantics in the regression tests.

Validated with two red-on-base path regressions, 21 passing tests using real ZIP outputs, typed lint/format checks, independent review, and exact-head CI. Recorded CLI before/after evidence is in the PR.

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/diagnostics-export-literal-output branch October 28, 2026 06:29
RomneyDa added a commit that referenced this pull request Oct 28, 2026
Preserve literal non-home diagnostics export destinations instead of trimming them through the home-path resolver. Retain blank defaults and existing home-path behavior; account for Windows trailing-space path semantics in the regression tests.

Validated with two red-on-base path regressions, 21 passing tests using real ZIP outputs, typed lint/format checks, independent review, and exact-head CI. Recorded CLI before/after evidence is in the PR.

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>

(cherry picked from commit bfb988f)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit c0e8769c864cdba57be58c5cd8f83f9ca86bbc9a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation 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: XS 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