Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

refactor(line): share the exact total WIP cap [N2,R1,H16]

Corey Olson0e837e30ad28
diff --git a/docs/formats.md b/docs/formats.md
index 38dde806..9652570b 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -629,4 +629,4 @@ its number at landing; no event-log or envelope format changes.
With `reviewsFirst` on, ordinary `next` offers an eligible review before a build when outstanding submissions exceed `wipPerReviewer` times the active-reviewer count (or ratio 3 while that numeric control is off). No permanent builder/reviewer seat type or role flag is required. Active reviewers are distinct registered seats with a reservation or verdict inside the flow window; its default is the last hour, and an empty window counts as one reviewer. The window uses the same validated boundaries as `stats --window`.
-With numeric `wipPerReviewer` on, a new claim that would exceed that limit is refused as `LINE_WIP_LIMIT`, naming the oldest eligible pending review when there is one. Live claimed items and outstanding submissions count; expired claims do not. Renewals remain possible. The native claim carries the configured verifier and family policies so its suggested review never relaxes those guards. With `takeoverMinutes` on, a sent-back item's idle interval can end its original builder's first-refusal window early; a live claim is never stolen, and normal claim appends preserve the old history. Disabled controls retain the previous behavior. New claims under these controls carry a true `lineCapacity` argument and the line-capacity engine floor; marker-absent older recorded claims keep their historical meaning during replay.
+With numeric `wipPerReviewer` on, a new claim that would exceed that limit is refused as `LINE_WIP_LIMIT`, naming the oldest eligible pending review when there is one. Live claimed items and outstanding submissions count; expired claims do not. The shared pure `lineWipLimit` function computes the total cap without rounding, using at least one observed reviewer. Renewals remain possible. The native claim carries the configured verifier and family policies so its suggested review never relaxes those guards. With `takeoverMinutes` on, a sent-back item's idle interval can end its original builder's first-refusal window early; a live claim is never stolen, and normal claim appends preserve the old history. Disabled controls retain the previous behavior. New claims under these controls carry a true `lineCapacity` argument and the line-capacity engine floor; marker-absent older recorded claims keep their historical meaning during replay.
diff --git a/src/board.js b/src/board.js
index c26ea838..2dae9085 100644
--- a/src/board.js
+++ b/src/board.js
@@ -1,3 +1,4 @@
+import { lineWipLimit } from './line-wip-limit.js';
import { capacitySettings, lineCapacitySnapshot, lineCapacityProblem } from './line-capacity.js';
import {
lineOrderEnabled,
@@ -1268,7 +1269,7 @@ export function reviewOffer(board, { agentId, lane, policy = 'any', familyPolicy
const settings = capacitySettings(board);
const capacity = settings.reviewsFirst === true ? lineCapacitySnapshot(board) : null;
if (capacity) ratio = typeof settings.wipPerReviewer === 'number' ? settings.wipPerReviewer : 3;
- if (capacity ? queue.pending <= ratio * capacity.activeReviewers : queue.pending < ratio * Math.max(queue.reviewing, 1)) return null;
+ if (capacity ? queue.pending <= lineWipLimit(ratio, capacity.activeReviewers) : queue.pending < ratio * Math.max(queue.reviewing, 1)) return null;
const { item } = nextFor(board, { agentId, lane, verify: true, policy, familyPolicy, runnable, routes });
return item ? { item, queue, ratio } : null;
}
diff --git a/src/line-capacity.js b/src/line-capacity.js
index 862d4e9d..58be301c 100644
--- a/src/line-capacity.js
+++ b/src/line-capacity.js
@@ -4,6 +4,7 @@ import { LINE_CAPACITY_ENGINE } from './line-capacity-engine.js';
import { lineSettings } from './line-settings.js';
import { flowWindowBounds } from './stats-flow-window.js';
import { Refused } from './refused.js';
+import { lineWipLimit } from './line-wip-limit.js';
/** Old ordered claims keep their original semantics even beside newer recorded controls. */
export function capacitySettings(board) {
@@ -28,7 +29,7 @@ export function lineCapacityProblem(board, { renewal, oldestReview } = {}) {
const ratio = capacitySettings(board).wipPerReviewer;
if (renewal || typeof ratio !== 'number') return null;
const snapshot = lineCapacitySnapshot(board);
- const limit = ratio * snapshot.activeReviewers;
+ const limit = lineWipLimit(ratio, snapshot.activeReviewers);
if (snapshot.wip + 1 <= limit) return null;
const review = oldestReview?.(snapshot.pending);
return new Refused('LINE_WIP_LIMIT', `the line has ${snapshot.wip} live claims and submissions against limit ${limit}; `
diff --git a/src/line-wip-limit.js b/src/line-wip-limit.js
new file mode 100644
index 00000000..b42d776f
--- /dev/null
+++ b/src/line-wip-limit.js
@@ -0,0 +1,12 @@
+/** One pure total-WIP cap for recorded native decisions and counterfactual replay [N2,R1,H16]. */
+/**
+ * Return the cap from an already validated line-setting ratio and observed distinct reviewer count.
+ * Off has no cap; an empty observation window uses one reviewer. Fractional caps are not rounded:
+ * the next integer item may enter only while the resulting total stays at or below this number.
+ * @param {number|false} ratio
+ * @param {number} activeReviewers - Nonnegative integer from the shared observation window.
+ * @returns {number|null}
+ */
+export function lineWipLimit(ratio, activeReviewers) {
+ return ratio === false ? null : ratio * Math.max(1, activeReviewers);
+}
diff --git a/test/line-capacity.test.js b/test/line-capacity.test.js
index 70c40c66..011cdd22 100644
--- a/test/line-capacity.test.js
+++ b/test/line-capacity.test.js
@@ -99,3 +99,16 @@ test('old recorded claims ignore new capacity while new claims retain the featur
assert.equal(current.error?.code, 'LINE_WIP_LIMIT');
assert.equal(store.getItem(replica, id).item_status, 'open');
});
+
+test('the total cap covers builds and submitted work together without rounding a fractional allowance [N2,R1,H16]', t => {
+ const f = fixture(t), first = f.submit('first'), second = f.submit('second');
+ store.reserveReview(f.board, first, { agentId: f.reviewer, leaseMs: HOUR, policy: 'any' });
+ store.reserveReview(f.board, second, { agentId: 'coordinator', leaseMs: HOUR, policy: 'any' });
+ f.setting('wipPerReviewer', 1.5);
+ const third = store.addItem(f.board, { by: 'coordinator', lane: 'core', title: 'third total item' });
+ const fourth = store.addItem(f.board, { by: 'coordinator', lane: 'core', title: 'fourth total item' });
+ f.claim(third);
+ assert.equal(lineCapacitySnapshot(f.board).wip, 3, 'two pending submissions and one live build consume the same cap');
+ assert.throws(() => f.claim(fourth, f.reviewer), { code: 'LINE_WIP_LIMIT' });
+ assert.equal(store.getItem(f.board, fourth).item_status, 'open');
+});