@lmzhen/dsh-evolution-review 0.62.2 → 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. 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
@@ -197,6 +197,7 @@ async function runReview(input) {
197
197
  const stream = streamReviewModel(llm, {
198
198
  provider: header.config.provider,
199
199
  model: header.config.model,
200
+ sessionId: parent.session.id,
200
201
  ...header.config.reasoningEffort === void 0 ? {} : { reasoningEffort: header.config.reasoningEffort },
201
202
  ...header.config.temperature === void 0 ? {} : { temperature: header.config.temperature },
202
203
  ...header.config.maxTokens === void 0 ? {} : { maxTokens: header.config.maxTokens },
@@ -751,60 +752,6 @@ var ReviewWriteLocks = class {
751
752
  });
752
753
  }
753
754
  };
754
- //#endregion
755
- //#region lib/types/review-limiter.js
756
- /** A tiny FIFO semaphore whose waiters can be aborted by unload/timeout. */
757
- var ReviewLimiter = class {
758
- limit;
759
- active = 0;
760
- closed = false;
761
- waiters = [];
762
- constructor(limit) {
763
- this.limit = limit;
764
- if (!Number.isInteger(limit) || limit < 1) throw new Error("review limiter limit must be a positive integer");
765
- }
766
- /** Wait for a slot; undefined means the wait was aborted or the limiter closed. */
767
- async acquire(signal) {
768
- if (this.closed || signal?.aborted === true) return void 0;
769
- if (this.active < this.limit) {
770
- this.active += 1;
771
- return this.releaseOnce();
772
- }
773
- return await new Promise((resolve) => {
774
- const waiter = { resolve };
775
- if (signal !== void 0) {
776
- waiter.signal = signal;
777
- waiter.onAbort = () => {
778
- const index = this.waiters.indexOf(waiter);
779
- if (index >= 0) this.waiters.splice(index, 1);
780
- resolve(void 0);
781
- };
782
- signal.addEventListener("abort", waiter.onAbort, { once: true });
783
- }
784
- this.waiters.push(waiter);
785
- });
786
- }
787
- dispose() {
788
- this.closed = true;
789
- for (const waiter of this.waiters.splice(0)) {
790
- if (waiter.signal !== void 0 && waiter.onAbort !== void 0) waiter.signal.removeEventListener("abort", waiter.onAbort);
791
- waiter.resolve(void 0);
792
- }
793
- }
794
- releaseOnce() {
795
- let released = false;
796
- return () => {
797
- if (released) return;
798
- released = true;
799
- this.active -= 1;
800
- const waiter = this.waiters.shift();
801
- if (waiter === void 0) return;
802
- if (waiter.signal !== void 0 && waiter.onAbort !== void 0) waiter.signal.removeEventListener("abort", waiter.onAbort);
803
- this.active += 1;
804
- waiter.resolve(this.releaseOnce());
805
- };
806
- }
807
- };
808
755
  /**
809
756
  * Whether a message is a notice this plugin delivered, judged only by durable source fields.
810
757
  *
@@ -1291,6 +1238,13 @@ function apply(ctx, rawConfig = {}) {
1291
1238
  substantiveMinAgentChars: snapshot?.substantiveMinAgentChars ?? DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS,
1292
1239
  resetOnFire: false
1293
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
+ }
1294
1248
  await stateService?.saveReviewState(session.id, state);
1295
1249
  });
1296
1250
  const debt = advanced.debt;
@@ -1303,7 +1257,6 @@ function apply(ctx, rawConfig = {}) {
1303
1257
  pendingCadenceReviews.delete(session.id);
1304
1258
  if (params().reviewMode === "aux") {
1305
1259
  const scheduled = await scheduleAuxDebt(session, agent, pendingDebt, signal, "cadence");
1306
- if (scheduled.scheduled !== void 0) await consumeReviewDebt(session.id, scheduled.scheduled);
1307
1260
  if (scheduled.failed !== void 0) pendingCadenceReviews.set(session.id, scheduled.failed);
1308
1261
  return;
1309
1262
  }
@@ -1475,7 +1428,6 @@ function apply(ctx, rawConfig = {}) {
1475
1428
  */
1476
1429
  let inFlightControllers = /* @__PURE__ */ new Set();
1477
1430
  const reviewWriteLocks = new ReviewWriteLocks();
1478
- const auxLimiter = new ReviewLimiter(8);
1479
1431
  let ptcToolHost;
1480
1432
  /**
1481
1433
  * Freeze the parent prefix for an aux review.
@@ -1514,32 +1466,17 @@ function apply(ctx, rawConfig = {}) {
1514
1466
  skill: debt.skill ? await tryAuxReview(session, agent, "skill", signal, reason) : false
1515
1467
  });
1516
1468
  }
1517
- async function consumeReviewDebt(sessionId, debt) {
1518
- await withReviewStateLock(sessionId, async () => {
1519
- const service = ctx.get("evolutionState");
1520
- const state = await service?.loadReviewState(sessionId);
1521
- if (state === void 0 || state === null) return;
1522
- if (debt.memory) state.turnsSinceMemory = 0;
1523
- if (debt.skill) state.turnsSinceSkill = 0;
1524
- await service?.saveReviewState(sessionId, state);
1525
- });
1526
- }
1527
1469
  async function tryAuxReview(session, agent, kind, signal, reason) {
1528
- let runningByKind = auxRunning.get(session.id);
1529
- if (runningByKind === void 0) {
1530
- runningByKind = /* @__PURE__ */ new Map();
1531
- auxRunning.set(session.id, runningByKind);
1532
- }
1533
- const running = runningByKind.get(kind);
1534
- if (running !== void 0) {
1535
- running.rerun = kind;
1536
- return true;
1470
+ let running = auxRunning.get(session.id);
1471
+ if (running === void 0) {
1472
+ running = /* @__PURE__ */ new Set();
1473
+ auxRunning.set(session.id, running);
1537
1474
  }
1538
- const state = {};
1539
- runningByKind.set(kind, state);
1475
+ if (running.has(kind)) return false;
1476
+ running.add(kind);
1540
1477
  const releaseKind = () => {
1541
- runningByKind.delete(kind);
1542
- if (runningByKind.size === 0) auxRunning.delete(session.id);
1478
+ running.delete(kind);
1479
+ if (running.size === 0) auxRunning.delete(session.id);
1543
1480
  };
1544
1481
  const projectedPreset = ctx.get("sessionProjections")?.snapshot?.(session, ["agentPreset"])?.values?.agentPreset;
1545
1482
  const headerPreset = session.header?.agentPreset;
@@ -1563,32 +1500,29 @@ function apply(ctx, rawConfig = {}) {
1563
1500
  ctx.logger.warn("dsh-evolution-review: aux review skipped — llm/tools service is not mounted");
1564
1501
  return false;
1565
1502
  }
1503
+ const controller = new AbortController();
1504
+ inFlightControllers.add(controller);
1505
+ let timedOut = false;
1506
+ const timer = setTimeout(() => {
1507
+ timedOut = true;
1508
+ controller.abort();
1509
+ }, config.reviewTimeoutMs);
1566
1510
  const liveAuthority = () => ctx.get("evolutionMutationAuthority");
1567
1511
  const authority = liveAuthority();
1568
1512
  let leaseToken;
1569
1513
  if (authority?.lease !== void 0) {
1570
1514
  const lease = await authority.lease.acquire("background_review", "review:" + session.id + ":" + kind, Math.max(config.reviewTimeoutMs + 3e4, 6e4)).catch(() => void 0);
1571
- if (lease === void 0) {
1572
- releaseKind();
1573
- ctx.logger.warn("dsh-evolution-review: aux review skipped — lease acquire failed");
1574
- return false;
1575
- }
1576
- if (!lease.ok) {
1515
+ if (lease === void 0 || !lease.ok) {
1577
1516
  releaseKind();
1578
- ctx.logger.warn("dsh-evolution-review: aux review already leased (" + lease.reason + ")");
1517
+ clearTimeout(timer);
1518
+ inFlightControllers.delete(controller);
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 + ")");
1579
1520
  return false;
1580
1521
  }
1581
1522
  leaseToken = lease.token;
1582
1523
  }
1583
1524
  const reviewId = "aux-" + randomUUID();
1584
1525
  const startedAt = Date.now();
1585
- const controller = new AbortController();
1586
- inFlightControllers.add(controller);
1587
- let timedOut = false;
1588
- const timer = setTimeout(() => {
1589
- timedOut = true;
1590
- controller.abort();
1591
- }, config.reviewTimeoutMs);
1592
1526
  let leaseRenewTimer;
1593
1527
  if (leaseToken !== void 0 && authority?.lease !== void 0) leaseRenewTimer = setInterval(() => {
1594
1528
  authority.lease.renew(leaseToken).then((record) => {
@@ -1655,10 +1589,7 @@ function apply(ctx, rawConfig = {}) {
1655
1589
  let hitRoundLimit = false;
1656
1590
  let report;
1657
1591
  let error;
1658
- let limiterRelease;
1659
1592
  try {
1660
- limiterRelease = await auxLimiter.acquire(controller.signal);
1661
- if (limiterRelease === void 0) throw new Error("aux review queue aborted");
1662
1593
  const prompt = reviewPrompt(kind, "aux") + "\n\nWhen all durable changes for this review are complete, call review_done as the only tool call in your final batch. Do not call it while more edits remain. A precise no-op is still a completed review: always finish with review_done and an unchanged report instead of stopping without it. If a write is locked, call review_wait once, then re-read the target and retry; never reapply a stale patch." + (channel.instruction === void 0 ? "" : "\n\n" + channel.instruction);
1663
1594
  const result = await withReviewContext({
1664
1595
  reviewId,
@@ -1708,7 +1639,6 @@ function apply(ctx, rawConfig = {}) {
1708
1639
  status = timedOut ? "timeout" : controller.signal.aborted ? "aborted" : "failed";
1709
1640
  ctx.logger.warn("dsh-evolution-review: aux review failed: " + error);
1710
1641
  } finally {
1711
- limiterRelease?.();
1712
1642
  clearTimeout(timer);
1713
1643
  if (leaseRenewTimer !== void 0) clearInterval(leaseRenewTimer);
1714
1644
  const finishedAt = Date.now();
@@ -1776,7 +1706,6 @@ function apply(ctx, rawConfig = {}) {
1776
1706
  ctx.logger.warn("dsh-evolution-review: PTC review child dispose failed: " + (disposeError instanceof Error ? disposeError.message : String(disposeError)));
1777
1707
  }
1778
1708
  if (leaseToken !== void 0 && authority?.lease !== void 0) await authority.lease.release(leaseToken).catch(() => {});
1779
- if (state.rerun !== void 0) tryAuxReview(session, agent, state.rerun, signal, reason);
1780
1709
  }
1781
1710
  })();
1782
1711
  return true;
@@ -1785,7 +1714,6 @@ function apply(ctx, rawConfig = {}) {
1785
1714
  for (const controller of inFlightControllers) controller.abort();
1786
1715
  inFlightControllers = /* @__PURE__ */ new Set();
1787
1716
  reviewWriteLocks.dispose();
1788
- auxLimiter.dispose();
1789
1717
  ptcToolHost?.dispose();
1790
1718
  sessionState.dispose();
1791
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.2",
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.2",
33
- "@lmzhen/dsh-evolution-platform": "0.62.2"
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.2"
45
+ "@lmzhen/dsh-evolution-core": "^0.62.4"
46
46
  },
47
47
  "engines": {
48
48
  "dsh": "0.2.2-rc.5"
@@ -1,31 +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
- /** A tiny FIFO semaphore whose waiters can be aborted by unload/timeout. */
20
- export declare class ReviewLimiter {
21
- private readonly limit;
22
- private active;
23
- private closed;
24
- private readonly waiters;
25
- constructor(limit: number);
26
- /** Wait for a slot; undefined means the wait was aborted or the limiter closed. */
27
- acquire(signal?: AbortSignal): Promise<(() => void) | undefined>;
28
- dispose(): void;
29
- private releaseOnce;
30
- }
31
- //# sourceMappingURL=review-limiter.d.ts.map