Skip to content

fix(memory): sanitize file-derived terminal search reports - #184396

Closed
Leon-SK668 wants to merge 1 commit into
openclaw:mainfrom
Leon-SK668:leon/fix-memory-search-terminal-output-20261026
Closed

Leon-SK668 wants to merge 1 commit into
openclaw:mainfrom
Leon-SK668:leon/fix-memory-search-terminal-output-20261026

Conversation

@Leon-SK668

Copy link
Copy Markdown
Contributor

What Problem This Solves

memory search prints file-derived result paths and Markdown snippets directly into human terminal output. A normally indexed Markdown file can therefore introduce terminal-control sequences into a successful search report. Existing CLI tests strip VT characters before comparing ordinary output, which can conceal this boundary.

Why This Change Was Made

Use the existing SDK sanitizeTerminalText in the one search renderer shared by local and attached-Gateway result owners. Sanitize the shortened display path before applying trusted theme styling. Sanitize snippets line by line so their intentional LF structure remains readable. The JSON branch returns before this human formatting.

The canonical sanitizer and existing multiline-report pattern already solve this operation; no new helper, package, setting or API is necessary. The search operation, index, snippet projection, files, raw result objects and machine output retain their contracts. Warnings/errors and arbitrary argument echoes are outside this bounded successful-result change.

All-state symptom, renderer-symbol and owner-path searches, including public Leon/Alix footprints, found no equivalent viable fix. Existing cli-search-output PRs #180553, #124118 and #144833 address other behavior. Accepted file-derived location-report repair #183359 supplies a related presentation precedent.

User Impact

Search results remain readable with ordinary Unicode and multiline snippets. File content no longer acts as terminal controls in the human report; TAB/CR are visible escape text. Raw JSON, source bytes, search ranking, indexing and result identities remain unchanged. No config/default, protocol, security permission, storage, migration or dependency change is introduced.

Evidence

Compiled RED is clean 18d2633de8abd677ae1852b48950701bce8ff302; exact GREEN is clean ea8af01c62356125180d343e2c892326edc976c5, parent main f0d422a7cb485eb19ff9671aa3a588cb4cf3a46a. Relevant entry/search/render/runtime owners match between RED and parent. Fresh main 95dff1e02bc59bc86dd6e75ff93d7ab2714daac9 retains those owners and the publication contracts; native merge-tree verification is clean. Each recorder run checks clean source HEAD and matching dist/build-info.json.commit.

The same frozen recorder writes two ordinary Markdown files into a fresh isolated workspace, configures the documented FTS-only memory search (provider: "none", vectors disabled), and uses five normal built CLI commands:

node openclaw.mjs memory index --agent main
node openclaw.mjs memory search saffronleaf --agent main --min-score 0
node openclaw.mjs memory search saffronleaf --agent main --min-score 0 --json
node openclaw.mjs memory search copperorchard --agent main --min-score 0
node openclaw.mjs memory search unfindablezebra739284 --agent main --min-score 0 --json

The first Markdown file contains normal multiline text plus ESC erase, BEL and C1 erase controls (U+001B, U+0007 and U+009B). RED human output contains all three original controls. GREEN contains none and retains this captured snippet excerpt:

saffronleaf first line
second line before after escape bell after C1
final line.

All five actual CLI commands exit 0 on both builds. The normal multiline copperorchard control is unchanged; absent JSON returns results: []. Controlled JSON still contains the exact original Markdown snippet and path memory/terminal-report.md, with source/snippet SHA256 5ba1bce00572da394f2671ee9b8df488ee23744cb5b984837894f74bc193d772. No source file, config or index content is rewritten for presentation. A separate reader reopens both Markdown files/config and all ten saved process streams, verifies hashes, reparses real JSON and compares it to the actual source. It makes zero new OpenClaw calls.

This uses the public index/search path and ordinary files, without internal database/result injection, Gateway, agent/model/embedding/API calls or production state. Dreaming, cron, catalog refresh and startup update checks are disabled only in the isolated fixture. Both runs retain the same 73-byte Node SQLite experimental warning on stderr; empty stderr is not claimed. An earlier plugins-disabled setup failure is retained as setup failure, not acceptance RED.

RED wall 63.86 s; GREEN wall 71.53 s. Frozen recorder SHA256 42fbe485049c41750303de91bbb4fa4843709bd29f1268e68d9af124f2ef483a; independent reader 042849e3bda7a7802ff5da16a439fcb7e688a73f8a15f9a0f3ba7367b45023f0. RED receipt bb340b8d665c455a519dafb06d78f79ae4c2460aa49caf2639f2bfee26903c9c; GREEN receipt 5d5c38ad34d5fe9a1756aa4382c5257816ed2ed4c82d02d8c61466c406ad6c75.

Validation:

OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs extensions/memory-core/src/cli-search-output.test.ts extensions/memory-core/src/cli.test.ts --maxWorkers=1 --testNamePattern='search|file-derived'
pnpm build sourcePerformance
git diff --check
  • Tests-only RED: new raw human-output assertion fails and raw JSON control passes; 138.13 s wall including 90.421 s cold worker preparation. Final focused GREEN: 9 passed, 51 unrelated cases unselected, 66.70 s wall; new test bodies 27.96 ms. Existing consumer cases also exercise normal search/stale/failure behavior. Expectations do not call the sanitizer to produce their expected output.
  • Source-backed tsgo PASS, 96.052 s. Canonical typed lint with original config/tsconfig/oxlint.source.json and full wrapper preparation: JSON diagnostics empty, two files, 293 rules, 77.893 s wall. Format/diff PASS. Exact-commit sourcePerformance build PASS, 296.55 s. An earlier broader lint attempt was interrupted, retained and excluded from PASS; no policy/limit was weakened.
  • Two files: production +6/-2 (net +4, existing import/display values and LF-contract comment), new tests +41. Complete author simplify/test audit has no remaining accepted finding. Independent review was waived by the user; the normal contributor identity hook stayed enabled.

Not tested: an on-disk control-bearing filename (covered at the raw renderer boundary by regression tests), actual interactive TTY, attached-Gateway execution, all error/warning reports, cross-OS, packaged upgrades, broad suites or hosted PR CI. Both transport callers share the same changed renderer; the actual native proof exercises the local caller.

Agent Transcript

Implemented with Codex assistance. Actual task-scoped excerpt, with unrelated context, raw tools, credentials, private paths and reasoning omitted.

Authorized sanitized agent transcript

Assistant: “并行处理:我负责提交、构建和线上状态;一个子代理完成 memory 修复的规范检查,另两个分别复查剩余 Unicode 入口和已合入的终端报告族。”

@clawsweeper

clawsweeper Bot commented Oct 26, 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Sanitize file-derived paths and snippets in human-readable memory search results while preserving raw JSON.

Example: Run memory search saffronleaf against Markdown containing ESC erase, BEL, and C1 controls.

  • Before: The human report emits the original terminal controls.
  • After: The report removes those controls, preserves snippet line breaks, and leaves JSON values unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused existing-owner repair with shipped-CLI evidence, meaningful regression coverage, and no open findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies captured output and byte-level observations from built memory index/search commands on the exact head in an isolated FTS-only workspace: control-bearing snippets become safe human text while normal multiline output and raw JSON remain intact; attached-Gateway and interactive-TTY execution are explicitly unclaimed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Indexed Markdown content and filenames can execute terminal controls when displayed by memory search.
Reason: The repair protects a concrete presentation boundary using an existing owner and sanitizer, without adding settings, APIs, or runtime state.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete terminal-output defect still present on current main with a focused change and credible shipped-CLI evidence; no actionable defect was found.

Priority: P2
Reviewed head: ea8af01c62356125180d343e2c892326edc976c5

Before merge

None.

Findings

None.

Agent review details

How this fits together

Local and Gateway-backed memory searches produce results for one CLI renderer, which emits either human-readable terminal text or raw JSON.

flowchart TD
  A[Memory files] --> B[Memory search owner]
  B --> C[Local or Gateway result]
  C --> D[Shared CLI renderer]
  D --> E[Sanitized human report]
  D --> F[Raw JSON]
Loading

Technical review

Best possible solution:

Keep sanitization in the existing shared renderer, preserving raw search results, JSON, and snippet line breaks.

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

Current-main source exposes the control-bearing text to console output, and the contributor supplies before/after built-CLI evidence; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is the smallest complete repair: reuse the canonical sanitizer at human display egress without changing indexing, transport, stored content, or machine output.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 798570bc460f.

Provenance checked

  • Shared memory-search human rendering keeps the original intent (e40606f: The prior renderer extraction preserved CLI search behavior while routing database work through the correct local or Gateway owner; it does not establish when raw rendering originally began.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +4, Tests +41. Total +45 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 6 2 +4
Tests 1 41 0 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 47 2 +45

Labels

Label changes:

No label changes.

Label justifications:

  • P2: File-derived terminal controls affect human memory-search reports, with a focused repair and limited scope.
  • 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.

Reviewed October 26, 2026, 4:45 AM ET / 08:45 UTC.

obviyus added a commit that referenced this pull request Oct 28, 2026
…amilies (#186502)

fix(cli): route remaining CLI reports through the terminal-text owner

After #185927 added one owner for escaping untrusted values in CLI output, contributors kept opening one PR per command to escape the next report. This moves the remaining human-readable reports in the plugins, secrets, sessions, memory and memory-wiki, workboard, backup, pairing, oc-path, config and setup commands onto `terminalText` / `displayPath`, and extends the owner to neutralize bidirectional control characters. JSON output, persisted identities, raw exports and the CLI's own colors are unchanged, and the trusted styling of `renderTable` is untouched.

This absorbs the per-site fixes from @Leon-SK668 (#184454, #184379, #185374, #186449, #184396, #184788, #184813, #184394), @huwei-xydt (#185895, #185719), @wangmiao0668000666 (#175600, #175181, #175179), @SunnyShu0925 (#184747), @KrasimirKralev (#184597) and @arpe1618 (#150599), whose original commits are kept. Families no PR touched (update, Doctor, install-trust producers and others) are listed under "Not fixed here".

Evidence: 85 built-CLI invocations per ref with crafted control and bidi characters in the reported values, captured as raw stdout bytes. Main printed the raw sequences; this change printed them neutralized, with identical normal colors and unchanged JSON. Details: #186502 (comment).

Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Leon-SK668 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Krasimir Kralev <[email protected]>
Co-authored-by: arpe1618 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Leon-SK668. This is now fixed at the root in #186502 (3bcca4f), which routes the remaining CLI reports through the shared terminalText owner from terminal-core. Your commit is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new output sites, please pass untrusted values through terminalText (or displayPath for paths) rather than opening a PR per command.

@obviyus obviyus closed this Oct 28, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…amilies (openclaw#186502)

fix(cli): route remaining CLI reports through the terminal-text owner

After openclaw#185927 added one owner for escaping untrusted values in CLI output, contributors kept opening one PR per command to escape the next report. This moves the remaining human-readable reports in the plugins, secrets, sessions, memory and memory-wiki, workboard, backup, pairing, oc-path, config and setup commands onto `terminalText` / `displayPath`, and extends the owner to neutralize bidirectional control characters. JSON output, persisted identities, raw exports and the CLI's own colors are unchanged, and the trusted styling of `renderTable` is untouched.

This absorbs the per-site fixes from @Leon-SK668 (openclaw#184454, openclaw#184379, openclaw#185374, openclaw#186449, openclaw#184396, openclaw#184788, openclaw#184813, openclaw#184394), @huwei-xydt (openclaw#185895, openclaw#185719), @wangmiao0668000666 (openclaw#175600, openclaw#175181, openclaw#175179), @SunnyShu0925 (openclaw#184747), @KrasimirKralev (openclaw#184597) and @arpe1618 (openclaw#150599), whose original commits are kept. Families no PR touched (update, Doctor, install-trust producers and others) are listed under "Not fixed here".

Evidence: 85 built-CLI invocations per ref with crafted control and bidi characters in the reported values, captured as raw stdout bytes. Main printed the raw sequences; this change printed them neutralized, with identical normal colors and unchanged JSON. Details: openclaw#186502 (comment).

Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Leon-SK668 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Krasimir Kralev <[email protected]>
Co-authored-by: arpe1618 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core 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