Skip to content

fix(sessions): keep sibling dirs that share the home prefix unshortened in tool path display - #96562

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
he-yufeng:fix/shortenpath-home-boundary
Jun 29, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
he-yufeng:fix/shortenpath-home-boundary

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The read (and other session tool) output in the TUI shortens home paths for display via shortenPath. It decided a path was "under home" with a bare path.startsWith(home), with no check for a path separator after the home directory. So a sibling directory that merely shares the home string as a prefix gets mangled:

  • home = /home/me, the tool shows /home/metrics/out.log as ~trics/out.log
  • home = C:\Users\He, the tool shows C:\Users\Helen\notes.md as ~len\notes.md

The displayed path is wrong and no longer copy-pasteable, which is the opposite of what the shortening is supposed to do.

Why This Change Was Made

src/utils.ts already gets this right in shortenHomePath: it special-cases input === home and otherwise only rewrites when the home segment is followed by a separator (${home}/ or ${home}\\). The TUI helper just predated that and never picked up the boundary check. This change brings shortenPath in line with the existing helper:

  • return ~ when the path is exactly the home directory
  • only rewrite when home is followed by / or \ (so real subpaths still shorten, siblings don't)

This is the same class of bug as #88449 (which fixes shortenHomeInString and the terminal-core display helper). That PR doesn't touch src/agents/sessions/tools/render-utils.ts, so this is a complementary fix for the one remaining helper with the naive prefix match.

User Impact

Session tool output displays sibling-of-home paths verbatim instead of corrupting them. Real subpaths under home keep shortening to ~/... exactly as before, and the home directory itself now collapses to ~.

Evidence

Before/after behavior, captured by running the actual shortenPath exported from src/agents/sessions/tools/render-utils.ts in this PR's checkout (HEAD 77137f14b) against the same helper on main. I bundled each real module with esbuild and called the exported function directly. shortenPath only depends on node:os, so the unrelated TUI imports in that file are not in its call path; the os.homedir() value is redacted to /home/alice through the environment:

os.homedir() [redacted] = /home/alice

input                           main (current)        this PR
------------------------------- --------------------- ----------------------------
/home/alice                     ~                     ~
/home/alice/project/app.ts      ~/project/app.ts      ~/project/app.ts
/home/alice-backup/app.ts       ~-backup/app.ts       /home/alice-backup/app.ts   <-- FIXED
/home/alicia/notes.md           /home/alicia/notes.md /home/alicia/notes.md
/home/alice2/tmp/x.log          ~2/tmp/x.log          /home/alice2/tmp/x.log   <-- FIXED
/etc/hosts                      /etc/hosts            /etc/hosts

main mangles the two sibling paths that only share the home string as a prefix (~-backup/app.ts and ~2/tmp/x.log). This PR leaves them intact while still shortening a real subpath and collapsing the home directory itself to ~.

The PR also adds a shortenPath block to render-utils.test.ts covering the same cases: a real subpath shortens, the home dir collapses to ~, a sibling sharing the prefix is left untouched, an unrelated path is untouched, and non-string input returns "". I couldn't run the full vitest suite end to end on my Windows machine, since a clean install pulls several heavyweight native packages (including @rolldown/binding-win32-x64-msvc) that don't fetch reliably here, so that test runs in CI rather than locally.

Note for maintainers

This PR was prepared with AI assistance (Claude Code). I verified the bug, the fix, and the tests myself before opening it.

… path display

shortenPath matched the home directory with a bare startsWith, so a path
that only shares the home prefix as a substring (home /home/user vs
/home/username, or C:\Users\He vs C:\Users\Helen) was rewritten to a bogus
"~..." display. Gate the rewrite on a path separator after the home dir,
matching shortenHomePath in src/utils.ts, and collapse the home directory
itself to "~".
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jun 24, 2026
@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 24, 2026, 8:37 PM ET / 00:37 UTC.

Summary
The PR updates the session tool shortenPath helper to shorten only exact home paths or separator-bounded home subpaths, and adds focused regression tests.

PR surface: Source +3, Tests +27. Total +30 across 2 files.

Reproducibility: yes. Source inspection shows current main and v2026.6.10 rewrite any string starting with os.homedir(), so a sibling path such as ${home}extra/app.ts would be displayed as ~extra/app.ts; I did not run a live TUI scenario in this read-only review.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/sessions/tools/render-utils.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #96562
Summary: This PR is the canonical candidate for the session tool shortenPath bug; related path-shortening work overlaps but does not replace this renderer-specific fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • none.

Next step before merge

  • [P2] No repair job is needed; the patch has no blocking code findings and the remaining action is ordinary maintainer review and merge validation.

Security
Cleared: The diff is limited to TypeScript display formatting and tests, with no dependency, workflow, package script, secret, or executable supply-chain changes.

Review details

Best possible solution:

Land the narrow helper and regression-test fix after ordinary maintainer review, preserving copy-pasteable session tool paths without changing the broader path-display policy.

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

Yes. Source inspection shows current main and v2026.6.10 rewrite any string starting with os.homedir(), so a sibling path such as ${home}extra/app.ts would be displayed as ~extra/app.ts; I did not run a live TUI scenario in this read-only review.

Is this the best way to solve the issue?

Yes. The PR fixes the local session renderer at the implicated helper and matches the separator-bounded behavior already used by shortenHomePath; importing the shared helper would also change this renderer's current OS-home-only display semantics.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This fixes a real user-visible session tool path display bug with a small, well-bounded code surface.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body now includes after-fix output from the PR checkout invoking the actual exported helper, with a current-main comparison showing the fixed behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body now includes after-fix output from the PR checkout invoking the actual exported helper, with a current-main comparison showing the fixed behavior.
Evidence reviewed

PR surface:

Source +3, Tests +27. Total +30 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 28 1 +27
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 32 2 +30

What I checked:

  • Repository policy applied: Root AGENTS.md and scoped agent/TUI guidance were read fully; the review applied the repo requirement to inspect source, callers, sibling helpers, tests, related PRs, proof, and history. (AGENTS.md:1, 8a5cb85c31e5)
  • Current main still has the bug: Current shortenPath rewrites any string starting with os.homedir(), so a sibling path sharing that prefix can display as a bogus ~... path. (src/agents/sessions/tools/render-utils.ts:21, 8a5cb85c31e5)
  • Latest release is also affected: The v2026.6.10 tag contains the same unbounded path.startsWith(home) implementation in the session tool renderer. (src/agents/sessions/tools/render-utils.ts:18, aa69b12d0086)
  • Caller surface is shared: The helper feeds session tool call display paths; read, write, edit, grep, find, and ls call renderers use this path-shortening surface. (src/agents/sessions/tools/read.ts:99, 8a5cb85c31e5)
  • Sibling helper supports this invariant: shortenHomePath already treats the exact home path separately and only shortens separator-bounded subpaths, so the PR aligns this local renderer without importing broader OPENCLAW_HOME display semantics. (src/utils.ts:183, 8a5cb85c31e5)
  • PR diff is narrow and covered: The PR adds exact-home and separator checks in shortenPath, plus tests for home subpaths, exact home, sibling prefixes, unrelated paths, and non-string input. (src/agents/sessions/tools/render-utils.ts:18, 77137f14b6d8)

Likely related people:

  • Shakker: Current-line blame and session-tool history for shortenPath and its call renderers point to commit c81fec0 on the relevant session rendering files. (role: recent area contributor; confidence: high; commits: c81fec0370c4; files: src/agents/sessions/tools/render-utils.ts, src/agents/sessions/tools/read.ts, src/agents/sessions/tools/write.ts)
  • Peter Steinberger: Git history shows commit 7a80e8f centralized home path shortening in src/utils.ts, the sibling invariant this PR follows. (role: adjacent display helper introducer; confidence: medium; commits: 7a80e8fe77a5; files: src/utils.ts)
  • Seb Slight: Commit db137dd updated OPENCLAW_HOME-aware path resolution and tests around the shared home-display helper behavior. (role: adjacent path-resolution contributor; confidence: medium; commits: db137dd65da0; files: src/utils.ts, src/utils.test.ts, src/infra/home-dir.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.

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and 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 Jun 24, 2026
@vincentkoc vincentkoc self-assigned this Jun 29, 2026
@vincentkoc
vincentkoc merged commit 1943363 into openclaw:main Jun 29, 2026
161 of 171 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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