@lmzhen/dsh-evolution-review 0.62.3 → 0.62.4

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 CHANGED
@@ -21,7 +21,7 @@ Subagent-origin, background-visibility, and review-child sessions are excluded.
21
21
 
22
22
  ## Events and limits
23
23
 
24
- The package emits `evolution/review-scheduled`, `evolution/review-completed`, `evolution/review-error`, and an aux `evolution/plan-applied` ledger entry. `reviewTimeoutMs` bounds the aux loop (default 300s; raise it, lower `reviewMaxRounds`, or raise `reviewMaxToolCalls` for unusually long reviews); `reviewMaxRounds` (default 12) and `reviewMaxToolCalls` (default 50) bound model rounds and tool calls. Aux reviews run at most 8 at once per plugin instance (`AUX_REVIEW_CONCURRENCY`): that is a provider/CPU budget, while cross-review writes are serialized per resource by the review write locks and the mutation-authority lease. Capacity is acquired **before** the parent prefix is frozen, and a queued review has its own 30s admission budget (`AUX_REVIEW_QUEUE_TIMEOUT_MS`), so `reviewTimeoutMs` starts only after admission and never pays for queue time; a review that cannot be admitted keeps its debt for the next boundary. Reaching any bound records `partial`/`timeout` with `hitRoundLimit` and `partialReason`, never `completed`. Review cadence state is persisted when `evolution-state` is available; without it, cadence can reset between turns.
24
+ The package emits `evolution/review-scheduled`, `evolution/review-completed`, `evolution/review-error`, and an aux `evolution/plan-applied` ledger entry. `reviewTimeoutMs` bounds the aux loop (default 300s; raise it, lower `reviewMaxRounds`, or raise `reviewMaxToolCalls` for unusually long reviews); `reviewMaxRounds` (default 12) and `reviewMaxToolCalls` (default 50) bound model rounds and tool calls. Aux reviews have no plugin-wide concurrency semaphore: like inject mode, they start immediately at the completed-turn boundary and the provider/LLM layer owns backpressure. The turn-end handler freezes the boundary prefix synchronously, resets the cadence counters in the same state transaction, and starts the review timer, so no queue can move the boundary, wipe a newer turn's counters, or charge queue time to `reviewTimeoutMs`; cross-review writes are still serialized per resource by the review write locks and the mutation-authority lease. Reaching any bound records `partial`/`timeout` with `hitRoundLimit` and `partialReason`, never `completed`. Review cadence state is persisted when `evolution-state` is available; without it, cadence can reset between turns. If a provider does not reuse a branch/background prefix (`cacheReadTokens` stays near zero while foreground reads hit), switch `reviewMode` to `inject`; that runs the review as a parent turn on the same request series.
25
25
 
26
26
  **Removed metadata:** `reviewProvider`, `reviewContextMessages`, `reviewMessageChars`, `reviewMaxDepth` and `reviewToolAllow` were declared but never read, so they are gone from the registry and the bundles. Provider/model come from the parent session header; native review sees the parent catalog but only the family allowlist executes, while PTC exposes only `run_code`.
27
27
  `memoryInterval` and `skillInterval` were removed from the live row schema in 0.48 (G0/S0.3). They survive only in the family's old-document migration table and doctor's old-key report; a deployment config that still spells them must be rewritten to `reviewMemoryInterval` and `reviewSkillInterval`.
package/lib/index.js CHANGED
@@ -752,65 +752,6 @@ var ReviewWriteLocks = class {
752
752
  });
753
753
  }
754
754
  };
755
- //#endregion
756
- //#region lib/types/review-limiter.js
757
- /** Maximum time a review may wait for a concurrency slot before the debt is
758
- * deferred to the next boundary. Kept separate from reviewTimeoutMs: queue
759
- * wait is not review execution time, and a prefix frozen through a long queue
760
- * may already be cold when the first request starts. */
761
- const AUX_REVIEW_QUEUE_TIMEOUT_MS = 3e4;
762
- /** A tiny FIFO semaphore whose waiters can be aborted by unload/timeout. */
763
- var ReviewLimiter = class {
764
- limit;
765
- active = 0;
766
- closed = false;
767
- waiters = [];
768
- constructor(limit) {
769
- this.limit = limit;
770
- if (!Number.isInteger(limit) || limit < 1) throw new Error("review limiter limit must be a positive integer");
771
- }
772
- /** Wait for a slot; undefined means the wait was aborted or the limiter closed. */
773
- async acquire(signal) {
774
- if (this.closed || signal?.aborted === true) return void 0;
775
- if (this.active < this.limit) {
776
- this.active += 1;
777
- return this.releaseOnce();
778
- }
779
- return await new Promise((resolve) => {
780
- const waiter = { resolve };
781
- if (signal !== void 0) {
782
- waiter.signal = signal;
783
- waiter.onAbort = () => {
784
- const index = this.waiters.indexOf(waiter);
785
- if (index >= 0) this.waiters.splice(index, 1);
786
- resolve(void 0);
787
- };
788
- signal.addEventListener("abort", waiter.onAbort, { once: true });
789
- }
790
- this.waiters.push(waiter);
791
- });
792
- }
793
- dispose() {
794
- this.closed = true;
795
- for (const waiter of this.waiters.splice(0)) {
796
- if (waiter.signal !== void 0 && waiter.onAbort !== void 0) waiter.signal.removeEventListener("abort", waiter.onAbort);
797
- waiter.resolve(void 0);
798
- }
799
- }
800
- releaseOnce() {
801
- let released = false;
802
- return () => {
803
- if (released) return;
804
- released = true;
805
- this.active -= 1;
806
- const waiter = this.waiters.shift();
807
- if (waiter === void 0) return;
808
- if (waiter.signal !== void 0 && waiter.onAbort !== void 0) waiter.signal.removeEventListener("abort", waiter.onAbort);
809
- this.active += 1;
810
- waiter.resolve(this.releaseOnce());
811
- };
812
- }
813
- };
814
755
  /**
815
756
  * Whether a message is a notice this plugin delivered, judged only by durable source fields.
816
757
  *
@@ -1297,6 +1238,13 @@ function apply(ctx, rawConfig = {}) {
1297
1238
  substantiveMinAgentChars: snapshot?.substantiveMinAgentChars ?? DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS,
1298
1239
  resetOnFire: false
1299
1240
  });
1241
+ if (event.data.reason.kind === "completed" && params().reviewMode === "aux") {
1242
+ const pendingAtBoundary = mergeDebt(pendingCadenceReviews.get(session.id), advanced.debt);
1243
+ if (pendingAtBoundary !== void 0) {
1244
+ if (pendingAtBoundary.memory) state.turnsSinceMemory = 0;
1245
+ if (pendingAtBoundary.skill) state.turnsSinceSkill = 0;
1246
+ }
1247
+ }
1300
1248
  await stateService?.saveReviewState(session.id, state);
1301
1249
  });
1302
1250
  const debt = advanced.debt;
@@ -1309,7 +1257,6 @@ function apply(ctx, rawConfig = {}) {
1309
1257
  pendingCadenceReviews.delete(session.id);
1310
1258
  if (params().reviewMode === "aux") {
1311
1259
  const scheduled = await scheduleAuxDebt(session, agent, pendingDebt, signal, "cadence");
1312
- if (scheduled.scheduled !== void 0) await consumeReviewDebt(session.id, scheduled.scheduled);
1313
1260
  if (scheduled.failed !== void 0) pendingCadenceReviews.set(session.id, scheduled.failed);
1314
1261
  return;
1315
1262
  }
@@ -1481,7 +1428,6 @@ function apply(ctx, rawConfig = {}) {
1481
1428
  */
1482
1429
  let inFlightControllers = /* @__PURE__ */ new Set();
1483
1430
  const reviewWriteLocks = new ReviewWriteLocks();
1484
- const auxLimiter = new ReviewLimiter(8);
1485
1431
  let ptcToolHost;
1486
1432
  /**
1487
1433
  * Freeze the parent prefix for an aux review.
@@ -1520,32 +1466,17 @@ function apply(ctx, rawConfig = {}) {
1520
1466
  skill: debt.skill ? await tryAuxReview(session, agent, "skill", signal, reason) : false
1521
1467
  });
1522
1468
  }
1523
- async function consumeReviewDebt(sessionId, debt) {
1524
- await withReviewStateLock(sessionId, async () => {
1525
- const service = ctx.get("evolutionState");
1526
- const state = await service?.loadReviewState(sessionId);
1527
- if (state === void 0 || state === null) return;
1528
- if (debt.memory) state.turnsSinceMemory = 0;
1529
- if (debt.skill) state.turnsSinceSkill = 0;
1530
- await service?.saveReviewState(sessionId, state);
1531
- });
1532
- }
1533
1469
  async function tryAuxReview(session, agent, kind, signal, reason) {
1534
- let runningByKind = auxRunning.get(session.id);
1535
- if (runningByKind === void 0) {
1536
- runningByKind = /* @__PURE__ */ new Map();
1537
- auxRunning.set(session.id, runningByKind);
1470
+ let running = auxRunning.get(session.id);
1471
+ if (running === void 0) {
1472
+ running = /* @__PURE__ */ new Set();
1473
+ auxRunning.set(session.id, running);
1538
1474
  }
1539
- const running = runningByKind.get(kind);
1540
- if (running !== void 0) {
1541
- running.rerun = kind;
1542
- return true;
1543
- }
1544
- const state = {};
1545
- runningByKind.set(kind, state);
1475
+ if (running.has(kind)) return false;
1476
+ running.add(kind);
1546
1477
  const releaseKind = () => {
1547
- runningByKind.delete(kind);
1548
- if (runningByKind.size === 0) auxRunning.delete(session.id);
1478
+ running.delete(kind);
1479
+ if (running.size === 0) auxRunning.delete(session.id);
1549
1480
  };
1550
1481
  const projectedPreset = ctx.get("sessionProjections")?.snapshot?.(session, ["agentPreset"])?.values?.agentPreset;
1551
1482
  const headerPreset = session.header?.agentPreset;
@@ -1554,7 +1485,13 @@ function apply(ctx, rawConfig = {}) {
1554
1485
  ctx.logger.info("dsh-evolution-review: minimal preset has no family review surface");
1555
1486
  return true;
1556
1487
  }
1557
- const triggerSeq = session.seq;
1488
+ const reviewParent = snapshotReviewParent(agent);
1489
+ const header = session.requestHeader();
1490
+ if (header === void 0) {
1491
+ releaseKind();
1492
+ ctx.logger.warn("dsh-evolution-review: aux review skipped — parent has no request header");
1493
+ return false;
1494
+ }
1558
1495
  const llm = llmPort(ctx)?.streamRaw;
1559
1496
  const toolsService = toolsPort(ctx);
1560
1497
  const tools = toolsService?.execute;
@@ -1565,46 +1502,11 @@ function apply(ctx, rawConfig = {}) {
1565
1502
  }
1566
1503
  const controller = new AbortController();
1567
1504
  inFlightControllers.add(controller);
1568
- let queueTimedOut = false;
1569
- const queueTimer = setTimeout(() => {
1570
- queueTimedOut = true;
1505
+ let timedOut = false;
1506
+ const timer = setTimeout(() => {
1507
+ timedOut = true;
1571
1508
  controller.abort();
1572
- }, AUX_REVIEW_QUEUE_TIMEOUT_MS);
1573
- let limiterRelease;
1574
- try {
1575
- limiterRelease = await auxLimiter.acquire(controller.signal);
1576
- } finally {
1577
- clearTimeout(queueTimer);
1578
- }
1579
- if (limiterRelease === void 0 || controller.signal.aborted) {
1580
- limiterRelease?.();
1581
- releaseKind();
1582
- inFlightControllers.delete(controller);
1583
- ctx.logger.warn(queueTimedOut ? "dsh-evolution-review: aux review queue wait exceeded " + String(AUX_REVIEW_QUEUE_TIMEOUT_MS) + "ms — debt deferred to the next boundary" : "dsh-evolution-review: aux review queue aborted (plugin unloading) — debt deferred to the next boundary");
1584
- return false;
1585
- }
1586
- let slotReleased = false;
1587
- const releaseSlot = () => {
1588
- if (slotReleased) return;
1589
- slotReleased = true;
1590
- limiterRelease?.();
1591
- };
1592
- if (session.seq !== triggerSeq) {
1593
- releaseKind();
1594
- inFlightControllers.delete(controller);
1595
- releaseSlot();
1596
- ctx.logger.warn("dsh-evolution-review: parent advanced before aux review admission — debt deferred");
1597
- return false;
1598
- }
1599
- const reviewParent = snapshotReviewParent(agent);
1600
- const header = session.requestHeader();
1601
- if (header === void 0) {
1602
- releaseKind();
1603
- inFlightControllers.delete(controller);
1604
- releaseSlot();
1605
- ctx.logger.warn("dsh-evolution-review: aux review skipped — parent has no request header");
1606
- return false;
1607
- }
1509
+ }, config.reviewTimeoutMs);
1608
1510
  const liveAuthority = () => ctx.get("evolutionMutationAuthority");
1609
1511
  const authority = liveAuthority();
1610
1512
  let leaseToken;
@@ -1612,8 +1514,8 @@ function apply(ctx, rawConfig = {}) {
1612
1514
  const lease = await authority.lease.acquire("background_review", "review:" + session.id + ":" + kind, Math.max(config.reviewTimeoutMs + 3e4, 6e4)).catch(() => void 0);
1613
1515
  if (lease === void 0 || !lease.ok) {
1614
1516
  releaseKind();
1517
+ clearTimeout(timer);
1615
1518
  inFlightControllers.delete(controller);
1616
- releaseSlot();
1617
1519
  ctx.logger.warn(lease === void 0 ? "dsh-evolution-review: aux review skipped — lease acquire failed" : "dsh-evolution-review: aux review already leased (" + lease.reason + ")");
1618
1520
  return false;
1619
1521
  }
@@ -1621,11 +1523,6 @@ function apply(ctx, rawConfig = {}) {
1621
1523
  }
1622
1524
  const reviewId = "aux-" + randomUUID();
1623
1525
  const startedAt = Date.now();
1624
- let timedOut = false;
1625
- const timer = setTimeout(() => {
1626
- timedOut = true;
1627
- controller.abort();
1628
- }, config.reviewTimeoutMs);
1629
1526
  let leaseRenewTimer;
1630
1527
  if (leaseToken !== void 0 && authority?.lease !== void 0) leaseRenewTimer = setInterval(() => {
1631
1528
  authority.lease.renew(leaseToken).then((record) => {
@@ -1669,7 +1566,6 @@ function apply(ctx, rawConfig = {}) {
1669
1566
  clearTimeout(timer);
1670
1567
  if (leaseRenewTimer !== void 0) clearInterval(leaseRenewTimer);
1671
1568
  inFlightControllers.delete(controller);
1672
- releaseSlot();
1673
1569
  if (leaseToken !== void 0 && authority?.lease !== void 0) await authority.lease.release(leaseToken).catch(() => {});
1674
1570
  ctx.logger.warn("dsh-evolution-review: aux review setup failed: " + (error instanceof Error ? error.message : String(error)));
1675
1571
  return false;
@@ -1743,7 +1639,6 @@ function apply(ctx, rawConfig = {}) {
1743
1639
  status = timedOut ? "timeout" : controller.signal.aborted ? "aborted" : "failed";
1744
1640
  ctx.logger.warn("dsh-evolution-review: aux review failed: " + error);
1745
1641
  } finally {
1746
- releaseSlot();
1747
1642
  clearTimeout(timer);
1748
1643
  if (leaseRenewTimer !== void 0) clearInterval(leaseRenewTimer);
1749
1644
  const finishedAt = Date.now();
@@ -1811,7 +1706,6 @@ function apply(ctx, rawConfig = {}) {
1811
1706
  ctx.logger.warn("dsh-evolution-review: PTC review child dispose failed: " + (disposeError instanceof Error ? disposeError.message : String(disposeError)));
1812
1707
  }
1813
1708
  if (leaseToken !== void 0 && authority?.lease !== void 0) await authority.lease.release(leaseToken).catch(() => {});
1814
- if (state.rerun !== void 0) tryAuxReview(session, agent, state.rerun, signal, reason);
1815
1709
  }
1816
1710
  })();
1817
1711
  return true;
@@ -1820,7 +1714,6 @@ function apply(ctx, rawConfig = {}) {
1820
1714
  for (const controller of inFlightControllers) controller.abort();
1821
1715
  inFlightControllers = /* @__PURE__ */ new Set();
1822
1716
  reviewWriteLocks.dispose();
1823
- auxLimiter.dispose();
1824
1717
  ptcToolHost?.dispose();
1825
1718
  sessionState.dispose();
1826
1719
  }, "dsh-evolution-review.cleanup");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-review",
3
3
  "description": "Background review orchestration (community build)",
4
- "version": "0.62.3",
4
+ "version": "0.62.4",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -29,8 +29,8 @@
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
31
  "@deepseek-ai/schemastery": "^3.18.5",
32
- "@lmzhen/dsh-evolution-core": "0.62.3",
33
- "@lmzhen/dsh-evolution-platform": "0.62.3"
32
+ "@lmzhen/dsh-evolution-core": "0.62.4",
33
+ "@lmzhen/dsh-evolution-platform": "0.62.4"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@deepseek-ai/cordis": "^4.0.5",
@@ -42,7 +42,7 @@
42
42
  "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
43
43
  "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
44
44
  "@deepseek-ai/dsh-session": "0.2.2-rc.5",
45
- "@lmzhen/dsh-evolution-core": "^0.62.3"
45
+ "@lmzhen/dsh-evolution-core": "^0.62.4"
46
46
  },
47
47
  "engines": {
48
48
  "dsh": "0.2.2-rc.5"
@@ -1,36 +0,0 @@
1
- /**
2
- * Process-local bound on concurrent AUX reviews.
3
- *
4
- * One semaphore for the plugin instance, no per-session or weighted fairness.
5
- * A review waits for a slot before its first model request; the bounded queue
6
- * keeps a burst of sessions from opening unbounded LLM streams. This is a
7
- * provider/CPU budget, not a correctness guard: cross-review writes are already
8
- * serialized by the review write locks and the mutation-authority lease.
9
- *
10
- * 8 slots matches the observed burst size of normal multi-session use: a long
11
- * queue can outlive the parent prefix cache and turn a warm aux review into a
12
- * cold one. Callers that need a different budget can construct their own
13
- * limiter; this constant is the shipped default.
14
- *
15
- * @module @lmzhen/dsh-evolution-review/review-limiter
16
- */
17
- /** Shipped default for concurrent aux reviews. */
18
- export declare const AUX_REVIEW_CONCURRENCY = 8;
19
- /** Maximum time a review may wait for a concurrency slot before the debt is
20
- * deferred to the next boundary. Kept separate from reviewTimeoutMs: queue
21
- * wait is not review execution time, and a prefix frozen through a long queue
22
- * may already be cold when the first request starts. */
23
- export declare const AUX_REVIEW_QUEUE_TIMEOUT_MS = 30000;
24
- /** A tiny FIFO semaphore whose waiters can be aborted by unload/timeout. */
25
- export declare class ReviewLimiter {
26
- private readonly limit;
27
- private active;
28
- private closed;
29
- private readonly waiters;
30
- constructor(limit: number);
31
- /** Wait for a slot; undefined means the wait was aborted or the limiter closed. */
32
- acquire(signal?: AbortSignal): Promise<(() => void) | undefined>;
33
- dispose(): void;
34
- private releaseOnce;
35
- }
36
- //# sourceMappingURL=review-limiter.d.ts.map