Skip to content

improve: avoid rebuilding terminal link fallbacks - #139159

Merged
steipete merged 1 commit into
mainfrom
codex/perf10-terminal-links
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf10-terminal-links

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Formatting CLI help and documentation links rebuilt every label and URL character by character, even when redirected output used an explicit fallback and neither input would be displayed.

Why This Change Was Made

The terminal-link owner now removes the same C0, DEL, and C1 characters with Unicode Cc replacement and selects explicit plain-text fallbacks before sanitizing unused inputs. Printable ANSI fragments, Unicode text, empty fallbacks, TTY/force selection, and OSC-8 framing keep their existing byte contract.

User Impact

CLI links render identically with less temporary allocation. The docs-fallback microbenchmark sampled 3,955 → 56 bytes per call; this is an owner-level result, not an end-to-end CLI or retained-memory claim. Production is 6 lines smaller; expanded existing tests add 6 net lines.

Evidence

  • 20 tests across the terminal-link, docs-link, and safe-text suites passed before and after; existing cases were expanded without increasing the test count.
  • 253,710 string/UTF-16 byte comparisons covered all Unicode code points, randomized UTF-16, controls, fallback options, and TTY/force combinations. Outputs matched exactly.
  • Real OS pipe and PTY calls preserved plain fallback and OSC-8 output. Formatting and diff checks passed; managed P0–P2 review was scoped-clean with no findings.
  • Timings and sampled allocation are shared-host microbenchmarks; they do not establish whole-Gateway RSS, retained heap, or CLI startup improvements. Current-head CI and native landing checks are recorded separately by the publisher.

@clawsweeper

clawsweeper Bot commented Sep 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 14:57
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 11:03 AM ET / 15:03 UTC.

ClawSweeper review

What this changes

The PR reduces temporary string allocation when formatting terminal links while preserving clickable links, plain-text fallbacks, and control-character filtering.

Merge readiness

✅ Ready for maintainer review

Keep open: this useful optimization is absent from inspected main and the latest release. No blocking correctness or security findings.

Priority: P3
Reviewed head: e65640e4555e2f93b6847c8af1ba76af26805a1e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused simplification with useful output-contract coverage and no actionable defects found.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer exemption applies to this behavior-preserving optimization; the body reports formatter checks through real pipes and PTYs, without an independently inspectable execution trace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer exemption applies to this behavior-preserving optimization; the body reports formatter checks through real pipes and PTYs, without an independently inspectable execution trace.
Evidence reviewed 10 items Formatter and implementation boundary: Read the complete formatter: explicit non-clickable fallbacks return before unused inputs are sanitized; force selection, empty fallback handling, and OSC-8 framing remain intact. The module uses JavaScript string operations and Node stdout, with no affirmative Codex dependency signal.
Production caller: The documentation-link wrapper always supplies a plain URL fallback, making the early return relevant to ordinary CLI output; root help calls this wrapper at src/cli/program/help.ts:161.
Behavioral coverage: Expanded existing cases exercise all 65 C0/DEL/C1 characters, printable Unicode, unpaired surrogates, literal ANSI fragments, and explicit empty fallbacks. The complete documentation-link and safe-text suites were also inspected. Tests were not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

Terminal Core formats links used by CLI help and documentation messages. It receives labels, URLs, and display options, then returns either terminal hyperlink sequences or readable plain text.

flowchart TD
  A[CLI help and documentation messages] --> B[Labels URLs and display options]
  B --> C{Clickable output enabled}
  C -->|Yes| D[Sanitize label and URL]
  D --> E[Terminal hyperlink]
  C -->|No| F[Select and sanitize fallback]
  F --> G[Plain text]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -6, Tests +6. Total 0 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 13 -6
Tests 1 16 10 +6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 23 23 0

Review metrics

Metric Value Why it matters
Production versus test LOC Production −6 net; tests +6 net The optimization simplifies the production owner while expanding existing behavioral cases without adding test-only production seams.

Technical review

Best possible solution:

Retain one formatter with the existing terminal-safety contract, avoiding unnecessary work without introducing caching, dependencies, or configuration.

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

Not applicable to a functional bug: this is an optimization, and current-main source confirms the unnecessary reconstruction and eager sanitization.

Is this the best way to solve the issue?

Yes. The shared formatter owns this work; caller-side shortcuts would duplicate policy, while the general safe-text sanitizer would change output semantics.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded allocation optimization that preserves existing CLI output rather than repairing a broken user workflow.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer exemption applies to this behavior-preserving optimization; the body reports formatter checks through real pipes and PTYs, without an independently inspectable execution trace.

Label justifications:

  • P3: This is a bounded allocation optimization that preserves existing CLI output rather than repairing a broken user workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer exemption applies to this behavior-preserving optimization; the body reports formatter checks through real pipes and PTYs, without an independently inspectable execution trace.

Evidence

What I checked:

  • Formatter and implementation boundary: Read the complete formatter: explicit non-clickable fallbacks return before unused inputs are sanitized; force selection, empty fallback handling, and OSC-8 framing remain intact. The module uses JavaScript string operations and Node stdout, with no affirmative Codex dependency signal. (packages/terminal-core/src/terminal-link.ts:14, e65640e4555e)
  • Production caller: The documentation-link wrapper always supplies a plain URL fallback, making the early return relevant to ordinary CLI output; root help calls this wrapper at src/cli/program/help.ts:161. (packages/terminal-core/src/links.ts:26, e65640e4555e)
  • Behavioral coverage: Expanded existing cases exercise all 65 C0/DEL/C1 characters, printable Unicode, unpaired surrogates, literal ANSI fragments, and explicit empty fallbacks. The complete documentation-link and safe-text suites were also inspected. Tests were not executed during this read-only review. (packages/terminal-core/src/terminal-link.test.ts:5, e65640e4555e)
  • Existing alternative has different semantics: The sibling sanitizer already uses Unicode Cc matching, but additionally strips complete ANSI sequences and escapes line controls. Reusing it would alter the terminal-link output contract. (packages/terminal-core/src/safe-text.ts:12, e65640e4555e)
  • Current main still performs unnecessary work: The fetched main revision retains character-by-character reconstruction and sanitizes both label and URL before selecting an explicit fallback. (packages/terminal-core/src/terminal-link.ts:21, 12a3b102f507)
  • Latest release comparison: The formatter in v2026.9.1 also retains the reconstruction loop and eager sanitization; this optimization is not present in that release. (packages/terminal-core/src/terminal-link.ts:3, ad6fe23aecb9)

Likely related people:

  • linhongkuan: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 7668ef0 into main Sep 5, 2026
184 checks passed
@steipete
steipete deleted the codex/perf10-terminal-links branch September 5, 2026 15:16
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to aniruddhaadak80/openclaw that referenced this pull request Sep 5, 2026
* origin/main: (46 commits)
  fix(gateway): keep chat metadata responsive across auth refresh (openclaw#139192)
  fix(doctor): keep Workshop relocation lint read-only (openclaw#139193)
  perf(ui): retain unchanged forwarded avatar publications (openclaw#139181)
  fix(config): guide exec policy migration repairs (openclaw#139143)
  test(i18n): refresh representative Watch key (openclaw#139197)
  fix(agents): preserve recovered scheduled-run outcomes (openclaw#139037)
  refactor(acp): simplify pending operation accounting (openclaw#139189)
  fix(plugin-sdk): harden account scope for pairing requests and challenges (openclaw#139142)
  perf(gateway): avoid redundant PR landing ancestry checks (openclaw#139186)
  perf(ui): release captured audio cache leases directly (openclaw#139174)
  fix(skills): validate names in library forms (openclaw#139184)
  fix(sessions): reduce cold catalog listing delays (openclaw#139146)
  perf(cron): scan preserved action output once (openclaw#139163)
  fix(agents): keep fresh tool results readable under context pressure (openclaw#139165)
  fix(compaction): heartbeat sessions ignore the active transcript byte cap (openclaw#136533)
  perf(agents): reuse snapshotted web search result rows (openclaw#139162)
  fix(onboarding): keep Tauri setup recoverable and verify model results (openclaw#139140)
  fix(memory): rank indexed sessions by source activity (openclaw#139112)
  perf(terminal): avoid rebuilding sanitized link fallbacks (openclaw#139159)
  perf(agents): bound retained tool result projection data (openclaw#139157)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

1 participant