Skip to content

fix(cli): align sessions cleanup label summary by visible width - #117459

Merged
steipete merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/sessions-cleanup-visible-width
Aug 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
zenglingbiao:fix/sessions-cleanup-visible-width

Conversation

@zenglingbiao

Copy link
Copy Markdown
Contributor

Summary

Fix the sessions cleanup dry-run "Summary by Label" table so labels containing emoji or CJK characters no longer shift the kept/pruned counts column out of alignment.

What Problem This Solves

Session labels are user-controlled via /name, and users routinely put emoji or CJK text in them. The dry-run summary groups sessions by label and aligns the counts column by padding each label to the widest label:

  • In src/commands/sessions-cleanup.ts:132, the column width was computed with summary.label.length — the UTF-16 code-unit count, not the terminal cell width.
  • In src/commands/sessions-cleanup.ts:139, label.padEnd(labelPad) padded by code units for the same reason.

A label like 🔥修复 occupies 6 terminal cells (wide emoji + 2 wide CJK) but only 5 UTF-16 code units, so the padding math disagrees with what the terminal renders and the kept, pruned counts no longer line up across rows. Any user running openclaw sessions cleanup --dry-run with emoji/CJK session names sees a crooked summary table.

Code evidence: in src/commands/sessions-cleanup.ts:132,139, the width and padding were based on .length/padEnd, which count UTF-16 code units instead of visible terminal columns.

Root Cause

  • Bug introduced by commit a89e6e05efa ("fix(cli): summarize cleanup dry-run by label", fix(cli): summarize cleanup dry-run by label #93565, 2026-06-16), which added the label summary table.
  • Violated invariant: the code assumed string.length equals the number of terminal cells a string occupies. That holds only for narrow ASCII; wide emoji, CJK, and combining characters break it.
  • Trigger condition: any two labels in the same summary whose UTF-16 length and visible width differ (e.g. /name 🔥修复 next to /name plain).

Why This Fix

  • The repository already solved this exact problem in fix(terminal): keep Unicode cron columns aligned #117062 by introducing visibleWidth (packages/terminal-core/src/ansi.ts), which measures terminal cell width (ANSI-aware, wide-grapheme-aware).
  • Option A (this PR): compute the column width with visibleWidth and pad with " ".repeat(labelPad - visibleWidth(label)) — the same idiom already used by src/cli/cron-cli/shared.ts and src/commands/models/list.format.ts.
  • Option B (rejected): keep padEnd and special-case wide characters — duplicates visibleWidth logic inline and drifts from the shared implementation.
  • Option C (rejected): strip emoji/CJK from labels before display — loses user information; the table should show the real label.

User Impact

  • Affected operation: openclaw sessions cleanup (dry-run and applied runs that print the "Summary by Label" table) when session labels contain emoji or CJK text.
  • After the fix, the counts column stays aligned regardless of label content; plain ASCII labels render exactly as before.

Evidence

  • Before: on main, seeding a real session store with /name 🔥修复 and /name plain and running the dry-run cleanup prints the counts at visible columns 9 and 7 — misaligned (FAIL).
  • After: on this branch, the same store prints both counts at visible column 8 — aligned (PASS).

Real Behavior Proof

Before (on main)

$ node --import tsx proof.mjs
=== sessions cleanup --dry-run label summary ===
🔥修复   1 kept, 0 pruned
plain  1 kept, 0 pruned
counts column visible offsets: 9, 7
FAIL: counts column is misaligned (UTF-16 .length used as column width)

After (with fix)

$ node --import tsx proof.mjs
=== sessions cleanup --dry-run label summary ===
🔥修复  1 kept, 0 pruned
plain   1 kept, 0 pruned
counts column visible offsets: 8, 8
PASS: counts column is aligned for emoji/CJK and ASCII labels

Proof setup: a real sqlite session store was seeded through the repository's own upsertSessionEntry API with two sessions labeled 🔥修复 and plain, then the real sessionsCleanupCommand({ dryRun: true, store }) code path printed the summary above.

Tests and Validation

  • Added a regression test in src/commands/sessions-cleanup.test.ts ("aligns the label summary columns for emoji and CJK labels") that asserts the counts column starts at the same visible offset for 🔥修复 and plain labels.
  • pnpm vitest run src/commands/sessions-cleanup.test.ts — 9/9 tests passed.
  • pnpm check passed.
  • Sibling audit: the other padEnd sites in this file (Action/Key/Age/Model columns) pad fixed ASCII enums, literals, or truncated ASCII-safe cells, so they are not affected.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Aug 1, 2026
@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 3:17 PM ET / 19:17 UTC.

ClawSweeper review

What this changes

This PR updates the sessions cleanup label-summary output to align kept/pruned counts by terminal display width for emoji and CJK labels, with a targeted regression test.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking findings. Current main still pads label summaries by UTF-16 code-unit length, while this PR uses the established terminal-width helper and adds focused regression coverage; it remains useful and ready for normal maintainer merge review after the behind-base state is refreshed.

Priority: P3
Reviewed head: 8cb02e5eee7cf980680e2145f723bca152ff7c27

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-aligned CLI repair with real-path terminal proof and targeted regression coverage; only the behind-main merge refresh remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides before/after terminal output from the real cleanup command path over a seeded SQLite session store, showing aligned visible offsets after the change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides before/after terminal output from the real cleanup command path over a seeded SQLite session store, showing aligned visible offsets after the change.
Evidence reviewed 6 items Current main still has the defect: The supplied current-main commit calculates the label width with summary.label.length and pads with padEnd, which measures UTF-16 code units rather than terminal cells.
PR repairs the owner-boundary formatting logic: The PR imports visibleWidth, computes the largest terminal-cell width, and appends only the required spaces before writing each count summary.
Regression coverage checks rendered column alignment: The new test runs the cleanup command’s dry-run path with 🔥修复 and plain, then compares the terminal-width offset where 1 kept begins.
Findings None None.
Security None None.

How this fits together

The sessions cleanup CLI reads session-store preview rows, groups them by session label, and prints a dry-run summary for operators. This change affects only the text-table padding used before the kept/pruned counts are logged.

flowchart LR
  A[Session store preview] --> B[Cleanup action rows]
  B --> C[Label summaries]
  C --> D[Terminal width measurement]
  D --> E[Aligned count padding]
  E --> F[CLI dry-run output]
Loading

Before merge

  • Resolve merge risk (P1) - The branch base predates the shared terminal-width helper and GitHub reports the PR as behind current main; refresh the merge result or rebase before landing so the import is evaluated against the current terminal-core surface.
  • Complete next step (P2) - No repair dispatch is needed: this PR already contains the narrow implementation, regression coverage, and real-path proof; the remaining action is ordinary current-head merge review.
Agent review details

Security

None.

PR surface

Source +1, Tests +71. Total +72 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 4 +1
Tests 1 71 0 +71
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 76 4 +72

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/commands/sessions-cleanup.test.ts, unknown-data-model-change: src/commands/sessions-cleanup.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused migration to the existing visibleWidth contract after a current-main merge refresh confirms the clean three-way result; keep all label content intact and preserve the existing cleanup policy and JSON behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land this focused migration to the existing visibleWidth contract after a current-main merge refresh confirms the clean three-way result; keep all label content intact and preserve the existing cleanup policy and JSON behavior.

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

Yes, at source level: current main derives padding from code-unit length, so a wide emoji/CJK label and an ASCII label can place the counts at different terminal columns. The PR body also supplies a real cleanup-path before/after terminal transcript, though this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing terminal-core’s existing ANSI-aware visibleWidth contract is the narrowest maintainable repair and matches established cron and model-list formatting patterns instead of duplicating Unicode-width logic.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This corrects a low-blast-radius CLI presentation defect without changing cleanup decisions, stored sessions, configuration, or API output.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides before/after terminal output from the real cleanup command path over a seeded SQLite session store, showing aligned visible offsets after the change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after terminal output from the real cleanup command path over a seeded SQLite session store, showing aligned visible offsets after the change.

Evidence

What I checked:

  • Current main still has the defect: The supplied current-main commit calculates the label width with summary.label.length and pads with padEnd, which measures UTF-16 code units rather than terminal cells. (src/commands/sessions-cleanup.ts:132, bf99e43ee7d3)
  • PR repairs the owner-boundary formatting logic: The PR imports visibleWidth, computes the largest terminal-cell width, and appends only the required spaces before writing each count summary. (src/commands/sessions-cleanup.ts:133, 8cb02e5eee7c)
  • Regression coverage checks rendered column alignment: The new test runs the cleanup command’s dry-run path with 🔥修复 and plain, then compares the terminal-width offset where 1 kept begins. (src/commands/sessions-cleanup.test.ts:707, 8cb02e5eee7c)
  • Shared terminal contract already exists: visibleWidth delegates to the terminal-core text-width path after stripping ANSI sequences, and its owner tests explicitly cover ASCII, emoji, CJK, ANSI, and controls. (packages/terminal-core/src/ansi.ts:202, 7ab05df415a4)
  • Feature-history provenance: The original label-summary behavior appears to date to the merged cleanup-summary change; the shared terminal-width implementation arrived later in the terminal-core change, leaving this output path as a remaining consumer to migrate. (src/commands/sessions-cleanup.ts:124, a89e6e05efab)
  • Submitted proof and CI state: The supplied PR context contains before/after real cleanup-path terminal output from a seeded SQLite session store, marks proof sufficient, and reports successful relevant hosted checks; the PR is mergeable but behind main. (8cb02e5eee7c)

Likely related people:

  • steipete: Peter Steinberger is the recorded author of the merged shared terminal-width change and has the deepest recent history across both the terminal and sessions-cleanup files. (role: recent terminal-core and sessions-area contributor; confidence: high; commits: 95e50d3a7f14, 7ab05df415a4; files: packages/terminal-core/src/ansi.ts, src/commands/sessions-cleanup.ts)
  • xiayu: The merged commit that introduced the cleanup dry-run label summary is attributed to xiayu, making this person a useful routing contact for the original output behavior. (role: label-summary feature introducer; confidence: high; commits: a89e6e05efab; files: src/commands/sessions-cleanup.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the merge result or rebase onto current main, then retain the focused visible-width regression test.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-01T15:14:57.381Z sha e60c58afca386d78b52e3b6c4feb5edaf3dc061f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T15:52:44.505Z sha 8cb02e5 :: needs maintainer review before merge. :: none

@zenglingbiao
zenglingbiao force-pushed the fix/sessions-cleanup-visible-width branch from e60c58a to 8cb02e5 Compare August 1, 2026 15:47
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Maintainer independently ran the same real SQLite session store -> production upsertSessionEntry -> production sessionsCleanupCommand({ dryRun: true, store }) -> actual process.stdout on current main and the exact untouched contributor head 8cb02e5eee7cf980680e2145f723bca152ff7c27:

BEFORE: 🔥修复   1 kept, 0 pruned
        plain  1 kept, 0 pruned
        measured count-column positions: [9, 7]
AFTER:  🔥修复  1 kept, 0 pruned
        plain   1 kept, 0 pruned
        measured count-column positions: [8, 8]
Both runs: 2 real SQLite entries kept; 0 entries removed or mutated.

For precision, 🔥修复 contains 4 UTF-16 code units but occupies 6 visible terminal columns; plain is 5 in both measures. The existing canonical visibleWidth helper already exists on current main, so this is output-only padding repair.

Focused owner regression: OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-vitest-s02-117459-sessions node scripts/run-vitest.mjs src/commands/sessions-cleanup.test.ts — 9 passed. Fresh exact full-commit gpt-5.6-sol xhigh review: clean (0.99). Exact untouched-head full CI is green: https://github.com/openclaw/openclaw/actions/runs/30706700106.

ClawSweeper rank-up addressed: native review refreshed current-main comparison and confirmed the existing shared terminal-width helper; the original contributor head is mergeable, so preserve the already-green original head without an unnecessary rebase.

@steipete
steipete merged commit 37e7307 into openclaw:main Aug 1, 2026
119 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 1, 2026
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5':
  fix(channels): preserve filters in offline status diagnostics (#117570)
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5':
  fix(channels): preserve filters in offline status diagnostics (#117570)
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
  refactor(ui): consolidate cron form control rendering (#117576)
  fix(memory): recover restored session freshness (#117548)
  fix(ui): preserve Talk transcript surrogate bounds
  fix(ui): harden Talk transcript marker bounds
  test(ui): cover bounded realtime Talk entries
  fix(ui): bound realtime Talk conversation text
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* origin/main:
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5':
  fix(channels): preserve filters in offline status diagnostics (#117570)
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* commit '58213dd5389737ff100c6286d110921defeb76e8':
  fix(channels): preserve filters in offline status diagnostics (openclaw#117570)
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* commit '58213dd5389737ff100c6286d110921defeb76e8':
  fix(channels): preserve filters in offline status diagnostics (openclaw#117570)
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* commit '58213dd5389737ff100c6286d110921defeb76e8':
  fix(channels): preserve filters in offline status diagnostics (openclaw#117570)
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
  refactor(ui): consolidate cron form control rendering (openclaw#117576)
  fix(memory): recover restored session freshness (openclaw#117548)
  fix(ui): preserve Talk transcript surrogate bounds
  fix(ui): harden Talk transcript marker bounds
  test(ui): cover bounded realtime Talk entries
  fix(ui): bound realtime Talk conversation text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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