@igorjpimenta/winch 2026.11.26-beta.1 → 2026.11.27-beta.2
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 +5 -4
- package/package.json +1 -1
- package/plugins/README.md +4 -5
- package/plugins/openclaw/winch/README.md +1 -1
- package/plugins/openclaw/winch/package.json +1 -1
- package/plugins/opencode/winch/package.json +1 -1
- package/src/webhook/core.js +41 -2
- package/src/webhook/delivery.js +39 -18
package/README.md
CHANGED
|
@@ -112,10 +112,11 @@ is the single scheduler:
|
|
|
112
112
|
`story.assigned`, `task.appended` (to the epic creator), and
|
|
113
113
|
`epic.completed` (to the epic creator).
|
|
114
114
|
- It writes each wake to `admission_queue`, creates a stable `dispatch_events`
|
|
115
|
-
row, one delivery row
|
|
116
|
-
|
|
117
|
-
the
|
|
118
|
-
dispatcher
|
|
115
|
+
row, one delivery row for the attempt's owner, and a per-attempt audit row.
|
|
116
|
+
Only the owner is delivered to, as `execution: "active"`; the other consumers
|
|
117
|
+
of the harness are not poked at all. If the owner fails or its lease expires,
|
|
118
|
+
the dispatcher hands the attempt to another consumer, bumps `leaseEpoch`, and
|
|
119
|
+
delivers that as active.
|
|
119
120
|
- An offer reserves capacity until it is claimed, closes, or expires. Failed
|
|
120
121
|
deliveries and expired offers requeue with backoff. Planner wakes
|
|
121
122
|
(`story`/`append`/`review`) are one-shot only after `backlog_accept_wake`
|
package/package.json
CHANGED
package/plugins/README.md
CHANGED
|
@@ -125,11 +125,10 @@ Two more rows matter to the dispatcher:
|
|
|
125
125
|
not on every replay.
|
|
126
126
|
|
|
127
127
|
Dispatch is delivered by HTTP, not polled. `202` means the receiver accepted
|
|
128
|
-
the request. Each
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
active route dies or its lease expires, the dispatcher promotes a standby and
|
|
128
|
+
the request. Each attempt is delivered to its owner only, as
|
|
129
|
+
`execution: "active"`, with its own delivery row and per-attempt audit row. The
|
|
130
|
+
other consumers of the harness are not contacted. If the owner's route dies or
|
|
131
|
+
its lease expires, the dispatcher hands the attempt to another consumer and
|
|
133
132
|
bumps `leaseEpoch`.
|
|
134
133
|
|
|
135
134
|
Planner wakes (`story`, `append`, `review`) require `backlog_accept_wake` with
|
|
@@ -6,7 +6,7 @@ OpenClaw companion for [winch](https://github.com/igorjpimenta/winch). Four jobs
|
|
|
6
6
|
onto every winch MCP tool call, overwriting unconditionally so model-supplied
|
|
7
7
|
meta cannot impersonate an agent.
|
|
8
8
|
2. **Wake receiver** — serves `POST /api/winch/dispatch`, verifies the
|
|
9
|
-
executor bearer,
|
|
9
|
+
executor bearer, deduplicates on
|
|
10
10
|
`admissionId + attemptNo`, and starts a one-shot session. Tasks use
|
|
11
11
|
`backlog_claim`; planner wakes must call `backlog_accept_wake` with the
|
|
12
12
|
payload lease before working.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@igorjpimenta/winch-openclaw",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.27-beta.2",
|
|
4
4
|
"description": "OpenClaw companion for winch: stamps caller identity on winch MCP tool calls, receives HTTP dispatch wakes, and reconciles in-progress work.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@igorjpimenta/winch-opencode",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.27-beta.2",
|
|
4
4
|
"description": "OpenCode companion for winch: stamps agent and session identity on winch tool calls, receives HTTP dispatch wakes, reports LLM usage, and reconciles assigned in-progress work. No SDK dependency \u2014 a plain id/setup/server export.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/webhook/core.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// winner starts a session. Item status remains the work acknowledgement.
|
|
4
4
|
|
|
5
5
|
import { HUMAN_AGENT, HUMAN_HARNESS } from "../reserved.js";
|
|
6
|
+
import { readyTasks } from "../ready-queue.js";
|
|
6
7
|
import { pickConsumer } from "./delivery.js";
|
|
7
8
|
|
|
8
9
|
const RELEASING_STATUSES = new Set(["done", "cancelled", "blocked", "backlog", "review"]);
|
|
@@ -208,8 +209,8 @@ export function recover(store, { harness, consumerId = null, at = Date.now(), co
|
|
|
208
209
|
const usedHarness = activeHarness + keptOffers.length;
|
|
209
210
|
const usedGlobal = activeGlobal + otherReserved + keptOffers.length;
|
|
210
211
|
let free = Math.max(0, Math.min(
|
|
211
|
-
config.dispatchHarnessMax - usedHarness,
|
|
212
|
-
config.dispatchGlobalMax - usedGlobal,
|
|
212
|
+
(config.dispatchHarnessMax ?? 8) - usedHarness,
|
|
213
|
+
(config.dispatchGlobalMax ?? 16) - usedGlobal,
|
|
213
214
|
));
|
|
214
215
|
if (mutate) for (const row of store.admission.queued(harness, at)) {
|
|
215
216
|
if (free <= 0 || (consumerId && windowFree <= 0)) break;
|
|
@@ -238,6 +239,44 @@ export function recover(store, { harness, consumerId = null, at = Date.now(), co
|
|
|
238
239
|
free--;
|
|
239
240
|
}
|
|
240
241
|
|
|
242
|
+
// A ready task whose last admission expired is otherwise dormant: only a new
|
|
243
|
+
// item event would enqueue it again. Recovery is the restart path, so it
|
|
244
|
+
// re-admits ready assigned work for this harness within the same caps.
|
|
245
|
+
if (mutate) for (const candidate of readyTasks(store, { harness, limit: free + 1 })) {
|
|
246
|
+
if (free <= 0 || (consumerId && windowFree <= 0)) break;
|
|
247
|
+
const agent = candidate.task.assignee_agent;
|
|
248
|
+
if (!agent || isHuman(agent, candidate.task.assignee_harness)) continue;
|
|
249
|
+
const busy = store.db.prepare(`
|
|
250
|
+
SELECT 1 FROM admission_queue WHERE item_id=? AND harness=? AND ended_at IS NULL
|
|
251
|
+
`).get(candidate.task.id, harness);
|
|
252
|
+
if (busy) continue;
|
|
253
|
+
const queued = store.admission.enqueue({ kind: "task", itemId: candidate.task.id, harness, agentId: agent, at });
|
|
254
|
+
if (!queued) continue;
|
|
255
|
+
const next = store.admission.markOffered(queued.id, at, {
|
|
256
|
+
pickActive: (attemptNo) => pickConsumer(store, { ...queued, attempt_no: attemptNo }),
|
|
257
|
+
leaseMs: config.dispatchConsumerTtlMs,
|
|
258
|
+
});
|
|
259
|
+
if (!next) continue;
|
|
260
|
+
start.push({
|
|
261
|
+
admissionId: next.id,
|
|
262
|
+
itemId: next.item_id,
|
|
263
|
+
attemptNo: next.attempt_no ?? null,
|
|
264
|
+
kind: next.kind,
|
|
265
|
+
agent: next.agent_id,
|
|
266
|
+
harness: next.harness,
|
|
267
|
+
eventId: next.event_id ?? null,
|
|
268
|
+
offerExpiresAt: at + config.dispatchOfferMs,
|
|
269
|
+
activeConsumerId: next.active_consumer_id ?? null,
|
|
270
|
+
leaseEpoch: next.lease_epoch ?? 0,
|
|
271
|
+
status: "offered",
|
|
272
|
+
});
|
|
273
|
+
if (consumerId) {
|
|
274
|
+
windowFree--;
|
|
275
|
+
store.delivery.markRunning({ admissionId: next.id, attemptNo: next.attempt_no ?? null, consumerId, at });
|
|
276
|
+
}
|
|
277
|
+
free--;
|
|
278
|
+
}
|
|
279
|
+
|
|
241
280
|
return { resume, start: consumerId ? start.filter((row) => row.activeConsumerId === consumerId) : start, free };
|
|
242
281
|
}
|
|
243
282
|
|
package/src/webhook/delivery.js
CHANGED
|
@@ -25,6 +25,12 @@ export function pickConsumer(store, row) {
|
|
|
25
25
|
return hashPick(consumers, `${row.id}:${row.attempt_no ?? 0}`)?.id ?? null;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
// A dead delivery is only terminal when no other consumer can take the attempt;
|
|
29
|
+
// otherwise promoteStranded hands it over on the next pass.
|
|
30
|
+
function hasSuccessor(store, row) {
|
|
31
|
+
return consumersFor(store, row.harness).some((consumer) => consumer.id !== row.active_consumer_id);
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
export function wakePayload(row, { at = Date.now(), offerMs = 120000, execution = "active", leaseEpoch = 0 } = {}) {
|
|
29
35
|
return {
|
|
30
36
|
type: "wake",
|
|
@@ -63,8 +69,14 @@ function permanent(status) {
|
|
|
63
69
|
return status >= 400 && status < 500 && status !== 408 && status !== 425 && status !== 429;
|
|
64
70
|
}
|
|
65
71
|
|
|
72
|
+
// Only the attempt owner gets a delivery. A non-owner has no session to start
|
|
73
|
+
// and cannot settle, so a notice to it would hold a wake-window slot for the
|
|
74
|
+
// whole lease. Ownership moves through promoteStranded, which creates the
|
|
75
|
+
// successor's delivery.
|
|
66
76
|
export function ensureDeliveries(store, row, { at = Date.now() } = {}) {
|
|
67
77
|
const consumers = consumersFor(store, row.harness);
|
|
78
|
+
const owner = consumers.find((consumer) => consumer.id === row.active_consumer_id);
|
|
79
|
+
if (!owner) return [];
|
|
68
80
|
const event = row.attempt_no == null ? null : store.dispatchEvent.ensure({
|
|
69
81
|
admissionId: row.id,
|
|
70
82
|
attemptNo: row.attempt_no,
|
|
@@ -73,16 +85,14 @@ export function ensureDeliveries(store, row, { at = Date.now() } = {}) {
|
|
|
73
85
|
payload: wakePayload(row, { at, leaseEpoch: row.lease_epoch ?? 0 }),
|
|
74
86
|
at,
|
|
75
87
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return consumers;
|
|
88
|
+
store.delivery.ensure({
|
|
89
|
+
admissionId: row.id,
|
|
90
|
+
attemptNo: row.attempt_no,
|
|
91
|
+
consumerId: owner.id,
|
|
92
|
+
eventId: event?.id ?? null,
|
|
93
|
+
at,
|
|
94
|
+
});
|
|
95
|
+
return [owner];
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
async function deliverOne(store, delivery, row, { config, logger, at }) {
|
|
@@ -103,7 +113,14 @@ async function deliverOne(store, delivery, row, { config, logger, at }) {
|
|
|
103
113
|
store.delivery.defer(delivery.id, { nextAt: at + 1000, at });
|
|
104
114
|
return { ok: false, consumerId: delivery.consumer_id, status: 0, error: "wake window full" };
|
|
105
115
|
}
|
|
106
|
-
|
|
116
|
+
if (row.active_consumer_id !== delivery.consumer_id) {
|
|
117
|
+
// Ownership moved after this row was queued; the successor has its own
|
|
118
|
+
// delivery, so this one must not reach a non-owner.
|
|
119
|
+
store.delivery.markDead(delivery.id, { error: "not the attempt owner", at });
|
|
120
|
+
store.delivery.recordAttempt({ deliveryId: delivery.id, attemptNo: delivery.attempts + 1, status: "cancelled", error: "not the attempt owner", at });
|
|
121
|
+
return { ok: false, consumerId: delivery.consumer_id, status: 0, error: "not the attempt owner" };
|
|
122
|
+
}
|
|
123
|
+
const execution = "active";
|
|
107
124
|
const payload = wakePayload(row, {
|
|
108
125
|
offerMs: config.dispatchOfferMs,
|
|
109
126
|
execution,
|
|
@@ -200,11 +217,11 @@ export async function deliverDue(store, { config = store.config, logger = null,
|
|
|
200
217
|
const row = store.admission.get(admissionId);
|
|
201
218
|
if (row && ["offered", "accepted"].includes(row.status)) {
|
|
202
219
|
const all = store.delivery.allForAttempt(row.id, row.attempt_no);
|
|
203
|
-
if (all.length && all.every((d) => d.status === "dead")) store.admission.fail(row.id, at);
|
|
220
|
+
if (all.length && all.every((d) => d.status === "dead") && !hasSuccessor(store, row)) store.admission.fail(row.id, at);
|
|
204
221
|
}
|
|
205
222
|
}
|
|
206
223
|
const exhausted = store.db.prepare(`
|
|
207
|
-
SELECT q.id
|
|
224
|
+
SELECT q.id, q.harness, aa.active_consumer_id
|
|
208
225
|
FROM admission_queue q
|
|
209
226
|
JOIN admission_attempts aa ON aa.admission_id=q.id AND aa.ended_at IS NULL
|
|
210
227
|
WHERE q.status IN ('offered','accepted') AND q.ended_at IS NULL
|
|
@@ -214,18 +231,22 @@ export async function deliverDue(store, { config = store.config, logger = null,
|
|
|
214
231
|
WHERE d.admission_id=q.id AND d.attempt_no=aa.attempt_no
|
|
215
232
|
AND d.status != 'dead')
|
|
216
233
|
`).all();
|
|
217
|
-
for (const row of exhausted) store.admission.fail(row.id, at);
|
|
234
|
+
for (const row of exhausted) if (!hasSuccessor(store, row)) store.admission.fail(row.id, at);
|
|
218
235
|
return results;
|
|
219
236
|
}
|
|
220
237
|
|
|
221
238
|
export async function deliverWake(store, row, { config = store.config, logger = null, at = Date.now() } = {}) {
|
|
222
|
-
|
|
239
|
+
promoteStranded(store, { at, config });
|
|
240
|
+
const current = store.admission.get(row.id) ?? row;
|
|
241
|
+
const consumers = ensureDeliveries(store, current, { at });
|
|
223
242
|
if (consumers.length === 0) {
|
|
224
|
-
store.
|
|
225
|
-
|
|
243
|
+
if (consumersFor(store, current.harness).length === 0) {
|
|
244
|
+
store.admission.fail(current.id, at);
|
|
245
|
+
logger?.warn?.(`winch: no dispatch endpoint for ${current.harness}; requeueing ${current.id}`);
|
|
246
|
+
}
|
|
226
247
|
return { ok: false, delivered: [], failed: [] };
|
|
227
248
|
}
|
|
228
|
-
const results = await deliverDue(store, { config, logger, at, admissionId:
|
|
249
|
+
const results = await deliverDue(store, { config, logger, at, admissionId: current.id });
|
|
229
250
|
const delivered = results.filter((r) => r.ok);
|
|
230
251
|
const failed = results.filter((r) => !r.ok);
|
|
231
252
|
return { ok: delivered.length > 0, delivered, failed };
|