@cydm/pie 4.3.12 → 4.4.0
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.
|
@@ -80,6 +80,18 @@ lark-cli daemon automatically; the warning gives the operator the explicit
|
|
|
80
80
|
`event stop --force` recovery command. Optional card/menu consumers respawn
|
|
81
81
|
on bounded backoff, reset only at their ready marker; dead children are removed.
|
|
82
82
|
|
|
83
|
+
On a machine where a resident holds the consumer slot, non-holder runtimes
|
|
84
|
+
operate in dispatch mode: they never spawn a consumer and receive events over
|
|
85
|
+
pie-ipc. For such runtimes the tag answers a delivery question, not a
|
|
86
|
+
lifecycle one: `[IM]` while dispatch mode is the working configuration (the
|
|
87
|
+
holder is alive and sorting), `[IM-DEGRADED:dispatch]` when the holder
|
|
88
|
+
heartbeat stays fresh yet nothing has been dispatched here past a ten-minute
|
|
89
|
+
grace window, and `[IM…]` only while the runtime is genuinely starting or
|
|
90
|
+
waiting to claim. A dispatched event restores `[IM]` immediately. Losing the
|
|
91
|
+
holder (restart churn) never shows degraded — no delivery evidence plus no
|
|
92
|
+
holder is not a failure signal. `/tools/im-forward status` prints the holder
|
|
93
|
+
identity and the last dispatched event time in dispatch mode.
|
|
94
|
+
|
|
83
95
|
Registered panel cards can bypass metadata/claim/scope IO only AFTER all
|
|
84
96
|
conversation/sender policies pass. Card ownership is session-and-epoch bound;
|
|
85
97
|
pending send/patch completions never reassign the card after a session switch.
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
composeForwardBody,
|
|
12
12
|
configSnapshot,
|
|
13
13
|
configurationIdentity,
|
|
14
|
+
currentConsumer,
|
|
14
15
|
estimatePostRequestBytes,
|
|
15
16
|
failureReason,
|
|
16
17
|
hasConfigLayers,
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
truncateMarkdown,
|
|
31
32
|
tryClaimConsumer,
|
|
32
33
|
writeConfig
|
|
33
|
-
} from "../../../chunks/chunk-
|
|
34
|
+
} from "../../../chunks/chunk-AKXEZH7K.js";
|
|
34
35
|
import {
|
|
35
36
|
detectImageMime,
|
|
36
37
|
readImageFormat
|
|
@@ -825,12 +826,39 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
|
|
|
825
826
|
return forwardingEnabled;
|
|
826
827
|
}
|
|
827
828
|
const STATUS_KEY = "im-forward";
|
|
829
|
+
let dispatchMode = false;
|
|
830
|
+
let lastDispatchReceivedAt;
|
|
831
|
+
const holderAlive = () => {
|
|
832
|
+
if (consumerLock) return true;
|
|
833
|
+
try {
|
|
834
|
+
return currentConsumer(bindingKey()).alive;
|
|
835
|
+
} catch {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
};
|
|
828
839
|
function updateFooterTag() {
|
|
829
840
|
ctx.ui.setStatus?.(
|
|
830
841
|
STATUS_KEY,
|
|
831
|
-
configurationFailed ? "[IM!]" : forwardingEnabled ? consumerLastExit ? "[IM!]" : busStale ? "[IM-DEGRADED:bus]" : consumerReady ? "[IM]" : "[IM\u2026]" : void 0
|
|
842
|
+
configurationFailed ? "[IM!]" : forwardingEnabled ? consumerLastExit ? "[IM!]" : busStale ? "[IM-DEGRADED:bus]" : consumerReady ? "[IM]" : dispatchMode ? dispatchStale() ? "[IM-DEGRADED:dispatch]" : "[IM]" : "[IM\u2026]" : void 0
|
|
832
843
|
);
|
|
833
844
|
}
|
|
845
|
+
const DISPATCH_GRACE_MS = 10 * 6e4;
|
|
846
|
+
let dispatchStaleWarned = false;
|
|
847
|
+
let dispatchModeEnteredAt;
|
|
848
|
+
const dispatchStale = () => {
|
|
849
|
+
if (!dispatchMode) return false;
|
|
850
|
+
const anchor = Math.max(lastDispatchReceivedAt ?? 0, dispatchModeEnteredAt ?? 0);
|
|
851
|
+
if (anchor && Date.now() - anchor < DISPATCH_GRACE_MS) return false;
|
|
852
|
+
return holderAlive();
|
|
853
|
+
};
|
|
854
|
+
const noteDispatchReceived = () => {
|
|
855
|
+
lastDispatchReceivedAt = Date.now();
|
|
856
|
+
if (dispatchStaleWarned) {
|
|
857
|
+
dispatchStaleWarned = false;
|
|
858
|
+
ctx.log("im-forward: dispatched events flowing again");
|
|
859
|
+
}
|
|
860
|
+
updateFooterTag();
|
|
861
|
+
};
|
|
834
862
|
let busStale = false;
|
|
835
863
|
const probeBusHealth = async () => {
|
|
836
864
|
if (terminated || !connection.consumeBusHealth) return;
|
|
@@ -848,6 +876,14 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
|
|
|
848
876
|
}
|
|
849
877
|
} catch {
|
|
850
878
|
}
|
|
879
|
+
if (dispatchMode) {
|
|
880
|
+
const stale = dispatchStale();
|
|
881
|
+
if (stale && !dispatchStaleWarned) {
|
|
882
|
+
dispatchStaleWarned = true;
|
|
883
|
+
ctx.log("im-forward: consumer holder alive but no dispatched events received past grace window");
|
|
884
|
+
}
|
|
885
|
+
updateFooterTag();
|
|
886
|
+
}
|
|
851
887
|
};
|
|
852
888
|
function writeEnabledToConfig(next) {
|
|
853
889
|
persistEnabled(next);
|
|
@@ -1533,6 +1569,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1533
1569
|
try {
|
|
1534
1570
|
const parsed = JSON.parse(trimmed.slice(DISPATCH_PREFIX.length).trim());
|
|
1535
1571
|
if (!parsed.event) return false;
|
|
1572
|
+
if (dispatchMode) noteDispatchReceived();
|
|
1536
1573
|
void handleInboundEvent(parsed.event);
|
|
1537
1574
|
return true;
|
|
1538
1575
|
} catch {
|
|
@@ -2106,7 +2143,12 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2106
2143
|
function acquireClaimedSlot(binding) {
|
|
2107
2144
|
if (consumerLock) return true;
|
|
2108
2145
|
if (!isManager && residentAliveSomewhere()) {
|
|
2109
|
-
|
|
2146
|
+
if (!dispatchMode) {
|
|
2147
|
+
dispatchMode = true;
|
|
2148
|
+
dispatchModeEnteredAt = Date.now();
|
|
2149
|
+
ctx.log("im-forward: a live resident owns the feed class; standing down (dispatch mode)");
|
|
2150
|
+
updateFooterTag();
|
|
2151
|
+
}
|
|
2110
2152
|
return false;
|
|
2111
2153
|
}
|
|
2112
2154
|
const claim = tryClaimConsumer(
|
|
@@ -2132,9 +2174,20 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2132
2174
|
isManager ? void 0 : () => residentAliveSomewhere()
|
|
2133
2175
|
);
|
|
2134
2176
|
if (!claim) {
|
|
2135
|
-
|
|
2177
|
+
if (!dispatchMode) {
|
|
2178
|
+
dispatchMode = true;
|
|
2179
|
+
dispatchModeEnteredAt = Date.now();
|
|
2180
|
+
ctx.log("im-forward: another consumer owns the event-hub slot; dispatch mode");
|
|
2181
|
+
updateFooterTag();
|
|
2182
|
+
}
|
|
2136
2183
|
return false;
|
|
2137
2184
|
}
|
|
2185
|
+
if (dispatchMode) {
|
|
2186
|
+
dispatchMode = false;
|
|
2187
|
+
dispatchModeEnteredAt = void 0;
|
|
2188
|
+
ctx.log("im-forward: consumer slot acquired; leaving dispatch mode");
|
|
2189
|
+
updateFooterTag();
|
|
2190
|
+
}
|
|
2138
2191
|
consumerLock = claim;
|
|
2139
2192
|
return true;
|
|
2140
2193
|
}
|
|
@@ -2294,10 +2347,15 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2294
2347
|
}, 5 * 60 * 1e3);
|
|
2295
2348
|
busHealthTimer.unref?.();
|
|
2296
2349
|
void probeBusHealth();
|
|
2350
|
+
const dispatchTagTimer = setInterval(() => {
|
|
2351
|
+
if (dispatchMode) updateFooterTag();
|
|
2352
|
+
}, 3e4);
|
|
2353
|
+
dispatchTagTimer.unref?.();
|
|
2297
2354
|
ctx.registerCleanup?.(async () => {
|
|
2298
2355
|
inputEpoch++;
|
|
2299
2356
|
terminated = true;
|
|
2300
2357
|
clearInterval(busHealthTimer);
|
|
2358
|
+
clearInterval(dispatchTagTimer);
|
|
2301
2359
|
registerDispatchReceiver(void 0);
|
|
2302
2360
|
registerTurnImDriver(void 0);
|
|
2303
2361
|
consumerLock?.release();
|
|
@@ -2333,6 +2391,17 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2333
2391
|
...cfg.appId ? [`- app: ${cfg.appId}`] : [],
|
|
2334
2392
|
`- allowed senders: ${cfg.allowUsers?.join(", ") ?? "(anyone in target)"}`,
|
|
2335
2393
|
`- consumer: ${terminated ? "stopped" : consumer ? consumerReady ? "ready" : "starting" : "idle (waits for first session)"}${consumerLastExit ? ` (last exit: ${consumerLastExit})` : ""}, restarts=${consumerRestarts}`,
|
|
2394
|
+
...dispatchMode ? [
|
|
2395
|
+
`- dispatch mode: resident holds the feed (holder ${(() => {
|
|
2396
|
+
try {
|
|
2397
|
+
const c = currentConsumer(bindingKey());
|
|
2398
|
+
return c.info ? `${c.info.holder} pid=${c.info.pid} ${c.alive ? "alive" : "STALE"}` : "(no lock file)";
|
|
2399
|
+
} catch {
|
|
2400
|
+
return "(unreadable)";
|
|
2401
|
+
}
|
|
2402
|
+
})()}); this runtime receives events over pie-ipc`,
|
|
2403
|
+
`- last dispatched event: ${lastDispatchReceivedAt ? new Date(lastDispatchReceivedAt).toISOString() : "(none since start)"}${dispatchStale() ? " \u2014 STALE past grace window" : ""}`
|
|
2404
|
+
] : [],
|
|
2336
2405
|
`- routes: ${routes.size} forwarded message(s) routable (${threadRoutes.size} thread(s), ${replyAnchor.size} anchor(s))`,
|
|
2337
2406
|
`- current session: ${currentSessionId ?? "(none)"}`
|
|
2338
2407
|
];
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
takeDispatchFrame,
|
|
27
27
|
wrapInboundText,
|
|
28
28
|
wrappedMessageMarker
|
|
29
|
-
} from "../../../chunks/chunk-
|
|
29
|
+
} from "../../../chunks/chunk-AKXEZH7K.js";
|
|
30
30
|
import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
31
31
|
|
|
32
32
|
// builtin/extensions/pie-ipc/index.ts
|
|
@@ -1894,7 +1894,9 @@ function pieIpcExtension(ctx) {
|
|
|
1894
1894
|
ctx.registerTool({
|
|
1895
1895
|
name: "ipc_send_notify",
|
|
1896
1896
|
label: "Send a message to a Pie peer and get notified when it finishes",
|
|
1897
|
-
description: `Send text to another Pie process (interactive peer) and SUBSCRIBE to its completion \u2014 the name is the contract: fire-and-forget sending requires an explicit notify:false. Default behavior: returns right after the receipt ack with a requestId; when the peer's turn settles (success, failure, or cancellation) it pushes one [ipc-done] notification as inbound input, and a local fallback timer (fallbackMs, default 600000ms) wakes a result check if that push is lost \u2014 you will be called back, do not poll in a loop and never resend while a result is pending. wait=true: hold the tool call open instead (bounded by waitMs) \u2014 one-shot hosts only. notify:false: explicit fire-and-forget (return after socket submission; receipt/consumption not confirmed; no wake). Inbound messages from peers arrive as user input or in ipc_poll
|
|
1897
|
+
description: `Send text to another Pie process (interactive peer) and SUBSCRIBE to its completion \u2014 the name is the contract: fire-and-forget sending requires an explicit notify:false. Default behavior: returns right after the receipt ack with a requestId; when the peer's turn settles (success, failure, or cancellation) it pushes one [ipc-done] notification as inbound input, and a local fallback timer (fallbackMs, default 600000ms) wakes a result check if that push is lost \u2014 you will be called back, do not poll in a loop and never resend while a result is pending. wait=true: hold the tool call open instead (bounded by waitMs) \u2014 one-shot hosts only. notify:false: explicit fire-and-forget (return after socket submission; receipt/consumption not confirmed; no wake). Inbound messages from peers arrive as user input or in ipc_poll.
|
|
1898
|
+
|
|
1899
|
+
SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's conversation as a user input and triggers one full model turn on the peer (cost + side effects there). If the user only asked you to observe (\u770B\u770B/\u67E5\u67E5/\u4E86\u89E3\u4E00\u4E0B a peer), do NOT use this tool: read ipc_list_peers/ipc_status or the peer's session files instead. Use this tool to dispatch work or ask a peer only when the user explicitly authorized contacting that peer.`,
|
|
1898
1900
|
parameters: Type.Object({
|
|
1899
1901
|
to: Type.String({ description: "Peer display name or instance id (see ipc_list_peers)" }),
|
|
1900
1902
|
text: Type.String({ description: "Message body for the peer" }),
|
|
@@ -1381,6 +1381,10 @@ function tryClaimConsumer(binding, holder, onLost, shouldYield) {
|
|
|
1381
1381
|
}
|
|
1382
1382
|
};
|
|
1383
1383
|
}
|
|
1384
|
+
function currentConsumer(binding) {
|
|
1385
|
+
const info = readLock(binding);
|
|
1386
|
+
return { info, alive: lockAlive(info) };
|
|
1387
|
+
}
|
|
1384
1388
|
|
|
1385
1389
|
export {
|
|
1386
1390
|
isRecord,
|
|
@@ -1433,5 +1437,6 @@ export {
|
|
|
1433
1437
|
isTurnUserImDriven,
|
|
1434
1438
|
registerDispatchReceiver,
|
|
1435
1439
|
takeDispatchFrame,
|
|
1436
|
-
tryClaimConsumer
|
|
1440
|
+
tryClaimConsumer,
|
|
1441
|
+
currentConsumer
|
|
1437
1442
|
};
|