Skip to content

perf(skills): skip warm prompt search when minimum cannot fit - #157343

Merged
vincentkoc merged 1 commit into
mainfrom
perf/warm-skill-prompt-minimum-fits-guard-20260924
Sep 24, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/warm-skill-prompt-minimum-fits-guard-20260924

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Warm skill prompt compaction rendered the catalog eight times even when descriptions at the minimum width could not fit the available budget.

User Impact

Skip the remaining search in that case and return the same compacted prompt. Fitting budgets still select the widest fitting descriptions, and the original prompt remains preferred whenever it is no longer than the compacted result.

Why This Change Was Made

The existing minimum-width render already establishes whether any candidate can fit. Reuse that result to guard the search. Tests cover budgets below, equal to, and above the minimum; escaped text, Unicode boundaries, and whitespace; the original-shorter fallback; and resource identity and captured contents through resolveSkillsPrompt.

Accepted as a conditional rendering optimization because the minimum-budget case avoids seven futile renders; the fitting/no-budget and RSS costs below remain part of the tradeoff.

Evidence

  • Focused native tests: 36 matching passing tests per arm across skill-contract.test.ts and workspace-skill-prompt-resolution.test.ts.
  • Full prompt, resource, and input parity passed. The native run completed 62 commands, including two count workers and five alternating timing pairs, with command settlement and source/install endpoint checks.
  • With 24 skills and a budget below the minimum, catalog renders fell from 8 to 1 and description callbacks from 192 to 24. Warm CPU fell 61.84% (222.230 µs/call) and wall time 75.38%, both in all five pairs. The one-skill case also rendered once instead of eight times.
  • Costs remain: exact-minimum warm CPU increased 3.348% (+9.492 µs/call) and wall time 3.786%, both in all five pairs. Fitting-budget warm CPU increased 4.526% (+13.031 µs/call, four of five) and wall time 6.913% (all five). No-budget CPU increased 0.332 µs/call (four of five). The first exact-minimum call added 574 µs CPU and 437.46 µs wall time (all five). Whole-worker peak RSS increased 0.464844 MiB (all five), and terminal RSS increased 0.464844 MiB (four of five).
  • These are synthetic, fixed-order cases on Node 24.19.0 / Linux x64. First-call measurements occur after fixture setup, and shared-process heap/cache effects can affect controls. They do not establish production frequency, startup performance, or a universal improvement.

Single-worker validation costs from the retained native run (baseline → candidate; 18 passing tests per file):

Test file Vitest test-execution span Vitest total duration Driver command interval
src/skills/loading/skill-contract.test.ts 12.285 → 14.335 ms 38.76 → 27.68 s 42.704 → 30.234 s
src/skills/loading/workspace-skill-prompt-resolution.test.ts 360.143 → 284.714 ms 30.90 → 26.79 s 34.062 → 29.563 s

The first column of timings uses the JSON reporter's file start/end timestamps; the framework total includes transform/import work. The driver interval also includes command settlement and the subsequent resource census. Each file ran separately with --maxWorkers=1 --fileParallelism=false. These are one-run validation costs, not performance samples. Hosted CI passed for this exact head in 1,173 seconds of workflow wall time (15:01:44–15:21:17 UTC). That includes scheduling, setup, and parallel jobs; it is not summed runner time or per-file CPU time. Per-file hosted costs are not separately attributed.

Formatting passed with oxfmt 0.68.0 on all three changed files. Hosted type checks, lint, and the required CI gate passed for the published head.

Punchcard-Session: ember-river-harbor-t4
@vincentkoc vincentkoc self-assigned this Sep 24, 2026
@clawsweeper

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

@vincentkoc
vincentkoc marked this pull request as ready for review September 24, 2026 15:01
@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 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 11:30 AM ET / 15:30 UTC (Revision 2).

ClawSweeper review

What this changes

The branch skips wider skill-description renders when the minimum-width catalog exceeds the context budget and adds prompt and skill-resource parity tests.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still performs the extra work, the reviewed patch has no identified correctness defect, and the updated PR body resolves the prior test-cost finding.

Priority: P3
Reviewed head: ab52352675d73c9ce5cb217e78b958b39e5a0f2d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow patch has focused parity coverage and detailed, qualified measurements; the prior test-cost gap is addressed.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This member-authored internal optimization is exempt from the contributor proof gate. The PR body reports synthetic before-and-after runs through skill prompt resolution, including output parity and the measured render reduction; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored internal optimization is exempt from the contributor proof gate. The PR body reports synthetic before-and-after runs through skill prompt resolution, including output parity and the measured render reduction; no stored-data contract changes.
Evidence reviewed 8 items Current main behavior: The minimum-width catalog is rendered, but the search still runs when that catalog exceeds the target size.
Introduced guard: The pinned PR delta skips the wider-description search only when the minimum-width result exceeds the budget; the verified test merge retains this change.
Production entry point: Skill prompt resolution applies context-budget compaction to the selected catalog before returning the agent prompt.
Findings None None.
Security None None.

How this fits together

OpenClaw builds a skill catalog from eligible workspace skills and places it in an agent's prompt. Context-budget compaction shortens descriptions while the catalog's skill identities and readable resources remain available to the agent.

flowchart LR
  A[Eligible skills] --> B[Skill catalog]
  B --> C[Context budget]
  C --> D{Minimum fits?}
  D -->|Yes| E[Choose widest fitting descriptions]
  D -->|No| F[Keep minimum descriptions]
  E --> G[Agent prompt]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Tests +46. Total +48 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 8 +2
Tests 2 49 3 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 59 11 +48

Review metrics

Metric Value Why it matters
Below-minimum work 8 → 1 catalog renders; 192 → 24 description callbacks The PR body reports the intended reduction for its synthetic 24-skill case.
Fitting-budget cost +4.526% warm CPU, or +13.031 µs/call The PR body records the measured countervailing cost and states that production case frequency is unknown.

Technical review

Best possible solution:

Keep the guard in the existing skill prompt owner while preserving exact prompt and resource behavior and documenting its measured performance tradeoff.

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

Yes, from source: a below-minimum budget on current main still enters the wider-render search. This read-only review did not execute that path.

Is this the best way to solve the issue?

Yes. The existing minimum-width render supplies the fit decision, so the guard avoids extra work without adding a second compaction policy.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is a bounded internal performance improvement with no demonstrated user-facing regression.
  • 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. Not applicable: This member-authored internal optimization is exempt from the contributor proof gate. The PR body reports synthetic before-and-after runs through skill prompt resolution, including output parity and the measured render reduction; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Kimiyu-186: 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-24T15:09:05.809Z sha ab52352 :: needs changes before merge. :: [P3] Record the changed test files' measured wall time

@vincentkoc

Copy link
Copy Markdown
Member Author

Additional hosted test-cost evidence for head ab52352675d73c9ce5cb217e78b958b39e5a0f2d, from successful CI run 36017115016, attempt 1.

The metric below is the sum of displayed integer-millisecond testcase durations, counting each passing leaf testcase once.

Test file Passing cases Sum CI job
src/skills/loading/skill-contract.test.ts 18 3 ms (0.003 s) 107694745278, log lines 6459–6476
src/skills/loading/workspace-skill-prompt-resolution.test.ts 18 202 ms (0.202 s) 107694745438, log lines 2922–2935 and 2947–2950

A displayed 0 ms does not prove zero work. These rounded testcase sums are neither isolated file wall times nor CPU measurements. Shared setup, import, teardown, and group wall times are not attributed per file.

For context, core-unit-fast-2 selected 220 files and reported 93.37 s of Vitest duration; core-unit-src-security-2-hosted-2 selected 53 files and reported 48.64 s. Both executed plans configured a maximum of 2 workers. The separate local single-worker timings are already recorded in the PR body.

@vincentkoc
vincentkoc merged commit 76c0724 into main Sep 24, 2026
292 checks passed
@vincentkoc
vincentkoc deleted the perf/warm-skill-prompt-minimum-fits-guard-20260924 branch September 24, 2026 16:14
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit '9a1a6f7db9783d0b8abaf918bfe12978ea745b57': (26 commits)
  fix(maintainer): restore cold PR worktree provisioning (#157394)
  feat(ios): establish native Cloudflare Access sign-in sessions (#146996)
  fix: restore the Gateway after interrupted Doctor maintenance (#156854)
  refactor(line): retire the Express webhook adapter (#157369)
  refactor(cron): consolidate unavailable delivery targets (#157393)
  ci: apply Go memory defaults to architecture checks
  fix(cli): preserve the first PowerShell completion test failure (#157267)
  refactor(agents): consolidate transcript-tail model selection (#157382)
  fix(release): honor frozen validation contracts (#157034)
  fix(perf): use settled Kova terminal CPU accounting (#157029)
  chore(windows): verify packaged repair worker lifecycle (#157047)
  refactor(logging): share memory pressure threshold selection (#157164)
  fix(release): verify bundled fs-safe native bindings (#157027)
  perf(skills): skip warm prompt search when minimum cannot fit (#157343)
  fix(ui): avoid retaining detached tooltip anchors (#157226)
  perf(ci): reuse compiler state and shorten guard and UI tests (#157265)
  perf(ui): preserve model caches on unrelated metadata updates (#157254)
  chore: remove the tracked PR-body artifact and ignore .artifacts (#157296)
  refactor: consolidate duplicate MCP lifecycle tests (#157360)
  test(qa): consolidate CLI runtime fixtures (#118496)
  ...
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

1 participant