Skip to content

Resolve skills hints once per command run - #8134

Merged
simonfaltum merged 21 commits into
mainfrom
skills/h3once-resolve-skills-hints-once-per-command-ru
Nov 27, 2026
Merged

simonfaltum merged 21 commits into
mainfrom
skills/h3once-resolve-skills-hints-once-per-command-ru

Conversation

@simonfaltum

@simonfaltum simonfaltum commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Skill hints can change within one command run. MaybeHint checks them before a command, and when auto-install may give the agent its tools, the hint prints after the command. If auto-install refreshes the manifest cache in between, the hint text, its throttle and the skills command exemption can disagree. This PR resolves the hints value once per run, so they agree. With DATABRICKS_SKILLS_PREVIEW unset, behaviour is unchanged.

Changes

  • execute puts skills.WithHintsMemo on the run's context. skills.HintsEnabled answers from the memo after its first call.
  • With DATABRICKS_SKILLS_PREVIEW unset, HintsEnabled returns false before it reads the memo, so behaviour and goldens are unchanged.

Why

skills.HintsEnabled read the manifest cache on every call. The auto-install that runs after a command can refresh that cache before the deferred hint prints, so the hint and its throttle could use different answers within one run. Memoising the answer on the run's context fixes this. The memo resolves on the first call rather than in execute, so a run that never checks hints does not read the cache. It lives on the context, so tests and library callers never share a value between runs. Without a memo, HintsEnabled reads the cache on each call, as before. The memo is a design choice to review: the first call decides the run's value, so any environment change the run makes must come before that call.

Tests

  • TestHintsEnabledOncePerRun covers a cache refresh in the middle of a run: the run keeps its answer, a call without the memo sees the refreshed cache, and a new run sees it.
  • TestMaybeHint_DeferredSkillsHintIgnoresCacheRefresh covers a deferred hint whose cache is refreshed before it prints: the text, its kind and its throttle keep the first answer. It fails without the memo.
  • TestExecuteSkillHintsOncePerRun covers the same refresh inside a command run through execute, so it also proves the wiring.
  • go test ./libs/skills/... ./cmd/root/... ./libs/aitools/agents/... passes, and ./task fmt-q lint-q reports no issues.
  • go test ./acceptance -run 'TestAccept/cmd/skills' and TestAccept/help pass with no golden changes.

Not tested: a real auto-install that refreshes the cache. The refresh is simulated by rewriting the cache file in the tests.

This pull request and its description were written by Isaac.

simonfaltum and others added 18 commits November 26, 2026 11:18
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>
Add a skills_hints boolean to the compatibility manifest entry, following
auto_install: off when absent, ignored by CLIs that predate it. HintsEnabled
stays off unless the skills feature is on. Then DATABRICKS_SKILLS_HINTS, when
set, decides in both directions; otherwise the entry for this CLI version does.

The entry is read from the local manifest cache or the embedded manifest only.
Hints are resolved while help is printed, so they never fetch the manifest.

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

The manifest cache is written as the bytes that were fetched, not re-encoded
from the parsed manifest, so fields a CLI does not know (skills_hints for a
CLI that predates it) survive a refresh.

Hints are resolved without fetching, so a cache older than the one-hour TTL
is ignored there and the embedded manifest (off) applies. A remote change
reaches hints only through a command that refreshes the cache.

Also: log why hints stay off when the manifest cannot be read, pin the cache
and skills environment in the tests so a developer's shell cannot change them,
and document the stale-cache rule in the field comment, the README and the
bump-cli-compat skill.

Co-authored-by: Isaac <no-reply@databricks.com>
…st env helper

A CLI that predates skills_hints re-encodes the manifest cache when it
refreshes it and drops the field, so this CLI reads hints as off until it
refreshes the cache itself. Say so in the cache write comment and the
build README.

The guard tests now use testutil.CleanupEnvironment instead of a
package-local unsetEnv helper.

Co-authored-by: Isaac <no-reply@databricks.com>
Hints no longer fall back to the embedded manifest: without a fresh local
cache they stay off, so a released CLI can be turned off remotely too. The
cache is written in its previous form again; the raw-bytes write did not
help skills_hints, since this CLI's entry already carries the field.

The cache path comes from clicompat.LocalManifestPath, so the guard tests do
not repeat the file name. The read-path explanation now lives in the README,
and the code comments point there.

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

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>
…h3-remote-switch-for-skills-hints

Resolve the guard test conflict by keeping the clean-environment helper and
setting only the variables each case names.

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

# Conflicts:
#	libs/skills/guard.go
#	libs/skills/guard_test.go
Name skills_hints in the manifest bump steps of internal/build/README.md.
Test an empty DATABRICKS_SKILLS_HINTS as set, so it forces hints off.
Share the test cache writer with testutil.WriteFile and state the contract
of forceEmbedded and cacheEnabled.

Co-authored-by: Isaac <no-reply@databricks.com>
HintsEnabled read the manifest cache on every call. Auto-install can
refresh that cache between the hint check and the hint printed after the
command, so the help footer, the hint text, its throttle and the skills
command exemption could disagree within one run.

execute puts a memo on the context, and HintsEnabled answers from it
after its first call in the run. Without the memo, HintsEnabled reads the
cache on every call as before, and with DATABRICKS_SKILLS_PREVIEW unset
nothing changes.

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: d92ac33

Run: 46056038023

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 173 17 3:39
💚​ aws-windows-latest-4core-16gb 1 173 17 3:14
💚​ azure linux-2core-8gb 1 172 17 3:29
💚​ azure-windows-latest-4core-16gb 1 172 17 2:53
💚​ gcp linux-2core-8gb 1 173 17 3:41
💚​ gcp-windows-latest-4core-16gb 1 173 17 3:15
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 6 slowest tests (at least 2 minutes):
duration env testname
3:29 azure linux-2core-8gb TestAccept
3:26 aws linux-2core-8gb TestAccept
3:23 gcp linux-2core-8gb TestAccept
3:14 gcp-windows-latest-4core-16gb TestAccept
3:13 aws-windows-latest-4core-16gb TestAccept
2:52 azure-windows-latest-4core-16gb TestAccept

Auto-install can refresh the manifest cache between MaybeHint and the
deferred hint. Memoise the hints value on the run's context so the
deferred text, its kind and its throttle keep the value MaybeHint saw.
Drop the unused lock and a duplicated preview-off test, use testutil.WriteFile
in the root test, and reword the root comment to name the deferred hint.

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added the aitools AI tools (databricks aitools) related changes label Nov 27, 2026
The memo test with the preview unset proves the feature gate still wins
over a memoised context. Restore it, and note in WithHintsMemo that
HintsEnabled must run on the command goroutine since the memo has no lock.

Co-authored-by: Isaac <no-reply@databricks.com>
@simonfaltum
simonfaltum marked this pull request as ready for review November 27, 2026 17:52
@simonfaltum
simonfaltum requested review from a team and lennartkats-db as code owners November 27, 2026 17:52

@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 f6345f3. Each finding was verified against the code.

No blocking issues found.

This PR adds a memo to the run's context so skills.HintsEnabled gives the same answer for the whole command run. That keeps a deferred hint's text, kind and throttle consistent even if auto-install refreshes the manifest cache before the hint prints. I traced MaybeHint and show in libs/aitools/agents/hint.go: before the change, message(ctx) was called twice, so the text and its throttle could disagree. The memo resolves that, and the tests cover the refresh both at the library level and through execute. I found no concrete defect. The memo isn't locked, but I found no caller that reaches HintsEnabled from another goroutine.

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

The change is correct, and I found no blocking issue. The memo makes the pre-run hint check and the deferred hint use the same value. With DATABRICKS_SKILLS_PREVIEW unset, behavior does not change. I left two optional suggestions and one nit inline.

Risk: LOW. The change has an effect only when the hidden DATABRICKS_SKILLS_PREVIEW env var is set. It touches only the stderr skills hint path and adds no persisted state, so a revert is simple. Unit tests cover the memo, preview off and the deferred hint, and all CI checks pass.

Comment thread libs/skills/guard.go
if !ok {
return resolveHints(ctx)
}
if !memo.resolved {

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] HintsEnabled reads and writes memo.resolved and memo.on with no lock. The memo is a context value, so every goroutine that gets a derived context shares it. No current caller runs off the command goroutine. But a future parallel caller causes a data race, and only the doc comment at line 43 prevents it. Use a sync.Once field, for example once sync.Once; on bool with memo.once.Do(func() { memo.on = resolveHints(ctx) }), and remove the caveat. Call Do with the caller's ctx, so that resolveHints logs to the logger of that call.

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.

Done in d92ac33. The memo now takes a mutex, and HintsEnabled passes the caller's ctx to resolveHints, so the first call's logger is used. I did not use sync.Once: this repo's forbidigo rule rejects it and points to sync.OnceValue, which cannot take the caller's ctx. The caveat about the command goroutine is gone; the memo is safe for concurrent use.

Comment thread cmd/root/root.go
// Skill hints resolve once for this run, so a deferred hint, its text and
// its throttle agree even when auto-install refreshes the manifest cache
// before the hint prints.
ctx = skills.WithHintsMemo(ctx)

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] The mismatch comes from one function. MaybeHint calls hint.message(ctx) for textDue, and the deferred show calls message(ctx) again after auto-install. If MaybeHint resolves msg once and gives it to show, the text, the throttle and the exemption use the same pre-run value. That fix needs no context memo, no change in execute and no run-wide rule for HintsEnabled. Today no other caller needs a run-wide value: the help footer runs before auto-install. Consider the local fix, or name in the PR the later caller that needs the run-wide memo.

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.

Kept the run-wide memo; the local fix alone does not meet the acceptance criterion. The ticket asks that HintsEnabled return the same value for the whole run, and TestExecuteSkillHintsOncePerRun checks HintsEnabled itself. A fix inside MaybeHint would make the deferred text consistent, but any later HintsEnabled call in the same run would still re-read the cache. The memo is one context value and a mutex, and the local fix is not needed on top of it. Callers today: the deferred show path (after auto-install) and the help footer and skills.WriteGroupHint (during the command, before auto-install). No change in d92ac33 for this point beyond the memo guard.

Comment thread cmd/root/root.go Outdated
ctx = context.WithValue(ctx, caughtSignalKey{}, &caught)
var deferredHint func()
ctx = context.WithValue(ctx, deferredHintKey{}, &deferredHint)
// Skill hints resolve once for this run, so a deferred hint, its text and

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 repeats the reason in the doc comment of skills.WithHintsMemo (libs/skills/guard.go:38-43). .agents/rules/comments.md asks for concise comments. Shorten it to one line, for example // One skills hints value per run; see skills.WithHintsMemo.

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.

Shortened to one line in d92ac33: // One skills hints value per run; see skills.WithHintsMemo.

HintsEnabled may now be called from any goroutine that holds the run
context, so the memo takes a lock instead of relying on the command
goroutine. The lock is held on the caller's context, so the first call's
logger is used. Shorten the root comment to point at WithHintsMemo.

Co-authored-by: Isaac <no-reply@databricks.com>
@simonfaltum
simonfaltum added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit e6f3460 Nov 27, 2026
28 checks passed
@simonfaltum
simonfaltum deleted the skills/h3once-resolve-skills-hints-once-per-command-ru branch November 27, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aitools AI tools (databricks aitools) related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants