fix(upstream-skills): delete the other pins once per registration
Processes of one profile can run different versions of a plugin at the same time, and they share the profile's pin directory. A registration that deleted the other pins after every download made two such processes delete each other's pin and download their own again at every check. Each registration now deletes the other pins once, the first time its own pin is in place; a process whose pin another process deleted downloads it again and leaves that process's pin in place. The README and the Agent Note no longer state that no other installation reads the directory, and the README lists the remaining case as a known limitation.
This commit is contained in:
1 parent
f5c30538f8
commit
5de4257956
11 files changed
+76
-34
No files matched your search
+6
-6
@@ -9,11 +9,11 @@
|
||||
en: 755fe8a192cfebe1
|
||||
zh: 855ad2920b33e364
|
||||
/agent-note-runtime-download-of-upstream-skills/decision:
|
||||
en: 112c51b2f5ee436e
|
||||
zh: 590329b20fb08d9d
|
||||
en: 98f6d4a4c6b7849f
|
||||
zh: a361378d5020c954
|
||||
/agent-note-runtime-download-of-upstream-skills/alternatives-considered:
|
||||
en: 963c4ebf1818a1c9
|
||||
zh: b8f2dfe02f7c3817
|
||||
en: 250ab524fc33cd94
|
||||
zh: bc4d8008af1f9d61
|
||||
/agent-note-runtime-download-of-upstream-skills/consequences:
|
||||
en: 967c7ec52d6ad244
|
||||
zh: dca075827cbc23d6
|
||||
en: 5df2a8d5d5b9fbb6
|
||||
zh: b827f6539833ee87
|
||||
+4
-2
@@ -10,7 +10,7 @@ The WeCom and Tencent Meeting plugins index guides that their vendors publish on
|
||||
|
||||
## Decision
|
||||
|
||||
Each of these plugins keeps only its DSH-authored entry `SKILL.md`, pins the upstream files by repository, commit, kept directory, exclusions, license file, total size, and a digest of the kept files, and registers both with `ctx.upstreamSkills`, the Service of [`@deepseek-ai/dsh-upstream-skills`](../../../../packages/connector/upstream-skills/README.md). The Service downloads the commit archive from GitHub when the plugin loads, keeps the directory and the license file, verifies them, publishes them under `$DSH_HOME/cache/<plugin>`, and lists the entry skill with the published directory as its base directory. In a profile the files go to that profile's own directory, `$DSH_HOME/cache/<plugin>/<profile>`, where the pin in place replaces the earlier ones: a profile holds one version of a plugin, so no other installation reads that directory, a plugin update leaves one copy, and an unchanged pin is never downloaded again. The plugin shows the download state beside the account state. Its check reads only the account and restarts a failed download without waiting for it: the CLI account runtime runs one operation at a time, so a check that waited for a slow GitHub download would also hold sign-in. Each archive source has `skillsTimeoutMs` to deliver the whole archive, and reading stops once the kept files exceed the pinned size. A plugin's `skillsDir` points at prepared files for tests and offline installations, and the Service's `skillsUrls` replaces the archive host for every plugin.
|
||||
Each of these plugins keeps only its DSH-authored entry `SKILL.md`, pins the upstream files by repository, commit, kept directory, exclusions, license file, total size, and a digest of the kept files, and registers both with `ctx.upstreamSkills`, the Service of [`@deepseek-ai/dsh-upstream-skills`](../../../../packages/connector/upstream-skills/README.md). The Service downloads the commit archive from GitHub when the plugin loads, keeps the directory and the license file, verifies them, publishes them under `$DSH_HOME/cache/<plugin>`, and lists the entry skill with the published directory as its base directory. In a profile the files go to that profile's own directory, `$DSH_HOME/cache/<plugin>/<profile>`, which only that profile's processes read, and each registration deletes the other pins there once, when its own pin first is in place: a plugin update leaves one copy, and an unchanged pin is never downloaded again. The plugin shows the download state beside the account state. Its check reads only the account and restarts a failed download without waiting for it: the CLI account runtime runs one operation at a time, so a check that waited for a slow GitHub download would also hold sign-in. Each archive source has `skillsTimeoutMs` to deliver the whole archive, and reading stops once the kept files exceed the pinned size. A plugin's `skillsDir` points at prepared files for tests and offline installations, and the Service's `skillsUrls` replaces the archive host for every plugin.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
@@ -26,10 +26,12 @@ Each of these plugins keeps only its DSH-authored entry `SKILL.md`, pins the ups
|
||||
|
||||
**One cache directory shared by every profile.** It saves one download per profile. Two DSH installations of different versions on one `$DSH_HOME` can pin different commits for one plugin, so deleting a replaced pin there deletes files the other installation reads, and keeping every pin leaves a copy per plugin update.
|
||||
|
||||
**Deleting the other pins after every download.** Processes of one profile can run different versions of a plugin at the same time, such as one started before a plugin update and one started after it, and they share the profile's directory. Each would delete the other's pin after each of its downloads and download its own again at its next check, without end. Deleting once per registration ends that: the later process still deletes the earlier one's pin once, the earlier one downloads it again, and both pins stay until another load. A record of the pins in use, or a period during which a replaced pin stays, would also keep the running process's pin, at the price of a protocol between processes or of a second copy for that period.
|
||||
|
||||
**The DSH version in the directory name.** Connector packages carry the DSH version, but a version in the name does not decide which installation may delete which directory, and it downloads the files again at every DSH release although the pin rarely changes.
|
||||
|
||||
**DingTalk's downloader.** DingTalk downloads checksummed release assets together with its executable. WeCom and Tencent Meeting publish no release assets and install their CLIs from npm, so only these two plugins register with this Service, and DingTalk keeps its own downloader.
|
||||
|
||||
## Consequences
|
||||
|
||||
The repository and the plugins' npm packages carry only the entry skills. The first load after a new pin needs GitHub or a configured mirror; until a download succeeds, the entry skill is not listed and the plugin shows the failure, which its next check retries. Tests, recorded Sessions, and Web end-to-end tests set `skillsDir` to fixture files and make no network requests. Each profile that loads a plugin downloads its own copy. Removing a plugin leaves its pin in the cache, and without a profile no pin is deleted. Updating a pin is a code change: `scripts/upstream-skills-digest.ts` prints the new pin, and the entry's guide index and a real-model run follow it.
|
||||
The repository and the plugins' npm packages carry only the entry skills. The first load after a new pin needs GitHub or a configured mirror; until a download succeeds, the entry skill is not listed and the plugin shows the failure, which its next check retries. Tests, recorded Sessions, and Web end-to-end tests set `skillsDir` to fixture files and make no network requests. Each profile that loads a plugin downloads its own copy. A process that still runs another version of a plugin loses its pin once to a later process of the same profile and downloads it again at its next check. Removing a plugin leaves its pin in the cache, and without a profile no pin is deleted. Updating a pin is a code change: `scripts/upstream-skills-digest.ts` prints the new pin, and the entry's guide index and a real-model run follow it.
|
||||
+4
-2
@@ -10,7 +10,7 @@ Status: implemented
|
||||
|
||||
## 决策
|
||||
|
||||
这些插件只保留 DSH 自己编写的入口 `SKILL.md`,按仓库、提交、保留的目录、排除项、许可证文件、总大小和保留文件的摘要固定上游文件,并把两者注册到 `ctx.upstreamSkills`,即 [`@deepseek-ai/dsh-upstream-skills`](../../../../packages/connector/upstream-skills/README.zh.md) 的 Service。插件加载时,Service 从 GitHub 下载这个提交的归档,保留该目录和许可证文件,校验后发布到 `$DSH_HOME/cache/<插件>` 下,再列出入口技能,并把发布的目录作为它的基础目录。在 profile 中,文件发布到这个 profile 自己的目录 `$DSH_HOME/cache/<插件>/<profile>`,就位的固定提交替换那里更早的固定提交:一个 profile 里一个插件只有一个版本,因此没有别的安装读取这个目录,插件更新后只留下一份,固定提交不变时也不会重新下载。插件在账号状态旁显示下载状态。它的检查只读取账号,并在不等待的情况下重新开始失败的下载:CLI 账号运行时一次只执行一个操作,检查若等待缓慢的 GitHub 下载,登录也会被占住。每个归档来源要在 `skillsTimeoutMs` 内送达完整归档,保留文件超过固定的大小时停止读取。插件的 `skillsDir` 为测试和离线安装指向准备好的文件,Service 的 `skillsUrls` 为所有插件替换归档主机。
|
||||
这些插件只保留 DSH 自己编写的入口 `SKILL.md`,按仓库、提交、保留的目录、排除项、许可证文件、总大小和保留文件的摘要固定上游文件,并把两者注册到 `ctx.upstreamSkills`,即 [`@deepseek-ai/dsh-upstream-skills`](../../../../packages/connector/upstream-skills/README.zh.md) 的 Service。插件加载时,Service 从 GitHub 下载这个提交的归档,保留该目录和许可证文件,校验后发布到 `$DSH_HOME/cache/<插件>` 下,再列出入口技能,并把发布的目录作为它的基础目录。在 profile 中,文件发布到这个 profile 自己的目录 `$DSH_HOME/cache/<插件>/<profile>`,只有这个 profile 的进程读取它;每次注册在自己的固定提交第一次就位时,删除一次那里其他的固定提交:插件更新后只留下一份,固定提交不变时也不会重新下载。插件在账号状态旁显示下载状态。它的检查只读取账号,并在不等待的情况下重新开始失败的下载:CLI 账号运行时一次只执行一个操作,检查若等待缓慢的 GitHub 下载,登录也会被占住。每个归档来源要在 `skillsTimeoutMs` 内送达完整归档,保留文件超过固定的大小时停止读取。插件的 `skillsDir` 为测试和离线安装指向准备好的文件,Service 的 `skillsUrls` 为所有插件替换归档主机。
|
||||
|
||||
## 考虑过的替代方案
|
||||
|
||||
@@ -26,10 +26,12 @@ Status: implemented
|
||||
|
||||
**所有 profile 共用一个缓存目录。** 它让每个 profile 少下载一次。同一个 `$DSH_HOME` 上两个不同版本的 DSH 安装,可能为同一个插件固定不同的提交,因此在那里删除被替换的固定提交,会删掉另一个安装正在读取的文件;而全部保留,则每次插件更新都多留一份。
|
||||
|
||||
**每次下载完成后都删除其他固定提交。** 同一个 profile 的多个进程可以同时运行同一插件的不同版本,例如一个在插件更新之前启动,另一个在更新之后启动,它们共用这个 profile 的目录。这样每个进程都会在自己每次下载完成后删除对方的固定提交,并在下一次检查时重新下载自己的,没有尽头。每次注册只删除一次就结束了这个循环:后启动的进程仍会删除一次先启动的进程的固定提交,先启动的进程重新下载,此后两个固定提交都保留,直到下一次加载。记录正在使用的固定提交,或让被替换的固定提交保留一段时间,也能保住运行中进程的固定提交,代价是进程之间要有一套约定,或者在这段时间里多留一份。
|
||||
|
||||
**在目录名中加入 DSH 版本。** Connector 包的版本与 DSH 版本一致,但目录名里的版本并不能决定哪个安装可以删除哪个目录,而且固定提交很少变化,每次 DSH 发版却都要重新下载这些文件。
|
||||
|
||||
**钉钉的下载器。** 钉钉把带校验和的发布资产和可执行文件一起下载。企业微信和腾讯会议没有发布资产,CLI 从 npm 安装,因此只有这两个插件注册到这个 Service,钉钉保留自己的下载器。
|
||||
|
||||
## 影响
|
||||
|
||||
仓库和插件的 npm 包里只有入口技能。换用新的固定提交后,首次加载需要能访问 GitHub 或配置的镜像;下载成功之前,入口技能不会列出,插件显示失败,下一次检查会重试。测试、录制的 Session 和 Web 端到端测试都把 `skillsDir` 设为夹具文件,不发起网络请求。每个加载该插件的 profile 都各自下载一份。移除插件后,它的固定提交仍留在缓存中;没有 profile 时,任何固定提交都不会被删除。更新固定提交需要改代码:`scripts/upstream-skills-digest.ts` 输出新的固定信息,随后更新入口的子指南索引,并用真实模型运行一次。
|
||||
仓库和插件的 npm 包里只有入口技能。换用新的固定提交后,首次加载需要能访问 GitHub 或配置的镜像;下载成功之前,入口技能不会列出,插件显示失败,下一次检查会重试。测试、录制的 Session 和 Web 端到端测试都把 `skillsDir` 设为夹具文件,不发起网络请求。每个加载该插件的 profile 都各自下载一份。仍在运行插件另一个版本的进程,会被同一 profile 后启动的进程删除一次固定提交,并在下一次检查时重新下载。移除插件后,它的固定提交仍留在缓存中;没有 profile 时,任何固定提交都不会被删除。更新固定提交需要改代码:`scripts/upstream-skills-digest.ts` 输出新的固定信息,随后更新入口的子指南索引,并用真实模型运行一次。
|
||||
@@ -337,9 +337,9 @@ Holds what CLI app plugins register: for each plugin, the entry skill and the do
|
||||
/**
|
||||
* Register the calling plugin's entry skill and start downloading the upstream files unless they are in place. The
|
||||
* download starts at load so that a session without a client also gets the skill; a failure is logged as a warning
|
||||
* and waits for `retry()`. In a profile, the files go to that profile's own directory for the plugin, and the pin
|
||||
* that is in place replaces every other pin there. The registration belongs to the calling plugin: unloading that
|
||||
* plugin aborts the download and removes the entry skill.
|
||||
* and waits for `retry()`. In a profile, the files go to that profile's own directory for the plugin, and the
|
||||
* registration deletes the other pins there once, the first time its own pin is in place. The registration belongs
|
||||
* to the calling plugin: unloading that plugin aborts the download and removes the entry skill.
|
||||
* @param registration - the plugin's provider name, entry, pinned files, and optional skills directory.
|
||||
* @returns the handle the plugin's view observes and its check retries.
|
||||
* @throws when the entry has no skill name or description in its frontmatter, `skillsDir` is not a directory, or a
|
||||
|
||||
@@ -337,9 +337,9 @@ Holds what CLI app plugins register: for each plugin, the entry skill and the do
|
||||
/**
|
||||
* Register the calling plugin's entry skill and start downloading the upstream files unless they are in place. The
|
||||
* download starts at load so that a session without a client also gets the skill; a failure is logged as a warning
|
||||
* and waits for `retry()`. In a profile, the files go to that profile's own directory for the plugin, and the pin
|
||||
* that is in place replaces every other pin there. The registration belongs to the calling plugin: unloading that
|
||||
* plugin aborts the download and removes the entry skill.
|
||||
* and waits for `retry()`. In a profile, the files go to that profile's own directory for the plugin, and the
|
||||
* registration deletes the other pins there once, the first time its own pin is in place. The registration belongs
|
||||
* to the calling plugin: unloading that plugin aborts the download and removes the entry skill.
|
||||
* @param registration - the plugin's provider name, entry, pinned files, and optional skills directory.
|
||||
* @returns the handle the plugin's view observes and its check retries.
|
||||
* @throws when the entry has no skill name or description in its frontmatter, `skillsDir` is not a directory, or a
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
en: 0633b5470e6b4e6c
|
||||
zh: 419916b5b305aa7d
|
||||
/deepseek-ai-dsh-upstream-skills/use-this-package/replaced-pins:
|
||||
en: 42c3124531c8425a
|
||||
zh: 6d2fd7212bfdd552
|
||||
en: 543da0e2871bec3d
|
||||
zh: ed80c0c59040440b
|
||||
/deepseek-ai-dsh-upstream-skills/use-this-package/pinning-a-commit:
|
||||
en: ea5587081cc3b471
|
||||
zh: e0993a154ae79dc1
|
||||
@@ -48,8 +48,8 @@
|
||||
en: 2a09699bc1130758
|
||||
zh: 972fc624936c8c2f
|
||||
/deepseek-ai-dsh-upstream-skills/known-limitations-and-deferred-work:
|
||||
en: 6784a592061a4e41
|
||||
zh: 815bcaf10415f792
|
||||
en: 25e90bc332e990a7
|
||||
zh: 3a4a3face42b5c13
|
||||
/deepseek-ai-dsh-upstream-skills/known-limitations-and-deferred-work/dev-note:
|
||||
en: e67f633dc6fe7773
|
||||
zh: e88aeb617ffb74ea
|
||||
@@ -96,7 +96,7 @@ The Service downloads `<prefix>/<owner>/<repository>/tar.gz/<commit>` from each
|
||||
|
||||
### Replaced pins
|
||||
|
||||
A profile that `dsh` launches holds one version of a plugin, so each profile has a directory of its own for a plugin's files: `$DSH_HOME/cache/<name>/<profile>`. Once a pin is in place there, already at load or after its download, the Service deletes the other pins of that directory, so a plugin update that changes the pin leaves one copy. The earlier pin stays until the new one is published. The deletion runs in the background, and neither `register` nor the end of a download waits for it; a pin that cannot be deleted is logged as a warning and deleted at a later load or download. A composition that `dsh` did not launch has no profile: its pins stay in `$DSH_HOME/cache/<name>`, which several installations may share, and none is deleted. A configured `skillsDir` and its sibling directories are never deleted.
|
||||
Each profile that `dsh` launches has a directory of its own for a plugin's files, `$DSH_HOME/cache/<name>/<profile>`, which the processes of that profile share. A registration deletes the other pins of that directory once, the first time its own pin is in place there: already at load, or after its download. A plugin update that changes the pin therefore leaves one copy, and the earlier pin stays until the new one is published. The deletion runs in the background, and neither `register` nor the end of a download waits for it; a pin that cannot be deleted is logged as a warning and deleted at a later load. Because a registration deletes the other pins only once, a process whose pin another process of the profile deleted downloads it again at its next check and leaves that process's pin in place; [Known Limitations](#known-limitations-and-deferred-work) describes that case. A composition that `dsh` did not launch has no profile: its pins stay in `$DSH_HOME/cache/<name>`, which several installations may share, and none is deleted. A configured `skillsDir` and its sibling directories are never deleted.
|
||||
|
||||
### Pinning a commit
|
||||
|
||||
@@ -148,6 +148,7 @@ A load that finds the files in place lists the entry in the session's first cata
|
||||
|
||||
- The first load after a new pin needs GitHub or a configured mirror; until a download succeeds, the entry skill is not listed and the plugin shows the `failed` state.
|
||||
- Each profile that loads a plugin downloads its own copy of the pin.
|
||||
- Processes of one profile can run different versions of a plugin at the same time, such as one started before a plugin update and one started after it. The later one deletes the pin the earlier one reads: the earlier process lists no entry skill, and its agents cannot open the guides, until its next check has downloaded the pin again. Both pins then stay until a process of the profile loads the plugin again.
|
||||
- Removing a plugin leaves its pin in the cache. A process that exits while it writes a download leaves its `.skills-<digest>-<uuid>` staging directory there too. Nothing deletes either.
|
||||
- Without a profile, every pin stays in `$DSH_HOME/cache/<name>` after the plugin pins another commit.
|
||||
- Only the published directory's existence is checked. When files inside it are deleted or changed, the entry skill stays listed over them; deleting the directory makes the next check or load download the pin again.
|
||||
|
||||
@@ -96,7 +96,7 @@ Service 按顺序从每个 `skillsUrls` 前缀下载 `<前缀>/<owner>/<reposito
|
||||
|
||||
### 替换旧的固定提交
|
||||
|
||||
由 `dsh` 启动的 profile 中,一个插件只有一个版本,因此每个 profile 为每个插件的文件保留自己的目录:`$DSH_HOME/cache/<name>/<profile>`。某个固定提交在这个目录中就位后(加载时已在位,或下载完成后),Service 删除该目录下其他固定提交的目录,所以插件更新换了固定提交之后只留下一份。新的固定提交发布之前,旧的保持不动。删除在后台进行,`register` 和下载的结束都不等待它;无法删除的目录记为警告,留到之后的加载或下载时再删。不是由 `dsh` 启动的组合没有 profile:它的固定提交都留在可能被多个安装共用的 `$DSH_HOME/cache/<name>` 中,一个也不删除。配置的 `skillsDir` 及其同级目录从不删除。
|
||||
每个由 `dsh` 启动的 profile 为每个插件的文件保留自己的目录 `$DSH_HOME/cache/<name>/<profile>`,这个 profile 的各个进程共用它。一次注册只删除一次该目录下其他固定提交的目录,时机是它自己的固定提交第一次在那里就位时:加载时已在位,或下载完成后。因此插件更新换了固定提交之后只留下一份,新的固定提交发布之前,旧的保持不动。删除在后台进行,`register` 和下载的结束都不等待它;无法删除的目录记为警告,留到之后的加载时再删。由于一次注册只删除一次,某个进程的固定提交被同一 profile 的另一个进程删除后,它在下一次检查时重新下载,并保留那个进程的固定提交;这种情况见[已知限制](#known-limitations-and-deferred-work)。不是由 `dsh` 启动的组合没有 profile:它的固定提交都留在可能被多个安装共用的 `$DSH_HOME/cache/<name>` 中,一个也不删除。配置的 `skillsDir` 及其同级目录从不删除。
|
||||
|
||||
### 固定提交
|
||||
|
||||
@@ -148,6 +148,7 @@ Service 按顺序从每个 `skillsUrls` 前缀下载 `<前缀>/<owner>/<reposito
|
||||
|
||||
- 换用新的固定提交后,首次加载需要能访问 GitHub 或配置的镜像;下载成功之前,入口技能不会列出,插件显示 `failed` 状态。
|
||||
- 每个加载该插件的 profile 都各自下载一份固定提交。
|
||||
- 同一个 profile 的多个进程可以同时运行同一插件的不同版本,例如一个在插件更新之前启动,另一个在更新之后启动。后启动的进程会删除先启动的进程正在读取的固定提交:先启动的进程不再列出入口技能,其中的 Agent 也打不开子指南,直到它下一次检查重新下载完成。此后两个固定提交都保留,直到这个 profile 的某个进程再次加载该插件。
|
||||
- 移除插件后,它的固定提交仍留在缓存中。进程在写入下载内容时退出,也会在那里留下它的暂存目录 `.skills-<摘要>-<uuid>`。两者都不会被删除。
|
||||
- 没有 profile 时,插件改为固定其他提交后,所有固定提交都留在 `$DSH_HOME/cache/<name>` 中。
|
||||
- 只检查已发布的目录是否存在。目录里的文件被删除或改动后,入口技能仍会基于这些文件列出;删除该目录后,下一次检查或加载会重新下载固定的提交。
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Upstream skills of CLI app plugins: the Host Service `ctx.upstreamSkills` downloads the files that a plugin's entry
|
||||
* skill indexes from one directory of the vendor's GitHub repository at a pinned commit, verifies them, publishes them
|
||||
* in the DSH cache, and lists the entry skill over them once they are there. In a profile, each plugin's files have
|
||||
* a directory of their own, where a newly published pin replaces the earlier ones.
|
||||
* a directory of their own, from which a registration deletes the other pins once its own pin is in place.
|
||||
* @module @deepseek-ai/dsh-upstream-skills
|
||||
*/
|
||||
|
||||
@@ -64,9 +64,9 @@ export default class UpstreamSkills extends Service {
|
||||
/**
|
||||
* Register the calling plugin's entry skill and start downloading the upstream files unless they are in place. The
|
||||
* download starts at load so that a session without a client also gets the skill; a failure is logged as a warning
|
||||
* and waits for `retry()`. In a profile, the files go to that profile's own directory for the plugin, and the pin
|
||||
* that is in place replaces every other pin there. The registration belongs to the calling plugin: unloading that
|
||||
* plugin aborts the download and removes the entry skill.
|
||||
* and waits for `retry()`. In a profile, the files go to that profile's own directory for the plugin, and the
|
||||
* registration deletes the other pins there once, the first time its own pin is in place. The registration belongs
|
||||
* to the calling plugin: unloading that plugin aborts the download and removes the entry skill.
|
||||
* @param registration - the plugin's provider name, entry, pinned files, and optional skills directory.
|
||||
* @returns the handle the plugin's view observes and its check retries.
|
||||
* @throws when the entry has no skill name or description in its frontmatter, `skillsDir` is not a directory, or a
|
||||
@@ -99,10 +99,13 @@ class UpstreamSkillProvider implements SkillProvider {
|
||||
readonly name: string
|
||||
readonly directory: string
|
||||
/**
|
||||
* The profile's own directory for this plugin, whose pins {@link prune} replaces with the one in place. Undefined
|
||||
* for a configured `skillsDir` and without a profile, where pins share `$DSH_HOME/cache/<name>` and all stay.
|
||||
* The profile's own directory for this plugin, from which {@link prune} deletes the other pins; the processes of
|
||||
* the profile share it. Undefined for a configured `skillsDir` and without a profile, where pins share
|
||||
* `$DSH_HOME/cache/<name>` and all stay.
|
||||
*/
|
||||
private readonly pins: string | undefined
|
||||
/** Whether this registration has started deleting the other pins, which it does once. */
|
||||
private pruned = false
|
||||
private readonly candidate: SkillCandidate
|
||||
private readonly content: string
|
||||
private readonly listeners = new Set<(state: UpstreamSkillsState) => void>()
|
||||
@@ -125,7 +128,7 @@ class UpstreamSkillProvider implements SkillProvider {
|
||||
} else if (profile === undefined) {
|
||||
this.directory = dshCachePath(options.name, pin)
|
||||
} else {
|
||||
// A profile holds one version of a plugin, so no other installation reads this directory's pins.
|
||||
// Only this profile's processes read these pins; one that still runs another plugin version loses its pin.
|
||||
this.pins = dshCachePath({ dshHome: profile.home }, options.name, profile.name)
|
||||
this.directory = join(this.pins, pin)
|
||||
}
|
||||
@@ -186,13 +189,16 @@ class UpstreamSkillProvider implements SkillProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the other pins from the profile's own directory once this pin is in place there, and return at once. It
|
||||
* deletes nothing without a profile or for a configured `skillsDir`. A pin that cannot be deleted is logged as a
|
||||
* warning and stays until the next load or download.
|
||||
* Start deleting the other pins from the profile's own directory, once per registration: the first time this pin is
|
||||
* in place there. It returns at once, and does nothing without a profile, for a configured `skillsDir`, or after it
|
||||
* has started once. A registration whose pin a process running another plugin version deleted therefore downloads
|
||||
* it again without deleting that process's pin. A pin that cannot be deleted is logged as a warning and stays until
|
||||
* a later load.
|
||||
*/
|
||||
prune(): void {
|
||||
const { pins } = this
|
||||
if (pins === undefined || !this.installed()) return
|
||||
if (pins === undefined || this.pruned || !this.installed()) return
|
||||
this.pruned = true
|
||||
const current = basename(this.directory)
|
||||
void readdir(pins).then(async (names) => {
|
||||
for (const name of names) {
|
||||
|
||||
@@ -15,6 +15,8 @@ import { KEPT, archivePath, pin, repository, serve, startHost, type ArchiveHost
|
||||
const renameHook = vi.hoisted(() => ({ before: undefined as ((from: string, to: string) => Promise<void>) | undefined }))
|
||||
/** The one path whose removal fails with the given error, as a directory in use does on Windows. */
|
||||
const removeHook = vi.hoisted(() => ({ refused: undefined as { readonly path: string; readonly error: Error } | undefined }))
|
||||
/** Every directory listed through `readdir`, by the Service or by a test, in call order. */
|
||||
const listHook = vi.hoisted(() => ({ listed: [] as string[] }))
|
||||
vi.mock('node:fs/promises', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('node:fs/promises')>()
|
||||
return {
|
||||
@@ -29,6 +31,10 @@ vi.mock('node:fs/promises', async (importOriginal) => {
|
||||
if (removeHook.refused?.path === args[0]) throw removeHook.refused.error
|
||||
return actual.rm(...args)
|
||||
},
|
||||
readdir: (path: string) => {
|
||||
listHook.listed.push(path)
|
||||
return actual.readdir(path)
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
@@ -78,6 +84,7 @@ afterEach(async () => {
|
||||
vi.unstubAllGlobals()
|
||||
renameHook.before = undefined
|
||||
removeHook.refused = undefined
|
||||
listHook.listed.length = 0
|
||||
await ctx.fiber.dispose()
|
||||
await rm(home, { recursive: true, force: true })
|
||||
})
|
||||
@@ -421,6 +428,29 @@ describe('register in a profile', () => {
|
||||
expect(host.requests).toEqual([])
|
||||
})
|
||||
|
||||
it('deletes the other pins once: it downloads a pin another process deleted again and keeps that process\'s pin', async () => {
|
||||
const other = 'skills-fedcba9876543210'
|
||||
await mkdir(join(pins(), EARLIER), { recursive: true })
|
||||
host.routes[archivePath(set)] = serve(repository())
|
||||
const skills = register()
|
||||
expect(await settled(skills)).toBe('installed')
|
||||
await vi.waitFor(async () => { expect(await readdir(pins())).toEqual([CURRENT]) })
|
||||
|
||||
// Another process of the profile, running another plugin version, publishes its pin and deletes this one.
|
||||
await mkdir(join(pins(), other))
|
||||
await rm(join(pins(), CURRENT), { recursive: true })
|
||||
expect(skills.state).toBe('failed')
|
||||
const before = listHook.listed.length
|
||||
skills.retry()
|
||||
expect(await settled(skills)).toBe('installed')
|
||||
|
||||
// The deletion starts by listing the directory, in the same turn in which the download settles.
|
||||
expect(listHook.listed.slice(before)).not.toContain(pins())
|
||||
expect(await entries(pins())).toEqual([CURRENT, other].toSorted())
|
||||
expect(await ctx.skills.list()).toEqual(listed(join(pins(), CURRENT)))
|
||||
expect(host.requests).toEqual([archivePath(set), archivePath(set)])
|
||||
})
|
||||
|
||||
it('keeps the earlier pin while the new one cannot be downloaded', async () => {
|
||||
await mkdir(join(pins(), EARLIER), { recursive: true })
|
||||
host.routes[archivePath(set)] = (response) => { response.writeHead(500).end() }
|
||||
|
||||
@@ -4794,7 +4794,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
methods: [
|
||||
{
|
||||
signature: 'register(registration: UpstreamSkillsRegistration): UpstreamSkillsHandle',
|
||||
description: 'Register the calling plugin\'s entry skill and start downloading the upstream files unless they are in place. The download starts at load so that a session without a client also gets the skill; a failure is logged as a warning and waits for `retry()`. In a profile, the files go to that profile\'s own directory for the plugin, and the pin that is in place replaces every other pin there. The registration belongs to the calling plugin: unloading that plugin aborts the download and removes the entry skill.',
|
||||
description: 'Register the calling plugin\'s entry skill and start downloading the upstream files unless they are in place. The download starts at load so that a session without a client also gets the skill; a failure is logged as a warning and waits for `retry()`. In a profile, the files go to that profile\'s own directory for the plugin, and the registration deletes the other pins there once, the first time its own pin is in place. The registration belongs to the calling plugin: unloading that plugin aborts the download and removes the entry skill.',
|
||||
parameters: [{ name: 'registration', description: 'the plugin\'s provider name, entry, pinned files, and optional skills directory.' }],
|
||||
returns: 'the handle the plugin\'s view observes and its check retries.',
|
||||
throws: ['when the entry has no skill name or description in its frontmatter, `skillsDir` is not a directory, or a skill provider named `name` is already registered.'],
|
||||
|
||||
Reference in new issue
Block a user