openclaw-windows-node icon indicating copy to clipboard operation
openclaw-windows-node copied to clipboard

feat: add sanitized diagnostics log bundle

Open christineyan4 opened this issue 6 months ago β€’ 9 comments

Summary

  • Add a sanitized diagnostics bundle export flow for the WinUI tray app, including generated debug summary, connection event timeline, tray log tails, structured diagnostics JSONL, crash log, and setup log tails.
  • Shift the privacy boundary toward source-side sanitization before logs/diagnostics are written or recorded, with DiagnosticsExportRedactor kept as defense-in-depth for older/raw export text.
  • Refactor export redaction away from a broad regex-only approach: parser-style handling now covers private keys, signed handshakes, DPAPI blobs, agent session keys, command-line secret options, sensitive key/value pairs, GUID-like IDs, and common URL/path/token cleanup.
  • Improve diagnostics preview/copy readability by decoding common JSON escape sequences like \u0022 and escaped CRLFs before final redaction, while keeping plain Windows paths stable and guarding control/backslash unicode escapes.
  • Add fail-closed sanitizer-timeout handling for log-tail section sanitization and final full-bundle sanitization so a timeout produces [REDACTED_SANITIZER_TIMEOUT] instead of aborting export.
  • Preserve the preview-before-copy/save full diagnostics flow and native Win32 Save dialog for the self-hosted WinUI app.
  • Add regression coverage for redaction safety, readability, timeout behavior, split-line/nested secrets, missing files, and diagnostics page copy/preview contracts.

Validation

  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --filter FullyQualifiedName~DiagnosticsExportRedactorTests
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --filter "FullyQualifiedName~DiagnosticsBundleBuilderTests|FullyQualifiedName~DiagnosticsPageContractTests"
  • .\build.ps1
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore
  • git diff --check
  • Hanselman-style adversarial review completed with Opus + Codex; follow-up fixes added for nested/double-escaped JSON secrets, conservative escape decoding for Windows paths, unicode control/backslash guards, deterministic escaped-CRLF decoding, and additional timeout/readability regression tests.

christineyan4 avatar May 27 '26 18:05 christineyan4

Codex review: needs real behavior proof before merge. Reviewed June 22, 2026, 3:04 PM ET / 19:04 UTC.

Summary The PR adds a WinUI diagnostics bundle preview/save flow with expanded log tails, log-time sanitization, persisted diagnostics normalization, native Save dialog support, localization updates, and regression tests.

Reproducibility: yes. for the review findings: PR-head source shows raw persisted tail inclusion, silent file rewrites, and unguarded setup-log enumeration, and the PR test asserts a split token remains in the bundle. I did not run tests because this was a read-only review.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 27 files, +2102/-192. The PR spans shared sanitization, setup logging, tray UI, Win32 save plumbing, diagnostics services, localization, and tests.
  • Included diagnostics sources: 6 source groups. Generated summaries, connection events, tray logs, JSONL, crash logs, and setup logs each need matching redaction guarantees.
  • Persisted rewrite entry points: 3 areas. Startup normalization, bundle-build normalization, and chat metadata constructor rewrites all affect upgrade safety before merge.

Merge readiness Overall: πŸ§‚ unranked krab Proof: πŸ¦ͺ silver shellfish Patch quality: πŸ§‚ unranked krab Result: blocked until stronger real behavior proof is added.

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

Rank-up moves:

  • Protect or fail-close legacy persisted tails without mutating user log files.
  • Guard setup-log enumeration and remove unapproved startup/cache rewrites or document/test them as a migration.
  • Post current-head proof showing seeded fake secrets absent from both preview and saved diagnostics output.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: Screenshots show the preview/save UI, but they do not prove current-head seeded fake secrets are absent from both the preview and saved diagnostics output; redact private details and update the PR body so ClawSweeper can re-review automatically, or ask a maintainer to comment @clawsweeper re-review if it does not run.

Mantis proof suggestion A desktop proof run would materially help verify the WinUI diagnostics preview/save flow and redaction boundary on current head. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis visual task: verify diagnostics bundle preview and saved file omit seeded fake tokens, setup codes, user paths, IPs, and raw settings.

Risk before merge

  • [P1] The shareable preview/save bundle can include raw legacy or multi-line persisted secrets because tails are appended without export-time protection.
  • [P1] The PR rewrites existing tray, JSONL, crash, setup, auxiliary log, and chat metadata files during startup/export/cache construction without an explicit migration decision or upgrade proof.
  • [P1] Setup-log enumeration can still throw during startup normalization or bundle preview, turning diagnostics collection into an availability problem.
  • [P1] The screenshots are insufficient and partly stale relative to current head; they do not prove seeded fake secrets are absent from both preview and saved file output.
  • [P1] GitHub reports the PR as draft and conflicting, so final review needs a refreshed mergeable head.

Maintainer options:

  1. Keep Existing Files Read-Only (recommended)
    Preserve source-side sanitization for new writes, but build the shareable bundle from sanitized export copies or fail-closed legacy sections instead of rewriting persisted user files.
  2. Approve A Real Migration
    Maintainers could accept persisted-file rewrites only with an explicit migration decision, upgrade tests, and proof that support evidence is not destructively changed.
  3. Pause Until Refreshed And Proven
    Because the PR is draft and conflicting, maintainers can leave it paused until the branch is mergeable and the contributor posts current-head seeded-secret proof.

Next step before merge

  • [P1] Manual review is needed because the remaining blockers combine privacy-boundary policy, persisted-file migration approval, contributor proof, and a draft/conflicting branch rather than one safe automation repair.

Security Needs attention: The patch introduces a shareable diagnostics bundle path that can still include raw legacy persisted log text without export-time protection.

Review findings

  • [P1] Protect persisted tails before sharing β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsLogTailReader.cs:42
  • [P1] Keep diagnostics export from rewriting user logs β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsBundleBuilder.cs:291
  • [P2] Guard setup-log enumeration failures β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsBundleBuilder.cs:150-154
Review details

Best possible solution:

Land a refreshed branch that keeps log-time sanitization for new writes, protects legacy persisted tails in read-only export copies or fails closed, avoids unapproved local file rewrites, guards enumeration failures, and includes current-head redaction proof.

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

Yes for the review findings: PR-head source shows raw persisted tail inclusion, silent file rewrites, and unguarded setup-log enumeration, and the PR test asserts a split token remains in the bundle. I did not run tests because this was a read-only review.

Is this the best way to solve the issue?

No; the feature direction is useful, but the current implementation mixes shareable log export with silent persisted-file mutation. The safer path is log-time sanitization plus read-only export protection or an explicit maintainer-approved migration.

Full review comments:

  • [P1] Protect persisted tails before sharing β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsLogTailReader.cs:42 BuildSection appends persisted log lines after truncation only, while the bundle manifest says there is no export-time sanitization and the added split-secret test asserts split-token-secret remains in output. Keep log-time sanitization, but add read-only export protection or fail-closed handling for legacy and multi-line tails before copy/save. Confidence: 0.95
  • [P1] Keep diagnostics export from rewriting user logs β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsBundleBuilder.cs:291 NormalizePersistedLogFile writes modified content back to existing tray/JSONL/crash logs, and startup calls the same normalization path. That silently mutates local support evidence during upgrade, so normalize an export copy or make this an explicit maintainer-approved migration with upgrade proof. Confidence: 0.9
  • [P2] Guard setup-log enumeration failures β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsBundleBuilder.cs:150-154 AppendLatestSetupLogs and NormalizeLatestSetupLogs enumerate setup logs after an Exists check without catching enumeration failures. If the directory becomes inaccessible, startup normalization or bundle preview can throw instead of reporting a failed diagnostics section. Confidence: 0.86
  • [P2] Avoid constructor cache rewrites without migration proof β€” src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:195-198 The chat data provider constructor rewrites tool and attachment metadata caches when legacy escaping is detected. Existing chat metadata should stay read-only on load, or this needs an approved migration with upgrade tests. Confidence: 0.78

Overall correctness: patch is incorrect Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority diagnostics export feature with limited blast radius, but it needs privacy, compatibility, availability, and proof fixes before merge.
  • merge-risk: 🚨 compatibility: The PR can silently rewrite existing persisted diagnostics logs and metadata caches during startup/export instead of treating existing user files as read-only.
  • merge-risk: 🚨 security-boundary: The PR changes how sensitive local diagnostics and persisted logs become a user-shareable bundle, and current head can include raw legacy tails.
  • merge-risk: 🚨 availability: The startup/export normalization path can throw on setup-log directory enumeration and block launch or diagnostics preview.
  • rating: πŸ§‚ unranked krab: Overall readiness is πŸ§‚ unranked krab; proof is πŸ¦ͺ silver shellfish and patch quality is πŸ§‚ unranked krab.
  • status: πŸ“£ needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Screenshots show the preview/save UI, but they do not prove current-head seeded fake secrets are absent from both the preview and saved diagnostics output; redact private details and update the PR body so ClawSweeper can re-review automatically, or ask a maintainer to comment @clawsweeper re-review if it does not run.
  • proof: πŸ“Έ screenshot: Contributor real behavior proof includes screenshot evidence. Screenshots show the preview/save UI, but they do not prove current-head seeded fake secrets are absent from both the preview and saved diagnostics output; redact private details and update the PR body so ClawSweeper can re-review automatically, or ask a maintainer to comment @clawsweeper re-review if it does not run.
Evidence reviewed

Security concerns:

  • [high] Raw persisted tails can leak secrets β€” src/OpenClaw.Tray.WinUI/Services/DiagnosticsLogTailReader.cs:42 DiagnosticsLogTailReader writes tail lines verbatim, and the branch test asserts split-token legacy text remains in the bundle, so the new sharing flow can expose sensitive data from pre-sanitization logs. Confidence: 0.95

What I checked:

Likely related people:

  • ranjeshj: Git blame/log ties DebugPage diagnostics wiring, BuildDebugBundle, and chat metadata cache history to commits authored by Ranjesh. (role: introduced current diagnostics/debug bundle structure and recent tray contributor; confidence: high; commits: 9a3a7a6131a8, 429be9ba9368; files: src/OpenClaw.Tray.WinUI/Pages/DebugPage.xaml.cs, src/OpenClaw.Tray.WinUI/Helpers/CommandCenterTextHelper.cs, src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • RBrid: Git blame/log ties TokenSanitizer and current tray-log/diagnostics redaction behavior to recent logging sanitizer work. (role: recent logging sanitizer contributor; confidence: high; commits: 753828f63e96; files: src/OpenClaw.Shared/TokenSanitizer.cs, src/OpenClaw.Tray.WinUI/Helpers/CommandCenterTextHelper.cs, src/OpenClaw.Tray.WinUI/Services/DiagnosticsJsonlService.cs)
  • kmahone: A collaborator review comment specifically directed the PR toward log-time sanitization, which is central to the remaining legacy-tail and migration question. (role: current PR reviewer with privacy-boundary direction; confidence: medium; files: src/OpenClaw.Tray.WinUI/Services/DiagnosticsBundleBuilder.cs, src/OpenClaw.Tray.WinUI/Services/DiagnosticsLogTailReader.cs)
  • shanselman: The PR discussion raises sanitizer reliability/performance concerns, and current-main history includes nearby hardening work. (role: reviewer and adjacent hardening contributor; confidence: medium; commits: d23f8ca50013; files: src/OpenClaw.Shared/TokenSanitizer.cs, src/OpenClaw.Tray.WinUI/Services/Logger.cs)
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.

clawsweeper[bot] avatar May 27 '26 18:05 clawsweeper[bot]

ClawSweeper PR egg

πŸ”₯ Warming up: real-behavior proof passed; findings, security review, or rank-up moves are still in progress.

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: πŸ‘€ ready for maintainer look, status: πŸš€ automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.
What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: πŸ₯š common, 🌱 uncommon, πŸ’Ž rare, ✨ glimmer, and 🌈 legendary.

clawsweeper[bot] avatar May 27 '26 18:05 clawsweeper[bot]

Real behavior proof for diagnostics bundle privacy boundary:

  • β€œCreate diagnostics bundle” opens a preview before log-tail diagnostics can be copied or saved.
  • Preview shows sanitized diagnostics/log content with useful context preserved.
  • β€œSave to file” opens the native Windows Save dialog.
  • Direct β€œCopy summary debug bundle” is summary-only and explicitly excludes log tails; log-tail diagnostics require the preview flow.
01-preview-dialog 02-native-save-dialog 03-summary-copy-card

christineyan4 avatar May 27 '26 20:05 christineyan4

This direction makes sense for a shareable diagnostics bundle, but the redactor is carrying a lot of regex responsibility in one place. I would not block solely because it uses regex β€” conservative over-redaction is probably right here β€” but I think it needs a maintainability/perf pass before merge: group the rules by threat class, consider source-generated regexes or clearly named rule objects, and add a worst-case/perf regression test so a long log line or malformed URL/token cannot cause pathological backtracking. The current test coverage for common secret shapes is good; my concern is mostly long-term maintainability and worst-case behavior.

shanselman avatar May 28 '26 00:05 shanselman

I took a closer pass on the redaction implementation. The feature is valuable and regex is not inherently the wrong tool for free-form diagnostics, but I think this needs a small reliability/perf cleanup before merge.

Concrete concerns:

  1. RegexMatchTimeoutException can abort the whole export. DiagnosticsLogTailReader.BuildSection() calls DiagnosticsExportRedactor.Sanitize(...), but its catch filter only handles IO/unauthorized/not-supported exceptions. If a regex hits the 100ms timeout on a long/malformed log line, the timeout escapes and the diagnostics export fails. Please catch RegexMatchTimeoutException there and around the final full-bundle Sanitize(builder.ToString()) pass in DiagnosticsBundleBuilder.Build() so the bundle can include a sanitization-timeout sentinel instead of failing.

  2. SlackSigningSecretPattern looks redundant/dead. It matches exactly 32 hex chars, but HexTokenPattern runs earlier and matches 32+ hex chars, so it should already replace every value that SlackSigningSecretPattern could see. I’d remove the Slack-specific regex and document/test that HexTokenPattern covers that shape.

  3. KeyValueSecretPattern has unbounded key-prefix scans before a large alternation. With MaxLineChars = 8000, a long non-matching key can burn work until the timeout. Consider bounding the key prefix/suffix length, or using a small rule pipeline that parses the key and then checks sensitive-key words outside regex.

  4. Please add tests for the scary cases: timeout does not abort bundle export, redaction is idempotent, JSON non-string secret values are handled or explicitly documented as a known gap, version strings/IP false positives are documented, and one max-size/perf smoke proves the redactor budget stays reasonable.

Longer-term, because this is net10.0, source-generated regexes ([GeneratedRegex]) or named redaction-rule objects would make this much easier to audit than a flat list of compiled regex fields. I would not block on β€œregex exists”, but I would block on timeout handling and at least one worst-case/perf regression guard.

shanselman avatar May 28 '26 00:05 shanselman

Screenshot 2026-06-11 131134 Screenshot 2026-06-11 131119

christineyan4 avatar Jun 11 '26 18:06 christineyan4

🦞🧹 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:

  • State: Complete
  • Detail: The targeted re-review finished, the durable review comment was updated, and the synced verdict was routed.
  • Run: https://github.com/openclaw/clawsweeper/actions/runs/27370565497
  • Updated: 2026-06-11T19:05:01.181Z

clawsweeper[bot] avatar Jun 11 '26 18:06 clawsweeper[bot]

@clawsweeper re-review

christineyan4 avatar Jun 11 '26 19:06 christineyan4

@christineyan4, take a look at Scott's feedback so that the sanitization is happening at log time instead of cleaning the log at export time.

kmahone avatar Jun 12 '26 21:06 kmahone