Skip to content

Bound the skills list width search - #8140

Merged
simonfaltum merged 34 commits into
mainfrom
skills/klistfast-skills-list-bound-the-width-search
Nov 30, 2026
Merged

simonfaltum merged 34 commits into
mainfrom
skills/klistfast-skills-list-bound-the-width-search

Conversation

@simonfaltum

@simonfaltum simonfaltum commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

This pull request changes only how renderText searches for the description width: the search now takes a few milliseconds on a 400-skill catalog with long descriptions, and the output is unchanged.

Changes

  • renderText finds the widest fitting description width with binary searches instead of trying every width from the widest down to 1. It picks the same width the full scan picked.
  • Each description is joined into one line once per call instead of once per layout.

Why

Every width tried laid out the whole list, and each layout re-joined every description. On a 400-skill catalog with descriptions of about 1.3 KB, the full scan took about 16 s. With this change the same catalog renders in about 4 ms.

The search splits at the first width that cuts every description. Below that width the search hint is always present, and above it the hint is never present, so the output length grows with the width within each part. Each part is searched with a binary search, and the upper part is searched first.

Decisions to review

  • The search keeps the full scan's result rather than using one plain binary search. The output length is not monotonic in the width, because a wider width can drop the search hint, so a plain binary search can settle on a narrower width. The split avoids that at the cost of a few more lines.

Tests

  • TestRenderTextMatchesWidthScan compares the output with the previous full scan on 300 seeded random catalogs: up to 60 skills, mixed descriptions, unbreakable descriptions, and long names. A sweep of 4000 seeds also passed locally and is not committed.
  • TestRenderTextFourHundredLongDescriptionsFitsBudget checks that a 400-skill catalog with long descriptions fits the text budget and lists its last skill.
  • BenchmarkRenderTextFourHundredLongDescriptions measures the same catalog. The timing is in the benchmark rather than a test, because a wall-clock assertion depends on the runner. On a loaded 8-core runner it measured about 13 ms per op, and about 320 ms per op under -race.
  • go test ./cmd/skills/... passes, including the existing TestRenderText* tests. go test ./acceptance -run 'TestAccept/cmd/skills' passes with no golden changes.
  • The skills command group is not registered unless DATABRICKS_SKILLS_PREVIEW is set, so nothing reaches this code with the variable unset. The equivalence test covers the output directly.

This pull request and its description were written by Isaac.

simonfaltum and others added 29 commits November 25, 2026 18:43
Skill sources need the manifest type and its path checks, and the
libs-no-aitools lint rule keeps shared libs from importing the installer.
Move Manifest, SkillMeta, NormalizeManifest, CheckManifestPaths, EscapesDir
and ErrUnsafeManifestPath down into libs/skills; the installer uses them
from there through aliases. Add the Skill and Catalog types, the Source
interface, sentinel errors, and NewFSSource over any fs.FS laid out like a
skills release. The manifest accepts optional per-skill commands and a
top-level catalog_rules file.

Co-authored-by: Isaac <no-reply@databricks.com>
The installer and libs/skills both reserve .state.json. Define the name once in
libs/skills and have the installer use it.

Co-authored-by: Isaac <no-reply@databricks.com>
The Windows CI checkout turns the LF fixtures into CRLF, so the exact
content assertions failed. Normalize line endings before comparing.

Co-authored-by: Isaac <no-reply@databricks.com>
Clean catalog_rules before reading it, expose min_cli_version on Skill,
document the Catalog fields and the release-relative paths the manifest
may name.

Co-authored-by: Isaac <no-reply@databricks.com>
Register the hidden skills command group only when DATABRICKS_SKILLS_PREVIEW
is set. Its five subcommands are stubs that report they are not implemented
yet. Add guards for the feature and for its hints switch, DATABRICKS_SKILLS_HINTS,
and a resolver for the folder in DATABRICKS_SKILLS_DIR, with an acceptance
fixture release that later changes reuse.

With the variable unset, the command group is not registered and nothing
else changes.

Co-authored-by: Isaac <no-reply@databricks.com>
The text output shows the catalog rules, one line per skill and a line on
how to read a skill. Descriptions are cut at a word boundary to the widest
width that keeps the output under a fixed budget, and only names are printed
when the names alone do not fit. The JSON output carries the full catalog.
Experimental skills are listed only with --experimental. A stale catalog
prints a provenance line on stderr.

The shared release fixture gains a catalog rules file and an experimental
skill.

Co-authored-by: Isaac <no-reply@databricks.com>
Skill sources need the manifest type and its path checks, and the
libs-no-aitools lint rule keeps shared libs from importing the installer.
Move Manifest, SkillMeta, NormalizeManifest, CheckManifestPaths, EscapesDir
and ErrUnsafeManifestPath down into libs/skills; the installer uses them
from there through aliases. Add the Skill and Catalog types, the Source
interface, sentinel errors, and NewFSSource over any fs.FS laid out like a
skills release. The manifest accepts optional per-skill commands and a
top-level catalog_rules file.

Co-authored-by: Isaac <no-reply@databricks.com>
The installer and libs/skills both reserve .state.json. Define the name once in
libs/skills and have the installer use it.

Co-authored-by: Isaac <no-reply@databricks.com>
The Windows CI checkout turns the LF fixtures into CRLF, so the exact
content assertions failed. Normalize line endings before comparing.

Co-authored-by: Isaac <no-reply@databricks.com>
Clean catalog_rules before reading it, expose min_cli_version on Skill,
document the Catalog fields and the release-relative paths the manifest
may name.

Co-authored-by: Isaac <no-reply@databricks.com>
Keep the path helper unexported since only libs/skills calls it, reject a
catalog_rules path that cleans to a directory, and test a missing rules
file. Drop the min_cli_version field, which is not in the skill interface
the package needs yet.

Co-authored-by: Isaac <no-reply@databricks.com>
Skill now has MinCLIVer, read from the manifest's min_cli_version, so a
caller can apply the same rule install uses. The fixture covers it.

Co-authored-by: Isaac <no-reply@databricks.com>
Register the hidden skills command group only when DATABRICKS_SKILLS_PREVIEW
is set. Its five subcommands are stubs that report they are not implemented
yet. Add guards for the feature and for its hints switch, DATABRICKS_SKILLS_HINTS,
and a resolver for the folder in DATABRICKS_SKILLS_DIR, with an acceptance
fixture release that later changes reuse.

With the variable unset, the command group is not registered and nothing
else changes.

Co-authored-by: Isaac <no-reply@databricks.com>
…ar-w

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…ests

Check the skills group in the root command uniqueness test, even though it
is registered only behind DATABRICKS_SKILLS_PREVIEW. Clear both guard
variables in the guard tests so an exported value does not leak in.
LocalCatalog calls Resolve first and maps ErrNoSource to no catalog.
Route the acceptance help check to LOG.help.

Co-authored-by: Isaac <no-reply@databricks.com>
Text output shows the catalog rules, then one line per skill with its
description cut to fit a fixed budget, then how to read a skill. JSON
output carries the full catalog with empty lists as []. Experimental
skills are listed only with --experimental.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Stop the description search at the narrowest width that keeps the first
word of every description, so no line is left as "name: ...". Print the
"left out" hint only when a description is actually left out. Render the
JSON through cmdio.Render like other commands, and drop the unit test that
duplicated the acceptance output. The list keeps the order the source
serves, which is sorted by name.

Co-authored-by: Isaac <no-reply@databricks.com>
Takes main's version of the skills command group (c2) and keeps this
branch's list implementation, its fixtures and the experimental preview
skill in the release fixture.

Co-authored-by: Isaac <no-reply@databricks.com>
Keep the skills list fixtures on top of the merged release fixture:
the enabled script no longer stubs list, the release manifest keeps the
experimental preview skill next to the read fixtures, and the resolve
test counts the whole catalog.

Co-authored-by: Isaac <no-reply@databricks.com>
skills list now runs, so the test's skills list call fails with the
no-source error instead of the not-implemented stub message. The test
only checks that no hint is printed, so update the comment and golden.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Drop the enabled script's stubs for list-files and read-file, which are
implemented now, and remove the unused notImplemented helper. Regenerate
the list golden for the release fixture's demo-skill commands.

Co-authored-by: Isaac <no-reply@databricks.com>
- Cut each description at a word boundary. A skill whose description has no
  boundary within the width is listed by name alone, so one long description
  does not drop the rest of the catalog.
- Collapse whitespace in text output so every skill takes one line.
- Print the provenance line through cmdio.LogString, and leave out the fetch
  time when it is unknown, as for a bundled copy.
- Use forward slashes in the JSON source label, as skills search does.
- Hint at --experimental when every skill is experimental.
- Drop the acceptance test.toml that repeats the parent's settings.

Co-authored-by: Isaac <no-reply@databricks.com>
The text length is not monotonic in width: a wider width can drop the
search hint, so a binary search could settle on a narrower width than
one that fits. Try each width from the widest down instead, and add a
test whose widths 35 to 37 are over the budget and 38 fits.

Co-authored-by: Isaac <no-reply@databricks.com>
When the names alone do not fit the budget, no description width can fit
either, so return the names-only text without trying each width. The early
return only applies when the names do not fit even with the search hint,
since a wider width can leave that hint out.

Change the widest-width test data so that a binary search settles on a
narrower width whose output differs. The old search passed this test by
landing on a width whose output matched the widest fitting one.

Co-authored-by: Isaac <no-reply@databricks.com>
renderText tried every width from the widest down to 1 until one fit.
Each try lays out the whole list, and every layout re-joined each
description, so a long catalog spent seconds on widths that were never
the answer.

Search the widths with binary searches instead. The layout length is not
monotonic in the width: once every description is cut the search hint
goes away. Below the first width that cuts every description the hint is
always there, and from that width on it is never there, so the length
only grows within each part. Search the upper part first, then the lower.
The result is the same width the full scan picked.

Descriptions are joined into one line once per call rather than on every
layout.

A 400-skill catalog with long descriptions now renders in a few
milliseconds. A randomized test checks the output against the full scan.

Co-authored-by: Isaac <no-reply@databricks.com>
Keep both sides of the merge. The shared acceptance release gains a
hyphen-prefixed file for guide-skill, so the list golden is regenerated
for the file list it prints.

Co-authored-by: Isaac <no-reply@databricks.com>
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 0416fe8

Run: 46416707168

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 90 6 2:13
💚​ aws-windows-latest-4core-16gb 1 90 6 3:23
💚​ azure linux-2core-8gb 1 90 6 1:45
💚​ azure-windows-latest-4core-16gb 1 90 6 3:19
💚​ gcp linux-2core-8gb 1 90 6 1:53
💚​ gcp-windows-latest-4core-16gb 1 90 6 2:50
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:21 aws-windows-latest-4core-16gb TestAccept
3:18 azure-windows-latest-4core-16gb TestAccept
2:49 gcp-windows-latest-4core-16gb TestAccept

@simonfaltum
simonfaltum marked this pull request as ready for review November 27, 2026 18:30
@simonfaltum
simonfaltum requested a review from a team as a code owner November 27, 2026 18:30

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at 5dd7276. Each finding was verified against the code.

No blocking issues found. 1 non-blocking comment(s) below.

This PR replaces the full width scan in renderText with a split binary search and joins each description into one line once per call rather than once per layout. I traced the split at complete against cutWords and layoutText, including the all-empty and never-fully-cut edge cases, and it returns the same width as the old scan. The one remaining issue is in the tests: the new speed test checks wall-clock time, so it can fail on a slow CI runner.

Comment thread cmd/skills/list_test.go Outdated
fastest = min(fastest, time.Since(start))
}
assert.LessOrEqual(t, len(out), textBudget)
assert.Less(t, fastest, 50*time.Millisecond)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] fastest < 50ms tests the runner, not the code. Under -race, -cover -coverpkg=./..., or on a loaded Windows/macOS runner, a render that takes 4 ms locally can go over 50 ms, and the test then fails even though the search is still bounded. Can we count layoutText calls through the fits closure instead, or move the timing into a BenchmarkRenderText...? Or is the margin wide enough that this isn't worth it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in fe1d82b. The wall-clock assertion is out of the test. TestRenderTextFourHundredLongDescriptionsIsFast is now TestRenderTextFourHundredLongDescriptionsFitsBudget, which checks the length and that the last skill is listed. The time is measured by BenchmarkRenderTextFourHundredLongDescriptions, which reports ns/op.

I did not count layoutText calls through fits: the search has no hook for that without changing renderText. On the runner I used, the load average was above 50. There the benchmark measured about 13 ms per op, and about 320 ms per op under -race, so the margin is not wide enough to assert on wall time in a test. The benchmark is the figure to watch: go test ./cmd/skills -run "^$" -bench RenderTextFourHundred.

simonfaltum and others added 2 commits November 27, 2026 19:06
The timing assertion measured wall-clock time on the test runner, so it
could fail under -race or on a loaded machine while the search was still
bounded. Keep the length check as a test and move the timing into
BenchmarkRenderTextFourHundredLongDescriptions, which reports time per op.

Co-authored-by: Isaac <no-reply@databricks.com>
Base automatically changed from skills/k1-skills-list-prints-the-catalog to main November 27, 2026 19:26
Take main's skills list files, which the squash merge of the list command replaced, and apply this branch's bounded width search on top of them.

Co-authored-by: Isaac <no-reply@databricks.com>
@simonfaltum
simonfaltum requested review from denik and rclarey November 28, 2026 09:02

@denik denik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Automated review of 2208734 by Opus and Astra (two independent passes); each finding verified against the code.

No blocking issues. I traced the split search against cutWords and layoutText: per-skill line length and dropsAny are monotone in width, the hint is present on every width below complete and absent from it on, so each part is monotone and the result equals the full scan. Also checked the PR merged into current main: go test ./cmd/skills/... ./libs/skills/... and TestAccept/cmd/skills pass.

Findings (not blocking, no user-visible failure today):

  1. Should fix cmd/skills/list_test.go:215: TestRenderTextMatchesWidthScan does not reach the edges of the split, so it would not catch a regression there. Mutation checks: complete := 2 + sort.Search(...) (off by one at the split) passes every test in the package; replacing both parts with one widestFitIn(1, top, fits) passes all 300 seeds (only TestRenderTextKeepsWidestFittingWidth catches it). The generator also never makes a description longer than textBudget (unbreakable ones are < 300 bytes, word ones < ~1.4 KB), so the complete == top+1 path (nothing cuts every description, the upper part is empty) is never taken. Two deterministic cases would pin it: one where only the width exactly at complete fits (the hint is just what pushes complete-1 over budget), and one with a > 4000-byte unbreakable description next to short ones, each compared with renderTextScan.
  2. Nit (comment) cmd/skills/list_test.go:227: "descriptions are each far longer than the text budget" — they are 1480–1560 bytes against a 4000-byte budget; together they exceed it, not each.

@denik
denik requested review from a team and denik November 30, 2026 08:39

@rclarey rclarey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[non-blocking] Did you consider a simpler fix than the split search? The slowdown had two causes. Each layout re-joined every description, and this PR fixes that with oneLineSkills. Each width tried also built the whole 400-line output just to read its length. The devil's-advocate reviewer measured an alternative: keep the old linear scan, check only the length, stop once the running total passes textBudget, and build the string only for the chosen width. It ran in about 4.4 ms/op against 8.6 ms/op for this PR on the same machine, and it passes TestRenderTextMatchesWidthScan. It also needs no widestFitIn or dropsAny, and no rule that the hint must be the only line a wider width can leave out. Its weak spot is many unbreakable long descriptions, because cutWords is O(width) per width, and the binary search handles that case better. The "Decisions to review" section only argues against a single plain binary search. Could you note why the split search beats the early-exit scan? Is a catalog of about 400 skills with about 1.3 KB descriptions expected soon? The bundled snapshot is empty, and #8103 picked the linear scan on purpose only just before this PR. (Raised by 3 sources: the devil's advocate, Isaac Review and the conventions reviewer. Nobody has asked it on the PR yet.)

Comment thread cmd/skills/list_test.go
}
return list
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] This test passes even if renderText falls back to names only. The names-only layout of this catalog is also under textBudget and also contains s399. Today the output keeps about 100 descriptions. Comparing against renderTextScan(rules, list), or asserting that some description text such as "s000: word0" is present, would make it catch that regression.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 607d861. The test now also asserts s000: word0 is in the output, so a fall back to names only fails it. I did not compare against renderTextScan because the full scan takes seconds on this catalog.

Comment thread cmd/skills/list_test.go
assert.Contains(t, out, "s399")
}

// BenchmarkRenderTextFourHundredLongDescriptions measures the width search on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] "the 50 ms the search must stay under" refers to the assertion removed in fe1d82b. Nothing else in the repo defines that bound. Consider dropping the number, or saying where it comes from (for example, "the full scan took about 16 s here").

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 607d861. The benchmark comment no longer cites the 50 ms figure. It now says the full width scan takes seconds on the same catalog.

Comment thread cmd/skills/list.go Outdated
// the smaller of maxLen and the budget.
top := min(maxLen, textBudget)
fits := func(w int) bool { return len(layoutText(rules, list, w)) <= textBudget }
// The length is not monotonic in width: once every description is cut, the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] "the first width that cuts every description" and "once the width cuts every description" read as "every description is truncated". The condition is really "no description is left out", which can mean some are shown whole. Something like "the first width at which no description is left out" would match cutWords's meaning of "cut".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 607d861. The comments now say "no description is left out" instead of "cuts every description", including the one on dropsAny.

Comment thread cmd/skills/list.go Outdated
if w := widestFitIn(complete, top, fits); w > 0 {
return layoutText(rules, list, w)
}
if w := widestFitIn(1, min(complete-1, top), fits); w > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] complete is at most top+1, so widestFitIn(1, complete-1, fits) is enough. Separately, the split is only correct while dropsAny matches layoutText's dropped rule. A note in layoutText saying the search hint must stay the only line a wider width can leave out, or one shared predicate for both, would stop a later edit from quietly breaking the search.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 607d861. The call is now widestFitIn(1, complete-1, fits), since complete is at most top+1. layoutText has a note that the search hint must stay the only line a wider width can leave out, and dropsAny says it must match the dropped rule there. I kept two predicates rather than sharing one, to avoid changing layoutText.

Co-authored-by: Isaac <no-reply@databricks.com>

@rugpanov rugpanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I found no correctness problem. The split search returns the same width as the old top-down scan, because dropsAny and the line length do not decrease as the width grows. The edge cases (top == 0, names over the budget) also match the old code. 607d861 fixes the 50 ms comment and the min, and the new s000: word0 check stops a silent fall back to names only. One nit is inline.

Two small points from the review by denik are still open. They do not block, and you can do them in a follow-up:

  • No test reaches complete == top+1 with top > 0. No test description is longer than textBudget.
  • The comment on fourHundredLongSkills says that each description is longer than the budget. Each one is about 1.5 KB, and textBudget is 4000.

Comment thread cmd/skills/list_test.go Outdated
assert.NotContains(t, out, "databricks skills search")
}

// renderTextScan is renderText before the width search was bounded: it tries

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This comment says that renderTextScan is the old renderText. It is not an exact copy: it calls the new oneLineSkills and the changed layoutText. Thus TestRenderTextMatchesWidthScan checks only the width search, and a bug in the shared helpers shows on both sides. Describe the function as a brute-force reference for the width search.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. The comment now calls renderTextScan a brute-force reference for the width search, and says it shares oneLineSkills and layoutText with renderText, so the test checks the search only.

Co-authored-by: Isaac <no-reply@databricks.com>
@simonfaltum
simonfaltum added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 05f2997 Nov 30, 2026
27 checks passed
@simonfaltum
simonfaltum deleted the skills/klistfast-skills-list-bound-the-width-search branch November 30, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants