Skip to content

skills: cache pinned sources in their own folder for tests - #8124

Open
simonfaltum wants to merge 7 commits into
skills/s3b-skills-fallback-chain-live-cache-bundledfrom
skills/s3acc-acceptance-coverage-for-the-skills-cache
Open

simonfaltum wants to merge 7 commits into
skills/s3b-skills-fallback-chain-live-cache-bundledfrom
skills/s3acc-acceptance-coverage-for-the-skills-cache

Conversation

@simonfaltum

@simonfaltum simonfaltum commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

This pull request gives pinned skills sources a cache folder of their own, so acceptance tests that pin the source to a fake server can cover the cache. It is stacked on the draft that adds the fallback chain, and merges after it, so the diff shows only this change.

Changes

  • With DATABRICKS_SKILLS_TEST_PINNED_CACHE set, a pinned source (DATABRICKS_SKILLS_REF or DATABRICKS_SKILLS_BASE_URL) caches its catalogs in a folder keyed by the source. That folder sits beside the release folder, so a pinned source never writes to the release folder, which stays keyed by release version only.
  • Without that variable, a pinned source still stores nothing, as before.
  • A local folder (DATABRICKS_SKILLS_DIR) never stores anything, since its files are not a release.
  • NewCache returns nil unless DATABRICKS_SKILLS_PREVIEW is set, so the whole cache is off with the feature.

Why

The cache was bypassed whenever DATABRICKS_SKILLS_BASE_URL or DATABRICKS_SKILLS_REF was set, and the skills acceptance tests pin the base URL to a fake server. No acceptance test could reach the cache or the fallback chain. The acceptance harness already gives each test its own DATABRICKS_CACHE_DIR, so the only missing piece was a cache for a pinned source that does not share the release folder.

Decisions to review:

  • A test-only variable, DATABRICKS_SKILLS_TEST_PINNED_CACHE, over caching pinned sources by default. Caching by default would change what users with a pinned source get, and this change does not do that. The cost is one more variable to know about. No acceptance test sets it yet; the acceptance cases follow once the commands read the chain.
  • The folder is keyed by a hash of both the ref and the base URL, so a ref pin and a base URL never share a folder.
  • A pinned branch ref or a mirror can keep stale files. ReadFile serves a cached file before it asks the source, and cacheFile checks only the release version, so such a source keeps its files until its version changes. Documented in the NewCache comment, not fixed here.

Tests

  • TestNewCacheOffWithoutPreview covers the guard: with DATABRICKS_SKILLS_PREVIEW unset, nothing is cached.
  • TestNewCacheWithoutCacheFolderStoresNothing covers a missing cache folder with the preview on.
  • TestNewCacheOffForPinnedSourceByDefault covers a pinned ref or base URL, and a local folder, storing nothing unless the test variable is set.
  • TestNewCachePinnedSourceUsesItsOwnFolder covers a pinned folder that differs from the release folder and from other sources, and the same source keeping its folder.
  • TestChainFreshCacheMakesNoLiveCall and TestChainCachedFileReadMakesNoLiveCall cover a warm cache making no live call.
  • Ran go test ./libs/skills/..., go test ./libs/aitools/installer/..., go test ./acceptance -run 'TestAccept/cmd/skills', ./task --force fmt-q lint-q and tools/check_deadcode.py. All pass.

Not tested: acceptance cases for a warm cache and for live-unreachable fallback, because the skills commands do not read the chain yet, so no acceptance test can reach it. Those cases follow once the commands are wired to it.

This pull request and its description were written by Isaac.

A pinned source, DATABRICKS_SKILLS_REF or DATABRICKS_SKILLS_BASE_URL, has
stored nothing so far, so no test that pins the source to a fake server can
cover the cache. With DATABRICKS_SKILLS_TEST_PINNED_CACHE set, a pinned
source now caches in a folder keyed by the source, beside the release
folder. It never shares the release folder, which is keyed by release
version only. Unset, a pinned source still stores nothing.

The whole cache is now off unless DATABRICKS_SKILLS_PREVIEW is set.

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: 8a205fb

Run: 46405857455

Env ✅​pass 🙈​skip Time
✅​ aws linux-2core-8gb 177 17 2:54
✅​ aws-windows-latest-4core-16gb 177 17 3:16
✅​ azure linux-2core-8gb 176 17 3:00
✅​ azure-windows-latest-4core-16gb 176 17 3:07
✅​ gcp linux-2core-8gb 177 17 2:59
✅​ gcp-windows-latest-4core-16gb 177 17 3:10
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:14 aws-windows-latest-4core-16gb TestAccept
3:08 gcp-windows-latest-4core-16gb TestAccept
3:06 azure-windows-latest-4core-16gb TestAccept

simonfaltum and others added 2 commits November 27, 2026 14:44
…3acc-acceptance-coverage-for-the-skills-cache
The missing-folder test returned nil from the preview gate, so it did not
reach the folder check. It now turns the preview on first. The pinned
cache comment names no acceptance test that sets the variable yet, and
documents that a pinned branch or mirror can keep stale files. The source
key reuses snapshot.HashFromContent.

Co-authored-by: Isaac <no-reply@databricks.com>
@simonfaltum
simonfaltum marked this pull request as ready for review November 27, 2026 15:22
@simonfaltum
simonfaltum requested a review from a team as a code owner November 27, 2026 15:22

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

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

This PR gives pinned skills sources their own cache folder under <version>/skills-pinned/<hash>. It is behind the test-only DATABRICKS_SKILLS_TEST_PINNED_CACHE switch, and it also gates NewCache on DATABRICKS_SKILLS_PREVIEW. The folder split works and the tests cover it. Two things are worth fixing: the folder key uses the raw base URL rather than the normalized one, and the preview gate is a second change bundled into this PR. There is also a small wording issue in a comment.

Comment thread libs/skills/cache.go
}
if env.Get(ctx, "DATABRICKS_SKILLS_REF") != "" || env.Get(ctx, "DATABRICKS_SKILLS_BASE_URL") != "" {
ref := env.Get(ctx, "DATABRICKS_SKILLS_REF")
baseURL := env.Get(ctx, "DATABRICKS_SKILLS_BASE_URL")

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] sourceKey hashes the raw DATABRICKS_SKILLS_BASE_URL, but GetSkillsBaseURL in ref.go strips trailing slashes before it fetches. So http://localhost:8080/ and http://localhost:8080 fetch from the same source but get different skills-pinned/<hash> folders, and a warm cache under one is cold under the other. Can this read the base URL through GetSkillsBaseURL(ctx), or apply the same strings.TrimRight(baseURL, "/"), so the key matches the URL actually fetched?

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.

Not changed in this PR. Normalising the base URL the same way GetSkillsBaseURL does is queued as a follow-up on this stack, so the key matches the URL that is fetched. Until then, http://localhost:8080/ and http://localhost:8080 keep separate folders, which costs only a cold cache.

Comment thread libs/skills/cache.go
//
//deadcode:allow the skills commands call it once they are wired to the chain
func NewCache(ctx context.Context) *Cache {
if !Enabled(ctx) {

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] The Enabled(ctx) check turns the release cache off whenever DATABRICKS_SKILLS_PREVIEW is unset, even with no pinned source, so it has nothing to do with caching pinned sources. It also brings its own test and the edit to TestNewCacheWithoutCacheFolderStoresNothing. Per AGENTS.md ("Keep each PR focused on one change"), can the gate move to its own PR, or into the one that wires the commands to the chain?

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.

Not moved. The repo rules require every pull request to prove its gate, and this is the gate for the cache: with DATABRICKS_SKILLS_PREVIEW unset, NewCache returns nil, and TestNewCacheOffWithoutPreview covers it. The edit to TestNewCacheWithoutCacheFolderStoresNothing is needed because that test returned at the gate before it reached the folder check. Nothing calls NewCache yet, so the gate changes nothing for users in this PR.

Comment thread libs/skills/cache.go Outdated
}

// pinnedCacheEnv turns the cache on for a pinned source, so a test that pins the
// source to a fake server has a cache to cover. No acceptance test sets it yet.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] "No acceptance test sets it yet" describes this PR's state, and the planned follow-up will make it false. Can you drop it, or replace it with what callers need to know, e.g. "Only tests set it; a pinned source can serve stale files, see NewCache"?

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 33891ee: the comment now says only tests set the variable. The stale-files note stays in the NewCache comment, which already says a pinned source can keep stale files.

simonfaltum and others added 3 commits November 27, 2026 15:33
The pinned cache comment said no acceptance test sets the variable yet,
which goes stale when the acceptance cases land. It now says only tests
set it.

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

# Conflicts:
#	libs/skills/cache.go
#	libs/skills/cache_test.go
Keep the pinned-cache switch and the source-keyed folder for pinned
sources, and check the local folder variable first so a local folder
never uses the cache. Clear the local folder variable in cache tests.

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

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

libs/skills/skills.go:7: [nit] The package doc still says "cache.go reads them to turn the cache off for a pinned source". After this PR, cache.go also uses DATABRICKS_SKILLS_REF/DATABRICKS_SKILLS_BASE_URL to key a skills-pinned/<hash> folder when DATABRICKS_SKILLS_TEST_PINNED_CACHE is set. A reader who trusts the package doc would think pinned sources are never cached. Suggest: "cache.go reads them to keep a pinned source out of the release folder: it stores nothing for one, or, in tests, stores it in a folder of its own."

Comment thread libs/skills/cache.go
// local folder (DATABRICKS_SKILLS_DIR). The cache is keyed by release version
// only, so a catalog from another source must not be stored under it. The
// returned nil Cache stores nothing.
// other caches of this CLI version (see libs/cache). It is off unless

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 NewCache doc is now 13 lines, and its last paragraph describes how ReadFile and cacheFile in the chain behave. That part will drift if the chain changes, and .agents/rules/comments.md asks doc comments to state the contract. Consider keeping only when the cache is on, off or per-source here, and moving the stale-files note to pinnedCacheEnv, which is the only way to reach it (e.g. "A pinned branch ref or mirror can serve stale files until its version changes; see chain.ReadFile.").

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 8a205fb. The NewCache doc no longer describes how the chain reads files. The stale-files note moved to pinnedCacheEnv and points at the chain's ReadFile.

Comment thread libs/skills/cache_test.go
assert.Nil(t, NewCache(env.Set(ctx, "DATABRICKS_SKILLS_DIR", "testdata/release")), "a local folder stores nothing")
}

func TestNewCachePinnedSourceUsesItsOwnFolder(t *testing.T) {

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] Three small test gaps. (a) defaultDir := NewCache(ctx).dir panics rather than failing cleanly if NewCache returns nil, so add require.NotNil first. (b) No case sets ref and base URL together, so a sourceKey that ignored one of them would still pass. (c) No case checks that DATABRICKS_CACHE_ENABLED=false still wins over DATABRICKS_SKILLS_TEST_PINNED_CACHE. Each is a one-line assert.

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 8a205fb. (a) The test now requires a non-nil default cache before reading its dir. (b) A case sets the ref and the base URL together and checks it differs from each alone. (c) A case checks DATABRICKS_CACHE_ENABLED=false still wins over the pinned cache switch.

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

This branch has not been deployed

No deployments
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.

3 participants