fix(forge): preserve refresh requests during active polling
This commit is contained in:
1 parent
dd0ed998e7
commit
a5460dbe41
8 files changed
+42
-18
No files matched your search
@@ -699,8 +699,8 @@ watch(ref: ChangeRequestRef, listener: ChangeRequestListener): () => void
|
||||
|
||||
/**
|
||||
* Poll a watched change request at once, including after a terminal state.
|
||||
* A fetch already in flight for its forge serves the request; an unwatched
|
||||
* change request is unchanged.
|
||||
* A fetch already in flight is followed immediately by another fetch; an
|
||||
* unwatched change request is unchanged.
|
||||
* @param ref - change request to poll.
|
||||
*/
|
||||
refresh(ref: ChangeRequestRef): void
|
||||
|
||||
@@ -699,8 +699,8 @@ watch(ref: ChangeRequestRef, listener: ChangeRequestListener): () => void
|
||||
|
||||
/**
|
||||
* Poll a watched change request at once, including after a terminal state.
|
||||
* A fetch already in flight for its forge serves the request; an unwatched
|
||||
* change request is unchanged.
|
||||
* A fetch already in flight is followed immediately by another fetch; an
|
||||
* unwatched change request is unchanged.
|
||||
* @param ref - change request to poll.
|
||||
*/
|
||||
refresh(ref: ChangeRequestRef): void
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 2f8a621b991260a1
|
||||
/deepseek-ai-dsh-experimental-forge/use-this-package:
|
||||
en: 396c0c1d508fa12a
|
||||
zh: 136efa3ad502420c
|
||||
en: a92423ce03ea1b83
|
||||
zh: f90d8784b715996e
|
||||
/deepseek-ai-dsh-experimental-forge/understand-the-implementation:
|
||||
en: e193cb547c47069b
|
||||
zh: faa517522402ea41
|
||||
|
||||
@@ -38,7 +38,7 @@ Mount the registry with at least one provider package, such as the GitHub provid
|
||||
|
||||
`diff(ref, signal)` reads the change request's unified patch as the host computes it, with `a/` and `b/` path prefixes, and `fileText(ref, commit, path, signal)` reads one file of its repository at a commit. Both delegate to the provider of the reference's forge, throw when none is registered, and resolve to the text or to a `ForgeFailure`, which is `too-large` when the host or the provider refuses an answer over its size limit. `fileUrl(ref, commit, path)` returns the web page of that file at that commit.
|
||||
|
||||
`ctx.forge.watch(ref, listener)` is also an effect. The first watcher of a change request polls it at once; `latest(ref)` returns the most recent result. Each forge has at most one fetch in flight, and that fetch includes every due change request of the forge. An open change request is polled every `activeIntervalMs` while checks are pending or mergeability is unknown, and every `idleIntervalMs` otherwise. Closed and merged change requests are not polled again. `refresh(ref)` polls a watched change request at once, including after a terminal state; a fetch already in flight for its forge serves the request. A failed read repeats after `activeIntervalMs` doubled for each consecutive failure, up to `maxBackoffMs`. A fetch that exceeds `fetchTimeoutMs` settles as an `unavailable` failure whose message names `FORGE_FETCH_TIMEOUT`. Unregistering a provider settles its watched change requests as `unavailable`. Polling stops when the last watcher leaves. The [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-experimental-forge) lists the defaults.
|
||||
`ctx.forge.watch(ref, listener)` is also an effect. The first watcher of a change request polls it at once; `latest(ref)` returns the most recent result. Each forge has at most one fetch in flight, and that fetch includes every due change request of the forge. An open change request is polled every `activeIntervalMs` while checks are pending or mergeability is unknown, and every `idleIntervalMs` otherwise. Closed and merged change requests are not polled again. `refresh(ref)` polls a watched change request at once, including after a terminal state; if a fetch is already in flight for its forge, another fetch starts immediately after it settles. A failed read repeats after `activeIntervalMs` doubled for each consecutive failure, up to `maxBackoffMs`. A fetch that exceeds `fetchTimeoutMs` settles as an `unavailable` failure whose message names `FORGE_FETCH_TIMEOUT`. Unregistering a provider settles its watched change requests as `unavailable`. Polling stops when the last watcher leaves. The [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-experimental-forge) lists the defaults.
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ kind: "package-reference"
|
||||
|
||||
`diff(ref, signal)` 读取托管平台计算出的变更请求统一补丁,路径带 `a/` 与 `b/` 前缀;`fileText(ref, commit, path, signal)` 读取其仓库中某个提交下的一个文件。两者都委托给引用所属 forge 的提供方,没有注册提供方时抛错,resolve 为文本或 `ForgeFailure`;托管平台或提供方因结果超过其大小上限而拒绝时,失败为 `too-large`。`fileUrl(ref, commit, path)` 返回该文件在该提交下的网页地址。
|
||||
|
||||
`ctx.forge.watch(ref, listener)` 同样是 effect。变更请求的第一个监听方会立即触发轮询;`latest(ref)` 返回最近一次结果。每个 forge 同时最多只有一次读取在进行,这次读取包含该 forge 所有到期的变更请求。打开状态的变更请求在检查未完成或可合并性未知时每 `activeIntervalMs` 轮询一次,否则每 `idleIntervalMs` 轮询一次。已关闭和已合并的变更请求不再轮询。`refresh(ref)` 立即轮询一个被监听的变更请求,已结束的也包括在内;该 forge 已有读取在进行时,由这次读取满足请求。读取失败后,重试间隔为 `activeIntervalMs` 按连续失败次数翻倍,最长 `maxBackoffMs`。读取超过 `fetchTimeoutMs` 时,以消息中包含 `FORGE_FETCH_TIMEOUT` 的 `unavailable` 失败结束。注销提供方会让其被监听的变更请求以 `unavailable` 结束。最后一个监听方离开后轮询停止。默认值见[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-experimental-forge)。
|
||||
`ctx.forge.watch(ref, listener)` 同样是 effect。变更请求的第一个监听方会立即触发轮询;`latest(ref)` 返回最近一次结果。每个 forge 同时最多只有一次读取在进行,这次读取包含该 forge 所有到期的变更请求。打开状态的变更请求在检查未完成或可合并性未知时每 `activeIntervalMs` 轮询一次,否则每 `idleIntervalMs` 轮询一次。已关闭和已合并的变更请求不再轮询。`refresh(ref)` 立即轮询一个被监听的变更请求,已结束的也包括在内;该 forge 已有读取在进行时,等待其结束后立即再读一次。读取失败后,重试间隔为 `activeIntervalMs` 按连续失败次数翻倍,最长 `maxBackoffMs`。读取超过 `fetchTimeoutMs` 时,以消息中包含 `FORGE_FETCH_TIMEOUT` 的 `unavailable` 失败结束。注销提供方会让其被监听的变更请求以 `unavailable` 结束。最后一个监听方离开后轮询停止。默认值见[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-experimental-forge)。
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ export class ForgeService extends Service {
|
||||
return () => {
|
||||
this.providers.delete(provider.forge)
|
||||
for (const watch of this.watches.values()) {
|
||||
if (watch.ref.repository.forge === provider.forge) this.settle(watch, this.missing(provider.forge))
|
||||
if (watch.ref.repository.forge === provider.forge) this.settle(watch, this.missing(provider.forge), undefined)
|
||||
}
|
||||
this.schedule()
|
||||
}
|
||||
@@ -258,8 +258,8 @@ export class ForgeService extends Service {
|
||||
|
||||
/**
|
||||
* Poll a watched change request at once, including after a terminal state.
|
||||
* A fetch already in flight for its forge serves the request; an unwatched
|
||||
* change request is unchanged.
|
||||
* A fetch already in flight is followed immediately by another fetch; an
|
||||
* unwatched change request is unchanged.
|
||||
* @param ref - change request to poll.
|
||||
*/
|
||||
refresh(ref: ChangeRequestRef): void {
|
||||
@@ -342,12 +342,12 @@ export class ForgeService extends Service {
|
||||
for (const watch of batch) {
|
||||
if (this.watches.get(watch.key) !== watch) continue
|
||||
const result = failure ?? results?.get(watch.key) ?? { code: 'unavailable', message: `provider returned no result for ${watch.key}` }
|
||||
this.settle(watch, result)
|
||||
this.settle(watch, result, watch.dueAt)
|
||||
}
|
||||
this.schedule()
|
||||
}
|
||||
|
||||
private settle(watch: Watch, result: ChangeRequestSnapshot | ForgeFailure): void {
|
||||
private settle(watch: Watch, result: ChangeRequestSnapshot | ForgeFailure, refreshAt: number | undefined): void {
|
||||
const fetchedAt = Date.now()
|
||||
let update: ChangeRequestUpdate
|
||||
if ('code' in result) {
|
||||
@@ -359,7 +359,8 @@ export class ForgeService extends Service {
|
||||
}
|
||||
watch.latest = update
|
||||
const delay = nextPollDelay(result, watch.failures, this.config)
|
||||
watch.dueAt = delay === undefined ? undefined : fetchedAt + delay
|
||||
// A refresh requested after this fetch started needs a subsequent fetch, even for a terminal result.
|
||||
watch.dueAt = refreshAt ?? (delay === undefined ? undefined : fetchedAt + delay)
|
||||
for (const listener of [...watch.listeners]) {
|
||||
try {
|
||||
listener(update)
|
||||
|
||||
@@ -220,7 +220,7 @@ describe('forge watch', () => {
|
||||
expect(provider.fetches).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('lets a fetch already in flight serve a refresh', async () => {
|
||||
it('coalesces refreshes during a fetch into one immediate subsequent fetch', async () => {
|
||||
const provider = new FakeProvider()
|
||||
const release = held(provider, target => snapshot(target))
|
||||
const context = await setup(provider)
|
||||
@@ -228,6 +228,7 @@ describe('forge watch', () => {
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.fetches).toHaveLength(1)
|
||||
|
||||
context.forge.refresh(ref(1))
|
||||
context.forge.refresh(ref(1))
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(provider.fetches).toHaveLength(1)
|
||||
@@ -235,8 +236,30 @@ describe('forge watch', () => {
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
expect(updates).toHaveLength(1)
|
||||
await vi.advanceTimersByTimeAsync(4_999)
|
||||
expect(provider.fetches).toHaveLength(1)
|
||||
expect(provider.fetches).toHaveLength(2)
|
||||
release()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(updates).toHaveLength(2)
|
||||
expect(provider.fetches).toHaveLength(2)
|
||||
})
|
||||
|
||||
it.each(['ready', 'merge'] as const)('fetches again after %s when an older poll is still pending', async (action) => {
|
||||
const provider = new FakeProvider()
|
||||
const release = held(provider, target => snapshot(target, { draft: true }))
|
||||
const context = await setup(provider)
|
||||
const { updates } = collect(context)
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
const signal = new AbortController().signal
|
||||
if (action === 'ready') await context.forge.markReady(ref(1), signal)
|
||||
else await context.forge.merge(ref(1), { method: 'merge', headSha: 'a'.repeat(40) }, signal)
|
||||
provider.fetchImpl = undefined
|
||||
provider.results.set(key, snapshot(ref(1), { draft: false, state: action === 'merge' ? 'merged' : 'open' }))
|
||||
release()
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
|
||||
expect(provider.fetches).toHaveLength(2)
|
||||
expect(updates.at(-1)).toMatchObject({ snapshot: { draft: false, state: action === 'merge' ? 'merged' : 'open' } })
|
||||
})
|
||||
|
||||
it('keeps notifying other listeners when one listener throws', async () => {
|
||||
|
||||
@@ -1306,7 +1306,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
},
|
||||
{
|
||||
signature: 'refresh(ref: ChangeRequestRef): void',
|
||||
description: 'Poll a watched change request at once, including after a terminal state. A fetch already in flight for its forge serves the request; an unwatched change request is unchanged.',
|
||||
description: 'Poll a watched change request at once, including after a terminal state. A fetch already in flight is followed immediately by another fetch; an unwatched change request is unchanged.',
|
||||
parameters: [{ name: 'ref', description: 'change request to poll.' }],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user