Repository navigation
Add the skills fallback chain over live, cache and bundled sources - #8115
Conversation
✅ Integration test reportCommit: d38a174
Top 3 slowest tests (at least 2 minutes):
|
|
Review follow-up in 17df02e:
|
There was a problem hiding this comment.
Automated review at 17df02e. Each finding was verified against the code.
No blocking issues found. 3 non-blocking comment(s) and 1 question(s) below.
This PR adds NewChain, a Source that serves skills from the live source, then the disk cache, then the bundled copy, with a 10-minute freshness window and release checks on fallbacks. Nothing calls it yet, so nothing changes for users. The fallback paths look right, but ReadFile has three gaps. Under a fresh cached catalog it can return bytes from a newer live release. When the release moves, it throws away the newer catalog it just fetched, so reads keep making extra live calls. And when the clock moves back, a newer release can end up ranked below an older one in the cache. Separately, I've raised one question about the bundled copy's FetchedAt.
Questions
- The bundled copy now carries
FetchedAt = time.Now()(fromfsSource.Catalog,fs.go:32) instead of zero, so a snapshot compiled into the binary looks freshly fetched, and the field doc keeps "zero means unknown" for no remaining producer. The provenance line this is meant to serve doesn't exist yet (skills listisnotImplemented). Should the bundled copy keep zero, with the future printer skipping a zero time (or keying onBundledLabel), or is the read time the intended provenance? (non-blocking)
Comments outside the changed lines
- [nice to have]
libs/skills/chain.go:214: Whencur.Versiondiffers from the cached catalog,curis dropped instead of being stored withputCatalog. For the rest of the 10-minute window, everyReadFilerepeats both the live file read and this live catalog read, and still caches nothing. Even when versions match, an uncached read right after a stale-cachecatalog()makes three live calls (line 131, line 183, here). CouldcacheFilestorecurwhen it is newer, so the next call picks it up?
| } | ||
| if bundled.Version != cat.Version { | ||
| return nil, fmt.Errorf("read %q of skill %q: bundled release %s is not release %s", file, skill, bundled.Version, cat.Version) | ||
| } |
There was a problem hiding this comment.
[nice to have] When catalog() returns a fresh cached catalog, the file is read live with no check that live is still on that release. Only cacheFile compares versions, and that check only decides whether the bytes get stored; they are returned either way. Example: the cache holds catalog 1.0.0, live moves to 2.0.0 within the window, and ReadFile returns the 2.0.0 body under the 1.0.0 catalog. TestChainReadFileLiveReleaseChangeIsNotCachedUnderCachedCatalog asserts exactly this. If 2.0.0 removed a file that 1.0.0 lists, the caller gets ErrUnknownFile for a file its catalog still shows. I thought the live path would get the same release guard as the bundled fallback. Should a version mismatch refresh the catalog, or fail, instead of returning the bytes?
There was a problem hiding this comment.
Not changed. This is the design the ticket sets for ReadFile: a file read that misses the cache is read live and returned, and only the cache write is gated on the live catalog still reporting the catalog's release. Refusing the read or refreshing the catalog would add a live catalog call to every uncached read, or turn a successful read into an error, and that choice is not made in this PR. The mismatch is bounded by the 10-minute freshness window of the cached catalog, and TestChainReadFileLiveReleaseChangeIsNotCachedUnderCachedCatalog asserts the behavior. If you want a refresh on mismatch, that is a follow-up with its own decision.
| } | ||
| data, liveErr := c.live.ReadFile(ctx, skill, file) | ||
| if liveErr == nil { | ||
| c.cacheFile(ctx, read.cat.Version, skill, file, data) |
There was a problem hiding this comment.
[nice to have] Cache.catalogs orders catalogs newest first by FetchedAt, so a catalog stamped after the clock moved back sorts below older entries. Example: 1.0.0 is cached at t0, the clock moves back an hour, and live returns 2.0.0, stored with FetchedAt t0-1h. Latest() keeps returning 1.0.0, so ReadFile serves cached 1.0.0 files with no live call, and offline Catalog serves 1.0.0. Once the clock passes t0 again, 1.0.0 is even served as fresh. TestChainFutureFetchedAtIsNotFresh keeps the same version on both reads, so it doesn't catch this. Should a future FetchedAt be ignored when picking Latest, or should the latest write win?
There was a problem hiding this comment.
Fixed in d953bf2. A live catalog is stored no earlier than the newest cached catalog (storedCopy in chain.go), so a clock that moved back cannot make an older release the newest cached one. The release order breaks the tie, so 2.0.0 stays ahead of 1.0.0. The returned catalog keeps its real fetch time. TestChainClockMovedBackKeepsNewestRelease covers the case: 1.0.0 cached at t0, clock back an hour, live 2.0.0, and Latest must return 2.0.0. The fix stays in the chain, so the cache format and cache.go are unchanged.
| // storedCopy returns the copy of live to cache. When a clock moved back has | ||
| // stamped the newest cached catalog later than now, live is stored no earlier | ||
| // than that one, so Latest keeps the newest release. The release order breaks the tie. | ||
| func storedCopy(newest, live *Catalog) *Catalog { |
There was a problem hiding this comment.
[non-blocking] storedCopy gives the stored catalog the same FetchedAt as the newest cached one and relies on the cache's version tie-break to keep the newer release, but that tie-break is a string compare, so 0.2.9 sorts above 0.2.10: after a clock moved back the older release stays Latest, and once the clock passes its stamp it is served as fresh for ten minutes with no live call. Compare versions as semver in the cache sort, or stamp the stored copy just after the newest one rather than equal to it.
There was a problem hiding this comment.
Fixed in ea4a9bf. storedCopy no longer relies on the version tie-break. A live catalog that would tie with, or sort behind, the newest cached one is now stamped one nanosecond after it, so the newest write is always the newest entry whatever the release versions are. The cache sort and cache.go are unchanged. TestChainClockMovedBackKeepsNewestReleaseWhenVersionsSortAsStrings covers 0.2.9 then 0.2.10 after the clock moves back; it fails on the previous code.
There was a problem hiding this comment.
🤖 Nit (convention) Since #8076 sorts ties with compareVersions (semver first, cache.go catalogs), the parenthetical at L104 ("the cache breaks ties by version as a string") is no longer true. The same goes for the rationale comment in TestChainClockMovedBackKeepsNewestReleaseWhenVersionsSortAsStrings (chain_test.go L326). The one-nanosecond step is still needed when the live stamp is strictly earlier, so only the comments need updating.
There was a problem hiding this comment.
Fixed in d6ed294. The storedCopy comment and the rationale comment in TestChainClockMovedBackKeepsNewestReleaseWhenVersionsSortAsStrings no longer say the cache breaks ties by version as a string. They now say the one-nanosecond step keeps the newest write the newest entry whichever release version sorts higher.
| assert.Equal(t, firstFetch, cat.FetchedAt, "the age is the time the cached copy was fetched") | ||
| } | ||
|
|
||
| func TestChainLiveUnreachableWithNoCacheUsesBundledAsStale(t *testing.T) { |
There was a problem hiding this comment.
[non-blocking] No test covers ReadFile when the live source is unreachable and nothing is cached, which is the offline path the chain exists for; this test and TestChainNothingAvailableNamesLiveFailure only call Catalog. Add a ReadFile case here that expects the bundled body.
There was a problem hiding this comment.
Added in ea4a9bf. TestChainReadFileNothingCachedFallsBackToBundled covers ReadFile with the live source unreachable and nothing cached: it returns the bundled body. The chain already took this path, so the test pins existing behavior rather than fixing a bug.
rugpanov
left a comment
There was a problem hiding this comment.
Thanks for the clear "Decisions to review" section. I found no blocking problem. The inline comments are non-blocking: two questions about the cache contract, two nice-to-have points and one nit.
Risk: LOW. chain.go is library code that nothing calls yet (//deadcode:allow). The skills command group is hidden, and its subcommands are still stubs at this head. A revert is simple.
CI: all check runs on ea4a9bf passed or were skipped by path rules.
Note: the base branch is 19 commits behind main, and main already has releaseSource. After the rebase, a test of the chain against the real source would also show the live call counts in the cacheFile comment.
| func (c *chain) ReadFile(ctx context.Context, skill, file string) ([]byte, error) { | ||
| cached, _ := c.cache.Latest() | ||
| if cached != nil { | ||
| if data, ok := c.cache.readFile(cached.Version, skill, file); ok { |
There was a problem hiding this comment.
[Question] ReadFile returns a cached file of cache.Latest() with no age check and no live call. On main, cmd/skills/read_file.go calls only ReadFile, not Catalog. After a new release, skills read-file can then return the old bytes of a cached file until some other command refreshes the catalog. Is this the intended contract when the chain is wired? If not, serve a cached file without a live call only while the cached catalog is fresh, or when the live source is unreachable. Else call c.catalog first.
There was a problem hiding this comment.
Not changed in this PR. A cached file of the newest cached release is served with no live call, as the ticket sets for this chain. Without a freshness check, a file read can keep returning bytes of a release that the catalog has since left, until a catalog read refreshes the cache. That is a real trade-off. Whether the read path needs a freshness check once the commands use the chain is carried to the follow-up work that wires the commands and sets their live budgets. Nothing calls the chain yet, so no user sees this behavior in this PR.
There was a problem hiding this comment.
🤖 +1. Within a single skills read, the file can also come from a different release than the catalog the command just printed. ReadFile takes the release from cache.Latest() again instead of using the catalog Catalog just served. If that catalog's putCatalog failed (the write error is only logged at debug, L83), or another process cached a different release between the two calls, Latest() is an older entry. Its cached SKILL.md is then returned with the newer catalog's version and file list. Reproduced with a cache folder made read-only after a first read: the live source moves 1.0.0 → 2.0.0, Catalog returns 2.0.0, and ReadFile returns the 1.0.0 body. Remembering on the chain the release it served from Catalog, and reading files of that release, would close this. It would also remove the second catalog read that ReadFile makes on a cold or stale cache.
There was a problem hiding this comment.
Agreed that this is a real gap, and it is not changed in this PR. Reading the files of the release the chain already chose needs a source method that takes the release, and Source has none; that interface belongs to the parent PR (#8076). Nothing calls the chain yet, and the wiring task is where the read path gets the catalog's release and a freshness rule. Carrying it there.
| if c.cache == nil { | ||
| return | ||
| } | ||
| cur, err := c.live.Catalog(ctx) |
There was a problem hiding this comment.
[nice to have] cacheFile makes one more live Catalog call after each live file read. An uncached ReadFile then makes 2 live calls inside the 10-minute window and 3 after it. This also occurs when c.catalog read the live source a moment before, in the same call.
On main, each releaseSource call sends an unauthenticated releases/latest request, and a rate-limit 403 becomes ErrSourceUnreachable. An install that reads many files can use up the 60-per-hour limit and then fall back to stale content.
Skip this check when read came from the live source in this call. Or read the files at the pinned release read.cat.Version. Also, when cur.Version is different, store cur, so the next reads do not repeat both calls.
There was a problem hiding this comment.
Not changed here. The check after the file read is a review fix this PR carries: a release that moves between the catalog read and the file read must not be cached under the old release. Skipping the check when the catalog came live in this call would miss exactly that move. Reducing the cost of the extra call, by reusing a catalog read made a moment earlier and storing a newer catalog when the check finds one, is carried to the follow-up work that sets the live call budget.
There was a problem hiding this comment.
🤖 +1, and the check also doesn't prove what it is there to prove. The file read and this catalog read each resolve the release separately (openRelease → GetSkillsRef). A matching version afterwards doesn't say which release served the bytes: a cli-compat pin can move the resolved ref back as well as forward, so "releases move forward" (L171) doesn't hold for GetSkillsRef. Reading the file from the release the chain already chose (or having the source return the ref with the bytes) would close that and drop this second release lookup and manifest download at the same time.
There was a problem hiding this comment.
Agreed that the post-read catalog check does not prove which release served the bytes, and it costs a second lookup. The fix is a source that returns the resolved release with the bytes, or reads a file at a given release. That changes the Source interface, which belongs to the parent PR (#8076), so it is not changed here; the wiring task picks it up together with the live call budget. Until then the check is a best-effort guard, and nothing calls the chain yet.
| func storedCopy(newest, live *Catalog) *Catalog { | ||
| cp := *live | ||
| if newest != nil && !cp.FetchedAt.After(newest.FetchedAt) { | ||
| cp.FetchedAt = newest.FetchedAt.Add(time.Nanosecond) |
There was a problem hiding this comment.
[nice to have] storedCopy keeps a future FetchedAt. If the newest cached catalog has a time after now (for example, the clock moved back), each new copy gets that time plus 1 ns. The age at line 75 is then negative. So every Catalog call and every uncached ReadFile goes live until the wall clock passes that time. The 10-minute cache is off for as long as the skew lasts.
Consider a sort of Cache.catalogs by semver in #8076 (ref.go already uses golang.org/x/mod/semver). Then storedCopy can keep the real time.
There was a problem hiding this comment.
Not changed. A clock that moved back makes the newest cached catalog younger than now, and a negative age is not fresh (the ticket rule, tested by TestChainFutureFetchedAtIsNotFresh). So the cache is skipped until the clock passes that time, and that window is the clock offset itself. The one-nanosecond step in storedCopy only orders the write. Cache.catalogs sorts by FetchedAt, and keeping the real time made Latest return the older release, which is the bug fixed in d953bf2. Ordering by semver would change what Latest means in cache.go, which this PR leaves unchanged. Each write during a skew adds one nanosecond, which is negligible. If the cache order should change, that is a separate change to the cache contract.
| return nil, err | ||
| } | ||
| // A stale catalog means the live source already failed, so it is not asked again. | ||
| if read.cat.Stale { |
There was a problem hiding this comment.
[nit] This branch uses read.cat.Stale to mean "the live read failed". The Stale doc in skills.go lets any source set Stale, also a caching source that is used as live. In that case read.liveErr is nil, and line 160 prints live source: %!w(<nil>); .... Test read.liveErr != nil instead.
There was a problem hiding this comment.
Fixed in 87fc602. ReadFile now falls back only when the live catalog read failed in this call (liveErr), not on Stale alone, so a live source that reports Stale with no error has its files read live. TestChainLiveStaleCatalogStillReadsFileLive covers it. The fallback message can no longer print a nil live error.
| return nil, fmt.Errorf("read %q of skill %q: bundled source: %w", file, skill, err) | ||
| } | ||
| } | ||
| if bundled.Version != cat.Version { |
There was a problem hiding this comment.
[Question] A cached catalog with no cached files can make offline reads fail. Example: online, skills list caches the 1.0.0 catalog. Later, offline, skills read alpha gets the stale 1.0.0 catalog, misses the file cache, and fails here with bundled release 0.9.0 is not release 1.0.0. With an empty cache, the same read works from the bundled copy (TestChainReadFileNothingCachedFallsBackToBundled). Is this trade-off intended? If not, consider a fallback to the bundled catalog and its files together in this case.
There was a problem hiding this comment.
Intended by the ticket, and not changed here. A bundled file is served only when the bundled release equals the cached catalog release, so bytes of one release are never returned under another release catalog. The cost is that an offline read with a cached catalog newer than the bundled copy, and no cached file, fails, while an empty cache reads the bundled copy. Whether an offline read should fall back to the bundled catalog and its files together is carried to the follow-up work that wires the chain into the commands. Nothing calls the chain yet.
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of 3668a57 by Opus and two independent Astra (gpt-6-astra) passes, plus a gpt-6-astra advocate; Fable was unavailable this round. Each finding was verified against the code, and the first two were reproduced on main with this PR merged in.
Verdict: the fallback rules are careful, but they key on Catalog.Version, and the live and bundled sources this chain is meant for set that to the manifest's schema version, "2" for every published release. Wired as it stands, it serves an old release's cached files after a new release (inline, L82).
Readiness:
- Stacked on #8076. I reviewed only this PR's diff against
skills/s3-disk-cache-and-fallback-chain. It merges cleanly into currentmain, andgo test -race ./libs/skills/... ./cmd/skills/...passes there.
Other findings, not posted inline:
- Should fix
libs/skills/chain.go:108: +1 to rugpanov's point that after the clock moves back, every stored copy is stamped in the future, so the 10-minute cache stays off for as long as the clock offset lasts (+1'd on the thread). - Nit
libs/skills/bundled_source.go:56: +1 to review-oss-bot's question on the bundledFetchedAt. The reason given in the description (avoid printing a zero time) is already handled onmain:cmd/skills/list.goprovenanceLinehas a branch, with a comment, that leaves the time out for the bundled copy, and #8136 givesskills readthe same branch. With the read time instead,skills listwould say a snapshot compiled into the binary was "fetched" just now. Keeping zero for the bundled copy looks simpler.
| live, liveErr := c.live.Catalog(ctx) | ||
| if liveErr == nil { | ||
| live.FetchedAt = c.now() | ||
| if err := c.cache.putCatalog(storedCopy(cached, live)); err != nil { |
There was a problem hiding this comment.
🤖 Blocking The chain keys the cache and every release check by Catalog.Version. For the sources it will be wired to, that field is the manifest's schema version, not the release tag. On main, releaseSource reads through fsSource, and fsSource.Catalog sets Version: m.Version. Every published databricks-agent-skills manifest has "version": "2" (I checked v0.2.53, v0.2.54 and v0.2.56). The bundled snapshot from #8075 copies that manifest as it is. So once NewChain(NewReleaseSource(), NewCache(ctx), NewBundledSource()) is wired:
- every release lands in the same
2/folder. After a new release,Catalogrefreshes2/catalog.json, butReadFile(L131) keeps serving the older release's cached files with no live call. Nothing replaces those files, so this lasts until the cache folder changes, for example with a new CLI version; - the release checks in
cacheFile(cur.Version != version) andreadBundled(bundled.Version != cat.Version) compare"2"with"2". They always pass, so bundled bytes of another release are served under the cached catalog.
Reproduced on main with this PR merged in. Two NewFSSource releases whose manifests both say "version":"2" (SKILL.md bodies "v0.2.56 body" and "v0.2.57 body"): Catalog and ReadFile on the first, then switch live to the second, move the clock an hour forward and call Catalog again. ReadFile then returns "v0.2.56 body".
Suggested fix: give the chain the resolved release tag as the identity of what it caches and compares, for example with releaseSource setting Catalog.Version to the ref that openRelease resolved, and the snapshot recording its tag. Add a chain test whose two releases have the same manifest version.
There was a problem hiding this comment.
Agreed, and it has to be fixed before the chain is wired. It is not fixable inside the chain: the chain treats Catalog.Version as the release identity, as the Catalog doc in skills.go says, and cannot tell a schema version from a release tag. The release source that sets Catalog.Version, and the bundled snapshot that records its tag, are not in this branch; they are part of the wiring task, which will set Catalog.Version to the resolved release ref in both and add the chain test with two releases that share a manifest version. Nothing calls the chain yet, so no user is affected in this PR.
There was a problem hiding this comment.
Correction to my earlier reply: the release-source tag is fixed in #8191. The bundled snapshot tag, the chain-level two-release test and the wiring follow in a later change.
| func (c *chain) ReadFile(ctx context.Context, skill, file string) ([]byte, error) { | ||
| cached, _ := c.cache.Latest() | ||
| if cached != nil { | ||
| if data, ok := c.cache.readFile(cached.Version, skill, file); ok { |
There was a problem hiding this comment.
🤖 +1. Within a single skills read, the file can also come from a different release than the catalog the command just printed. ReadFile takes the release from cache.Latest() again instead of using the catalog Catalog just served. If that catalog's putCatalog failed (the write error is only logged at debug, L83), or another process cached a different release between the two calls, Latest() is an older entry. Its cached SKILL.md is then returned with the newer catalog's version and file list. Reproduced with a cache folder made read-only after a first read: the live source moves 1.0.0 → 2.0.0, Catalog returns 2.0.0, and ReadFile returns the 1.0.0 body. Remembering on the chain the release it served from Catalog, and reading files of that release, would close this. It would also remove the second catalog read that ReadFile makes on a cold or stale cache.
| if c.cache == nil { | ||
| return | ||
| } | ||
| cur, err := c.live.Catalog(ctx) |
There was a problem hiding this comment.
🤖 +1, and the check also doesn't prove what it is there to prove. The file read and this catalog read each resolve the release separately (openRelease → GetSkillsRef). A matching version afterwards doesn't say which release served the bytes: a cli-compat pin can move the resolved ref back as well as forward, so "releases move forward" (L171) doesn't hold for GetSkillsRef. Reading the file from the release the chain already chose (or having the source return the ref with the bytes) would close that and drop this second release lookup and manifest download at the same time.
| // storedCopy returns the copy of live to cache. When a clock moved back has | ||
| // stamped the newest cached catalog later than now, live is stored no earlier | ||
| // than that one, so Latest keeps the newest release. The release order breaks the tie. | ||
| func storedCopy(newest, live *Catalog) *Catalog { |
There was a problem hiding this comment.
🤖 Nit (convention) Since #8076 sorts ties with compareVersions (semver first, cache.go catalogs), the parenthetical at L104 ("the cache breaks ties by version as a string") is no longer true. The same goes for the rationale comment in TestChainClockMovedBackKeepsNewestReleaseWhenVersionsSortAsStrings (chain_test.go L326). The one-nanosecond step is still needed when the live stamp is strictly earlier, so only the comments need updating.
databricks#8191) ## Changes The release skills source now sets `Catalog.Version` to the release tag it resolved, without the leading `v`, instead of the manifest's `version` field. A local folder source (`DATABRICKS_SKILLS_DIR`) keeps the manifest value. The `Catalog.Version` doc now covers the release, a local folder, and a pinned branch or commit ref. ## Why The manifest's `version` field is the manifest schema version (`"2"` in every release), not the release. Any cache keyed by `Catalog.Version` would give two different releases one entry. This lands the release-source half of the fix asked for in the blocking thread on `libs/skills/chain.go` line 82 of databricks#8115: databricks#8115 (comment). The other parts of that thread, recording the tag in the bundled snapshot and a chain-level test with two releases that share a manifest version, follow in a later change. It lands on main on its own, so databricks#8076 and databricks#8115 do not change. The feature stays behind `DATABRICKS_SKILLS_PREVIEW`: the skills commands are hidden without it, so default CLI behaviour and existing goldens are unchanged. The guard test is the existing acceptance case `acceptance/cmd/skills/disabled`: it runs `skills list` with `DATABRICKS_SKILLS_PREVIEW` unset and expects `unknown command "skills"`, and checks the root help does not list `skills`. Nothing outside the gated command group reaches the changed code, so no further guard test is needed. No changelog entry is added, because the feature is preview-gated. ## Tests - Two releases whose manifests both say `"version": "2"` report different catalog versions, equal to their tags. - A pinned ref with and without a leading `v` reports the version without it. A ref that is not a semantic version, such as `vendor-fix`, is reported as given. - The release catalog test serves the shared fixture (manifest version 1.2.0) under tag v3.4.5 and expects 3.4.5, so it fails if the manifest version is used. - The existing local folder test still reports the manifest value. - `go test ./libs/skills/...`, `go test ./acceptance -run 'TestAccept/cmd/skills'`, `./task fmt-q lint-q`. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
NewChain serves a catalog from the live source, the disk cache or the bundled copy, and reads files the same way. A cached catalog younger than ten minutes is served without a live call; a negative age is not fresh. Both Catalog and ReadFile fall back only for an error that wraps ErrSourceUnreachable. A file read under a cached catalog is cached only when a live catalog read after it still reports that release, so a file of a newer release is never stored under an older catalog. The bundled copy is served only when its release matches the catalog's. Catalogs from the cache or the bundled copy are marked Stale when they are a fallback, and labelled as cached. The bundled copy keeps the time it was read as its FetchedAt. Cache write errors are logged and ignored. Nothing calls the chain yet; the skills commands are wired in a later change. Co-authored-by: Isaac <no-reply@databricks.com>
A canceled caller now gets the live error back instead of stale cached or bundled data. The live failure behind a stale catalog is kept in the error of a bundled fallback for a file read, wrapped the same way as the fresh path. Co-authored-by: Isaac <no-reply@databricks.com>
A live catalog stored while the clock is behind the newest cached catalog was stamped earlier than it, so Latest kept returning the older release. Store it no earlier than the newest cached catalog; the release order breaks the tie. Co-authored-by: Isaac <no-reply@databricks.com>
When the clock moved back, a live catalog was stored with the same FetchedAt as the newest cached one, so the cache's version tie-break decided which release was Latest. That tie-break compares versions as strings, so 0.2.9 sorted above 0.2.10 and the older release could stay the newest. Stamp the stored copy one nanosecond after the newest cached catalog instead, so the newest write is always the newest entry. Add a ReadFile test for the offline case with nothing cached, which falls back to the bundled copy. Co-authored-by: Isaac <no-reply@databricks.com>
ReadFile fell back to the bundled copy whenever the catalog was Stale. A live source that is itself a cache can report Stale with no error, so its files were never read live and the fallback message printed a nil live error. The chain now falls back only when the live catalog read failed in this call. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
690e456 to
261861e
Compare
Co-authored-by: Isaac <no-reply@databricks.com>
Adds
NewChain, aSourcethat serves skills from the live source, then the disk cache from #8076, then the bundled copy. Nothing calls it yet, so behaviour is unchanged.Changes
NewChain(live, cache, bundled)inlibs/skills/chain.go. A cached catalog younger than 10 minutes is served without a live call. A negative age is not fresh. Otherwise the live catalog is read and cached.Catalogserves the newest cached catalog, or the bundled catalog when nothing is cached. Both are markedStale. A cached catalog is labelledcached copy.ReadFileserves a file of the newest cached release with no live call. Otherwise it reads the file live and caches the bytes only when a live catalog read after the file read still reports the catalog's release. Bytes of a newer release are never stored under an older catalog.ReadFileserves the bundled copy only when its release equals the catalog's release.ErrSourceUnreachable. Other live errors are returned. The contract is documented onSource.FetchedAtstays zero, as on main. The chain does not depend on it: freshness is checked only on the cached catalog. A live catalog that reportsStaleis not cached, so it is never served as fresh. Cache write errors are logged at debug and ignored.Why
A coding agent calls the skills commands several times per session. Without a cache, each call refetches the release. Without a fallback, a network failure leaves the agent with no skills. The chain gives both, and each rule above keeps a fallback from serving bytes of a different release than the catalog it is served under.
Decisions to review
Stale. The provenance line thatskills listprints for a stale catalog says the source could not be refreshed, which is false when nothing failed.FetchedAtstays zero, as on main. The chain never caches or time-compares the bundled copy, so it does not need a read time.Tests
TestChainCatalogThenReadFileIsCachedForOfflineReads: after a catalog read and a file read, going offline still serves that release's file.TestChainFreshCacheUnreachableFileReadFallsBackToBundled,TestChainNonUnreachableLiveErrorIsNotFallenBackandTestChainReadFileUnknownFileIsNotBundledcover the fallback onErrSourceUnreachableonly.TestChainFutureFetchedAtIsNotFresh: a clock moved back makes a second live call.TestChainClockMovedBackKeepsNewestRelease: a clock moved back does not hide the newest cached release.TestChainClockMovedBackKeepsNewestReleaseWhenVersionsSortAsStrings: after a clock moved back, the newer release stays the newest even when its version sorts below the older one as a string (0.2.9, 0.2.10).TestChainReadFileNothingCachedFallsBackToBundled: offline with nothing cached,ReadFileserves the bundled copy.TestChainReadFileStaleCacheOtherBundledReleaseIsNotServedandTestChainReadFileLiveReleaseChangeIsNotCachedUnderCachedCatalogcover the release checks.TestChainCanceledCallerIsNotFallenBack: a canceled caller gets the live error, not the stale cache.TestChainCacheWriteFailureIsIgnored,TestChainFreshCacheIsServedAsCacheAndNotStaleandTestChainLiveUnreachableWithWarmCacheIsStalecover the stale and label rules.TestChainLiveStaleCatalogIsNotCached: a live catalog that reportsStaleis not cached, and a second call reaches live again.go test ./libs/skills/...,./task fmt-q lint-q(0 issues),tools/check_deadcode.py, andgo test ./acceptance -run 'TestAccept/cmd/skills'.This pull request and its description were written by Isaac.