dsh-unlimited-retry 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/README.zh.md +5 -1
- package/index.js +37 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -342,9 +342,15 @@ curl -s http://127.0.0.1:3080/unlimited-retry/stats | head -c 400
|
|
|
342
342
|
| Requirement | Value |
|
|
343
343
|
|---|---|
|
|
344
344
|
| Node.js | **>= 20** |
|
|
345
|
-
| DSH | **>= 0.2.0-0 < 0.3.0-0** (`engines.dsh`, enforced by the host's compatibility preflight) |
|
|
345
|
+
| DSH | **>= 0.2.0-0 < 0.3.0-0** (`engines.dsh`, enforced by the host's compatibility preflight). Verified against 0.2.1-rc.3, 0.2.1-rc.5 and 0.2.2-alpha.2 |
|
|
346
346
|
| Ships `dsh-agent-loop` and `dsh-llm-retry` | Yes — the retry listener hangs off that event |
|
|
347
347
|
|
|
348
|
+
The session-projection reader adapts to both registration shapes the Host has
|
|
349
|
+
shipped: the disposer returned before 0.2.2, and the callable thenable returned
|
|
350
|
+
from 0.2.2 on, whose `typeof` is `"function"` while it still carries `then`.
|
|
351
|
+
The handle is preferred where it exists, so no deprecated read is performed on a
|
|
352
|
+
runtime that deprecated it.
|
|
353
|
+
|
|
348
354
|
The `-0` lower bound in `engines.dsh` is deliberate: the host matches with
|
|
349
355
|
`includePrerelease: true`, and only a boundary carrying a prerelease tag admits a
|
|
350
356
|
prerelease runtime such as `0.2.1-rc.3`. A plain `>=0.2.0` would silently exclude
|
package/README.zh.md
CHANGED
|
@@ -262,9 +262,13 @@ curl -s http://127.0.0.1:3080/unlimited-retry/stats | head -c 400
|
|
|
262
262
|
| 依赖 | 要求 |
|
|
263
263
|
|---|---|
|
|
264
264
|
| Node.js | **>= 20** |
|
|
265
|
-
| DSH | **>= 0.2.0-0 < 0.3.0-0**(`package.json` 的 `engines.dsh
|
|
265
|
+
| DSH | **>= 0.2.0-0 < 0.3.0-0**(`package.json` 的 `engines.dsh`,由宿主的兼容性预检强制执行)。已在 0.2.1-rc.3、0.2.1-rc.5、0.2.2-alpha.2 上验证 |
|
|
266
266
|
| 带 `dsh-agent-loop` 与 `dsh-llm-retry` | 是(重试监听器挂在那条事件上) |
|
|
267
267
|
|
|
268
|
+
会话投影读取对宿主先后提供过的两种注册形态都做了适配:0.2.2 之前 `register`
|
|
269
|
+
返回 disposer,0.2.2 起返回**可调用 thenable**(`typeof` 是 `"function"`,但仍带 `then`)。
|
|
270
|
+
有句柄时优先用句柄,因此在已弃用旧读取的运行时上不会走那条路。
|
|
271
|
+
|
|
268
272
|
`engines.dsh` 的 `-0` 下界是刻意的:宿主的预检用 `includePrerelease: true` 匹配,而只有带预发布标签的边界才能放行 `0.2.1-rc.3` 这样的预发布运行时。写成 `>=0.2.0` 会把所有 `-rc` 版本静默排除。
|
|
269
273
|
- 有 `AbortSignal.any` 就用它,没有则用 controller 方案等价实现。
|
|
270
274
|
- 1.x 的 `config` 仍可挂载:`retryAllCodes` 被忽略(除非显式排除,否则每个码都会重试),`terminalCodes` 按 `excludeCodes` 读取,两者各打一条替代提示。
|
package/index.js
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
/** Cordis function-plugin name; also the Loader row id used by the patch. */
|
|
41
41
|
export const name = "unlimited-retry";
|
|
42
42
|
|
|
43
|
-
const PLUGIN_VERSION = "2.4.
|
|
43
|
+
const PLUGIN_VERSION = "2.4.1";
|
|
44
44
|
const STATS_PATH = "/unlimited-retry/stats";
|
|
45
45
|
const CONFIG_PATH = "/unlimited-retry/config";
|
|
46
46
|
const RESET_PATH = "/unlimited-retry/reset";
|
|
@@ -780,9 +780,15 @@ export function apply(ctx, config) {
|
|
|
780
780
|
const EMPTY_CHAIN = Object.freeze({ attempt: 0, retryId: undefined });
|
|
781
781
|
|
|
782
782
|
let chainsRegistered = false;
|
|
783
|
+
/**
|
|
784
|
+
* A 0.2.2+ registration handle, whose `stateOf(session)` is the supported reader.
|
|
785
|
+
* Absent on runtimes whose `register` returns a disposer; there the service-level
|
|
786
|
+
* `stateOf(session, key)` is the only reader, and it is not yet deprecated.
|
|
787
|
+
*/
|
|
788
|
+
let chainHandle;
|
|
783
789
|
if (cfg.recordSessionEvents && CHAIN_SCHEMA !== undefined) {
|
|
784
790
|
try {
|
|
785
|
-
ctx.sessionProjections.register({
|
|
791
|
+
const registered = ctx.sessionProjections.register({
|
|
786
792
|
key: CHAIN_KEY,
|
|
787
793
|
stateVersion: 1,
|
|
788
794
|
stateSchema: CHAIN_SCHEMA,
|
|
@@ -802,6 +808,30 @@ export function apply(ctx, config) {
|
|
|
802
808
|
},
|
|
803
809
|
});
|
|
804
810
|
chainsRegistered = true;
|
|
811
|
+
// The two runtimes differ only in what `register` returns: a plain disposer
|
|
812
|
+
// before 0.2.2, and from 0.2.2 a *callable thenable* — upstream's own README
|
|
813
|
+
// says `typeof` is "function" and `instanceof Promise` is false. A check for
|
|
814
|
+
// an object misses it and leaves every read on the deprecated service reader,
|
|
815
|
+
// so this test intentionally accepts a function that carries `then`.
|
|
816
|
+
//
|
|
817
|
+
// Deliberately not an async `apply`: upstream's guidance for new plugins is
|
|
818
|
+
// to await registration, but this plugin's routes and mount probe are
|
|
819
|
+
// registered synchronously and its reader is served from a listener that can
|
|
820
|
+
// fire at any time. Definitions install synchronously anyway, and the handle
|
|
821
|
+
// lands on a microtask, so resolving it here keeps `apply` sync without ever
|
|
822
|
+
// reading stale state.
|
|
823
|
+
if (registered !== null && (typeof registered === "object" || typeof registered === "function")
|
|
824
|
+
&& typeof registered.then === "function") {
|
|
825
|
+
Promise.resolve(registered).then(
|
|
826
|
+
(handle) => {
|
|
827
|
+
if (handle !== null && typeof handle === "object" && typeof handle.stateOf === "function") chainHandle = handle;
|
|
828
|
+
},
|
|
829
|
+
(error) => {
|
|
830
|
+
chainsRegistered = false;
|
|
831
|
+
log("warn", `session projection registration failed (${String(error)}); retry ladders are bounded and process-local instead`);
|
|
832
|
+
},
|
|
833
|
+
);
|
|
834
|
+
}
|
|
805
835
|
} catch (error) {
|
|
806
836
|
log("warn", `session projections unavailable (${String(error)}); retry ladders are bounded and process-local instead`);
|
|
807
837
|
}
|
|
@@ -836,6 +866,11 @@ export function apply(ctx, config) {
|
|
|
836
866
|
function chainFor(session) {
|
|
837
867
|
if (chainsRegistered) {
|
|
838
868
|
try {
|
|
869
|
+
// Prefer the handle, which is the supported reader from 0.2.2 on; the
|
|
870
|
+
// service reader is deprecated there. The handle resolves on a microtask,
|
|
871
|
+
// so no recorded event can arrive before it is adopted — measured on
|
|
872
|
+
// 0.2.2-alpha.2: zero deprecation warnings across a full ladder.
|
|
873
|
+
if (chainHandle !== undefined) return chainHandle.stateOf(session) ?? EMPTY_CHAIN;
|
|
839
874
|
return ctx.sessionProjections.stateOf(session, CHAIN_KEY) ?? EMPTY_CHAIN;
|
|
840
875
|
} catch (error) {
|
|
841
876
|
// Reading a projection needs a real session (the registry folds its log
|