Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/reference/network-connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ a deadline of 60 seconds, so one slow hub doesn't hold the others. With no activ
closes the way its queue closes one: done with the resolution and the closure reason (`no-follow-on`, `canceled`
or `denied`), or failed when the local item failed. A close with no resolution sends the closer's own note on that
close, or "Closed without a stated result." No other note on the item is sent.

A stage note goes out only while it's still true. An item the seat picked up before its queued note went out gets
the pickup note alone, and one that finished before its notes went out gets only its result.
3. Under a backlog, reporting keeps pace with intake. A pass reports up to twice as many items as it can take, results
first, then pickups, then queued notes, so finished work doesn't sit behind work still open and the hub doesn't show
it in progress. An item handed on here, once or along a chain of handoffs, whose last item is still open waits its
Expand Down
86 changes: 1 addition & 85 deletions packages/cli/test/fixtures/network-hub/inbound-loop.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
{
"pass": 2,
"does": "The local seat picked it up and closed it done: pickup note, a check that the hub item is still open, the close, and its readback."
"does": "The local seat picked it up and closed it done before this pass: a check that the hub item is still open, the close, and its readback. A pickup note would no longer be news, so none is sent."
},
{
"pass": 3,
Expand Down Expand Up @@ -964,90 +964,6 @@
}
}
},
{
"pass": 2,
"required": true,
"request": {
"method": "POST",
"path": "/mcp",
"headers": {
"authorization": "Bearer <TOKEN>"
},
"body": {
"method": "tools/call",
"params": {
"name": "rig_queue_update",
"arguments": {
"qitemId": "qitem-hub-1",
"note": "Picked up by the local seat at 2026-01-01T00:00:13.000Z."
}
},
"jsonrpc": "2.0",
"id": 4
}
},
"response": {
"status": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"jsonrpc": "2.0",
"id": 4,
"result": {
"content": [
{
"type": "text",
"text": "{\"pickup\":{\"state\":\"working\"},\"waiting\":{\"owner\":\"alex@team\",\"state\":\"in-progress\"},\"qitemId\":\"qitem-hub-1\",\"tsCreated\":\"2026-01-01T00:00:01.000Z\",\"tsUpdated\":\"2026-01-01T00:00:21.000Z\",\"sourceSession\":\"lead@team\",\"destinationSession\":\"alex@team\",\"state\":\"in-progress\",\"priority\":\"routine\",\"tier\":null,\"tags\":null,\"blockedOn\":null,\"handedOffTo\":null,\"handedOffFrom\":null,\"expiresAt\":null,\"chainOfRecord\":null,\"body\":\"Summarize the release notes. Reply with the word ok.\",\"summary\":\"Summarize the notes\",\"evidenceRef\":null,\"humanIntent\":null,\"humanDetail\":null,\"replyTo\":null,\"humanQuestions\":null,\"humanAnswers\":null,\"delegatedDecision\":null,\"closureReason\":null,\"closureTarget\":null,\"closureRequiredAt\":null,\"claimedAt\":\"2026-01-01T00:00:09.000Z\",\"lastNudgeAttempt\":null,\"lastNudgeResult\":null,\"lastNudgeWireResult\":null,\"lastHeartbeat\":null,\"resolution\":null,\"targetRepo\":null,\"deliveryOutcome\":null}"
}
],
"structuredContent": {
"pickup": {
"state": "working"
},
"waiting": {
"owner": "alex@team",
"state": "in-progress"
},
"qitemId": "qitem-hub-1",
"tsCreated": "2026-01-01T00:00:01.000Z",
"tsUpdated": "2026-01-01T00:00:21.000Z",
"sourceSession": "lead@team",
"destinationSession": "alex@team",
"state": "in-progress",
"priority": "routine",
"tier": null,
"tags": null,
"blockedOn": null,
"handedOffTo": null,
"handedOffFrom": null,
"expiresAt": null,
"chainOfRecord": null,
"body": "Summarize the release notes. Reply with the word ok.",
"summary": "Summarize the notes",
"evidenceRef": null,
"humanIntent": null,
"humanDetail": null,
"replyTo": null,
"humanQuestions": null,
"humanAnswers": null,
"delegatedDecision": null,
"closureReason": null,
"closureTarget": null,
"closureRequiredAt": null,
"claimedAt": "2026-01-01T00:00:09.000Z",
"lastNudgeAttempt": null,
"lastNudgeResult": null,
"lastNudgeWireResult": null,
"lastHeartbeat": null,
"resolution": null,
"targetRepo": null,
"deliveryOutcome": null
}
}
}
}
},
{
"pass": 2,
"required": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/test/network-connector-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ describe("the network connector against a recorded hub", () => {
await localRepo.update({ qitemId: local!.qitemId, actorSession: "dev-impl@lab", state: "done", closureReason: "no-follow-on", resolution: "ok" });
const second = await pass(2);
expect(second.error).toBeUndefined();
expect(second).toMatchObject({ taken: 0, pickupsSent: 1, resultsSent: 1 });
// It finished before this pass, so its result goes alone, with no late pickup note.
expect(second).toMatchObject({ taken: 0, pickupsSent: 0, resultsSent: 1 });
expect(receipt("qitem-hub-1")).toMatchObject({ outcome: "done" });
expect(receipt("qitem-hub-1")!.settled_at).not.toBeNull();
expect(bindings.get(binding.id)!.lastError).toBeNull();
Expand Down
16 changes: 12 additions & 4 deletions packages/daemon/src/domain/network/network-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function currentSession(db: Database.Database, nodeId: string): string | null {
return row?.session_name ?? null;
}

/** `queued_sent_at` and `pickup_sent_at` say a stage is reported, which isn't always that its note was sent: a stage the
* item had already passed when its turn came is marked with no note. */
interface Receipt {
local_qitem_id: string; binding_id: string; hub_qitem_id: string; queued_sent_at: string | null; pickup_sent_at: string | null;
settled_at: string | null; outcome: string | null;
Expand Down Expand Up @@ -418,16 +420,22 @@ async function reportBack(deps: NetworkConnectorDeps, binding: NetworkBinding, h
await unknown("This item's local record is gone, so whether it ran is unknown. It won't be run again.");
continue;
}
const end = local.state === "handed-off" ? finalItem(deps.queueRepo, local) : local;
// A stage note goes out only while it's still true: an item already picked up here gets no "Not picked up yet",
// and one that already ended goes straight to its result. Under a backlog those notes reached the hub minutes late,
// with the result, and were two of a result's five hub calls. A stage passed this way counts as reported.
const ended = !end || FINAL.has(end.state);
if (!receipt.queued_sent_at) {
await hub.note(receipt.hub_qitem_id, "Queued for the connected local seat. Not picked up yet.");
if (!local.claimedAt && !ended) await hub.note(receipt.hub_qitem_id, "Queued for the connected local seat. Not picked up yet.");
mark("queued_sent_at", receipt);
}
if (!receipt.pickup_sent_at && local.claimedAt) {
await hub.note(receipt.hub_qitem_id, `Picked up by the local seat at ${local.claimedAt}.`);
if (!ended) {
await hub.note(receipt.hub_qitem_id, `Picked up by the local seat at ${local.claimedAt}.`);
result.pickupsSent++;
}
mark("pickup_sent_at", receipt);
result.pickupsSent++;
}
const end = local.state === "handed-off" ? finalItem(deps.queueRepo, local) : local;
if (!end) {
await unknown("This item was handed on here without one successor, so its outcome is unknown. It won't be run again.");
continue;
Expand Down
33 changes: 31 additions & 2 deletions packages/daemon/test/network-connector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,12 @@ describe("network connector", () => {

const second = bind();
expect(second.id).not.toBe(first.id);
expect(await pass(second.id)).toMatchObject({ taken: 0, pickupsSent: 2, resultsSent: 1, unknown: 1 });
// r-picked's pickup goes out; r-done finished before the reconnect, so its result goes alone, with no late pickup note.
expect(await pass(second.id)).toMatchObject({ taken: 0, pickupsSent: 1, resultsSent: 1, unknown: 1 });
for (const id of ["r-queued", "r-picked", "r-done"]) expect(runs(id)).toHaveLength(1);
expect(runs("r-gone")).toHaveLength(0);
expect(hub.items.get("r-picked")!.notes.at(-1)).toMatch(/^Picked up by the local seat at /);
expect(hub.items.get("r-done")).toMatchObject({ state: "done", resolution: "Finished before the reconnect." });
expect(hub.items.get("r-done")).toMatchObject({ state: "done", resolution: "Finished before the reconnect.", notes: ["Queued for the connected local seat. Not picked up yet."] });
expect(hub.items.get("r-gone")!.notes.at(-1)).toBe("This item's local record is gone, so whether it ran is unknown. It won't be run again.");
expect(db.prepare("SELECT DISTINCT binding_id FROM network_receipts").all()).toEqual([{ binding_id: second.id }]);
await pass(second.id);
Expand Down Expand Up @@ -747,6 +748,34 @@ describe("network connector", () => {
expect(hubStates()).toEqual({ done: 30 });
});

it("an item that finished here before its stage notes went out gets its result alone, with no late queued or pickup note", async () => {
const b = bind();
hub.add("hub-late");
// Taken with no turn to report, so its queued note hasn't gone out.
await runNetworkBindingPass({ ...deps, reportLimit: 0 }, bindings.get(b.id)!);
expect(hub.items.get("hub-late")!.notes).toEqual([]);
const local = runs("hub-late")[0]!;
repo.claim({ qitemId: local.qitemId, destinationSession: "dev-impl@lab" });
await repo.update({ qitemId: local.qitemId, actorSession: "dev-impl@lab", state: "done", closureReason: "no-follow-on", resolution: "Finished before any note." });
expect(await pass(b.id)).toMatchObject({ resultsSent: 1, pickupsSent: 0 });
expect(hub.items.get("hub-late")).toMatchObject({ state: "done", resolution: "Finished before any note.", notes: [] });
// Its stages count as reported: a later pass sends nothing more.
await pass(b.id);
expect(hub.items.get("hub-late")!.notes).toEqual([]);
expect(hub.closes).toBe(1);
});

it("an item picked up here before its queued note went out gets the pickup note, never \"Not picked up yet\"", async () => {
const b = bind();
hub.add("hub-picked");
await runNetworkBindingPass({ ...deps, reportLimit: 0 }, bindings.get(b.id)!);
repo.claim({ qitemId: runs("hub-picked")[0]!.qitemId, destinationSession: "dev-impl@lab" });
expect(await pass(b.id)).toMatchObject({ pickupsSent: 1 });
expect(hub.items.get("hub-picked")!.notes).toEqual([expect.stringMatching(/^Picked up by the local seat at /)]);
await pass(b.id);
expect(hub.items.get("hub-picked")!.notes).toHaveLength(1);
});

it("a long intake leaves reporting its window: what finished here reaches the hub in the same pass", async () => {
const b = bind();
for (let i = 0; i < 20; i++) hub.add(`hub-w${i}`);
Expand Down