arco-workbench 0.1.6 → 0.1.7
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 +6 -1
- package/client/dist/assets/{PhosphorBackdrop-BR-TgB5x.js → PhosphorBackdrop-DVQdBrTw.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DgcFj6JN.js → ThemedBackgroundShaderImpl-BfSs2tB4.js} +1 -1
- package/client/dist/assets/{XtermView-CflVBQgC.js → XtermView-DaMjC8Ny.js} +1 -1
- package/client/dist/assets/{galleryEditor-BB-emfmi.js → galleryEditor-BCQnXj7R.js} +1 -1
- package/client/dist/assets/{index-B_EqHDz3.js → index-COfbHCYv.js} +218 -218
- package/client/dist/index.html +1 -1
- package/client/src/buildCheck.ts +3 -1
- package/client/src/components/AppUpdateNotice.tsx +2 -1
- package/client/src/components/ClusterRightPanel/AutoPickupControl.tsx +24 -12
- package/client/src/components/ClusterRightPanel/index.tsx +2 -1
- package/client/src/components/HeaderVersionBox.tsx +7 -4
- package/client/src/components/UpdateAction.tsx +18 -4
- package/client/src/components/UpdateResultNotice.tsx +3 -1
- package/client/src/help/content/cluster.tsx +16 -5
- package/client/src/help/content/header.tsx +3 -1
- package/client/src/help/content/rightPanel.tsx +1 -1
- package/client/src/help/content/settings.tsx +1 -1
- package/client/src/help/manualSections/clusters.tsx +17 -1
- package/client/src/help/manualSections/configuration.tsx +20 -4
- package/client/src/help/manualSections/maintenance.tsx +12 -0
- package/client/src/help/manualSections/plans.tsx +5 -1
- package/client/src/help/manualSections/workflows.tsx +7 -0
- package/client/src/stores/appUpdateStore.ts +29 -8
- package/client/src/utils/wsSession.ts +2 -1
- package/docs/GETTING_STARTED.md +5 -1
- package/docs/OPERATIONS.md +23 -0
- package/docs/PERSISTENCE.md +18 -1
- package/docs/PROTOCOL_CLUSTER.md +9 -2
- package/native/darwin-arm64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/protocol/autoPickup.d.ts +3 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/scripts/packaging/native-repair.mjs +46 -8
- package/scripts/packaging/update.mjs +5 -1
- package/server/dist/clusterAutoTurn.d.ts +4 -0
- package/server/dist/clusterAutoTurn.js +29 -25
- package/server/dist/clusterBusyReminder.js +1 -1
- package/server/dist/clusterStore.d.ts +3 -0
- package/server/dist/clusterStore.js +22 -0
- package/server/dist/smartPickup.d.ts +2 -1
- package/server/dist/smartPickup.js +28 -1
- package/server/dist/smartPickupLedger.js +6 -4
- package/server/dist/smartPickupObserver.d.ts +1 -0
- package/server/dist/smartPickupObserver.js +24 -15
- package/server/dist/ws/clusterHandlers.d.ts +1 -0
- package/server/dist/ws/clusterHandlers.js +2 -1
- package/server/package.json +1 -1
- package/server/src/clusterAutoTurn.ts +26 -21
- package/server/src/clusterBusyReminder.ts +1 -1
- package/server/src/clusterStore.ts +26 -1
- package/server/src/smartPickup.ts +27 -3
- package/server/src/smartPickupLedger.ts +6 -4
- package/server/src/smartPickupObserver.ts +20 -11
- package/server/src/ws/clusterHandlers.ts +3 -2
- package/shared/dist/protocol/autoPickup.d.ts +3 -0
- package/shared/src/protocol/autoPickup.ts +5 -0
|
@@ -68,6 +68,7 @@ export declare function handleClusterAutoTurnToggle(ws: WebSocket, clusterId: st
|
|
|
68
68
|
export declare function handleClusterAutoPickupSet(ws: WebSocket, msg: {
|
|
69
69
|
clusterId: string;
|
|
70
70
|
mode: unknown;
|
|
71
|
+
paused?: unknown;
|
|
71
72
|
evaluator?: unknown;
|
|
72
73
|
limits?: unknown;
|
|
73
74
|
ruleLimits?: unknown;
|
|
@@ -2389,9 +2389,10 @@ export async function handleClusterAutoTurnToggle(ws, clusterId, enabled) {
|
|
|
2389
2389
|
// Operator chose an AUTO-PICKUP mode in the cluster dialog. Smart modes need
|
|
2390
2390
|
// an evaluator from an enabled provider and start a new session; Off and
|
|
2391
2391
|
// Rule-based end any Smart session. Pushes cluster_state on success.
|
|
2392
|
+
// A pause-only request keeps the current mode, session and budgets.
|
|
2392
2393
|
export async function handleClusterAutoPickupSet(ws, msg) {
|
|
2393
2394
|
const settings = await readSettings().catch(() => null);
|
|
2394
|
-
const result = await applyAutoPickup(msg.clusterId, { mode: msg.mode, evaluator: msg.evaluator, limits: msg.limits, ruleLimits: msg.ruleLimits, resumeRule: msg.resumeRule }, (provider) => settings?.enabledProviders?.[provider] !== false);
|
|
2395
|
+
const result = await applyAutoPickup(msg.clusterId, { mode: msg.mode, paused: msg.paused, evaluator: msg.evaluator, limits: msg.limits, ruleLimits: msg.ruleLimits, resumeRule: msg.resumeRule }, (provider) => settings?.enabledProviders?.[provider] !== false);
|
|
2395
2396
|
if (!result.ok) {
|
|
2396
2397
|
send(ws, { type: 'error', message: `cluster_auto_pickup_set rejected: ${result.problem}` });
|
|
2397
2398
|
return;
|
package/server/package.json
CHANGED
|
@@ -197,24 +197,28 @@ async function sweep(): Promise<void> {
|
|
|
197
197
|
const membersByCluster = resolveMembersFn();
|
|
198
198
|
if (!membersByCluster) return;
|
|
199
199
|
for (const clusterId of clusterStore.listKnownClusterIds()) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
clusterId,
|
|
213
|
-
senderWfid: pending[0].fromWorkflowId,
|
|
214
|
-
recipientWfid: m.workflowId,
|
|
215
|
-
incomingChainDepth: heldMailDepth(m.workflowId, pending),
|
|
216
|
-
});
|
|
200
|
+
await pickupWaitingMail(clusterId, membersByCluster.get(clusterId));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Resume uses the same scan as the periodic sweep, including every normal
|
|
205
|
+
// guard and budget. Never reset the Rule-based ledger to resume an operator pause.
|
|
206
|
+
export async function pickupWaitingMail(clusterId: string, liveMembers = resolveMembersFn?.()?.get(clusterId)): Promise<void> {
|
|
207
|
+
if (!isBusyFn || !clusterStore.isAutoPickupWaking(clusterId) || clusterStore.isAutoPickupPaused(clusterId) || !liveMembers) return;
|
|
208
|
+
for (const m of liveMembers) {
|
|
209
|
+
if (m.busy) {
|
|
210
|
+
if (dispatchBusyReminderFn) await remindBusyMember(clusterId,m.workflowId,{isBusy:isBusyFn,hasClusterTools:hasClusterToolsFn,dispatch:dispatchBusyReminderFn});
|
|
211
|
+
continue;
|
|
217
212
|
}
|
|
213
|
+
if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId)) continue;
|
|
214
|
+
const pending = await clusterMailbox.peek(m.workflowId).catch(() => []);
|
|
215
|
+
if (pending.length === 0) continue;
|
|
216
|
+
onPeerMessageSent({
|
|
217
|
+
clusterId,
|
|
218
|
+
senderWfid: pending[0].fromWorkflowId,
|
|
219
|
+
recipientWfid: m.workflowId,
|
|
220
|
+
incomingChainDepth: heldMailDepth(m.workflowId, pending),
|
|
221
|
+
});
|
|
218
222
|
}
|
|
219
223
|
}
|
|
220
224
|
|
|
@@ -346,6 +350,7 @@ export function onPeerMessageSent(opts: {
|
|
|
346
350
|
if (isBusyFn && dispatchBusyReminderFn) void remindBusyMember(opts.clusterId,opts.recipientWfid,{isBusy:isBusyFn,hasClusterTools:hasClusterToolsFn,dispatch:dispatchBusyReminderFn});
|
|
347
351
|
if (!clusterStore.isAutoTurnOnMailboxEnabled(opts.clusterId)) return;
|
|
348
352
|
if (opts.incomingChainDepth > pendingChainDepth(opts.recipientWfid)) pendingDepth.set(opts.recipientWfid, opts.incomingChainDepth);
|
|
353
|
+
if (clusterStore.isAutoPickupPaused(opts.clusterId)) return;
|
|
349
354
|
try { ruleGuard.mail(opts.clusterId, opts.senderWfid, opts.recipientWfid); } catch (error) { console.error('[arco] Rule-based pickup ledger unavailable:', error); return; }
|
|
350
355
|
const key = `${opts.clusterId}:${opts.recipientWfid}`;
|
|
351
356
|
if (pendingChecks.has(key)) return;
|
|
@@ -369,7 +374,7 @@ function fireRulePickup(opts: { clusterId: string; senderWfid: string; recipient
|
|
|
369
374
|
|
|
370
375
|
// Guard 0: cluster toggle armed. Most clusters won't have this on; the
|
|
371
376
|
// gate is the first check so the hot path is one map lookup when off.
|
|
372
|
-
if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId)) return;
|
|
377
|
+
if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId) || clusterStore.isAutoPickupPaused(clusterId)) return;
|
|
373
378
|
|
|
374
379
|
// Guard 1: depth cap. An incoming chainDepth of (cap - 1) is the last one
|
|
375
380
|
// we'll auto-turn on; the auto-turn it produces will land at cap, so the
|
|
@@ -406,12 +411,12 @@ function fireRulePickup(opts: { clusterId: string; senderWfid: string; recipient
|
|
|
406
411
|
const wasBudgetPaused = ruleGuard.snapshot(clusterId).budgetPaused;
|
|
407
412
|
const problem = ruleGuard.admit(clusterId, senderWfid, recipientWfid, limits, now);
|
|
408
413
|
if (problem) {
|
|
409
|
-
const notice = problem === 'budget_paused' && !wasBudgetPaused ? 'Wake budget reached.
|
|
414
|
+
const notice = problem === 'budget_paused' && !wasBudgetPaused ? 'Wake budget reached. Select RESET BUDGET beside AUTO-PICKUP.' : undefined;
|
|
410
415
|
emitSkip(clusterId, recipientWfid, senderWfid, incomingChainDepth, problem, now, notice); return;
|
|
411
416
|
}
|
|
412
417
|
const pauses = ruleGuard.stamp(clusterId, senderWfid, recipientWfid, limits, now);
|
|
413
418
|
const notices = [
|
|
414
|
-
...(pauses.budgetPaused ? ['Wake budget reached.
|
|
419
|
+
...(pauses.budgetPaused ? ['Wake budget reached. Select RESET BUDGET beside AUTO-PICKUP.'] : []),
|
|
415
420
|
...(pauses.pairPaused ? [`Alternating wakes paused between ${clusterStore.displayNameFor(senderWfid)} and ${clusterStore.displayNameFor(recipientWfid)}.`] : []),
|
|
416
421
|
];
|
|
417
422
|
|
|
@@ -453,7 +458,7 @@ function fireRulePickup(opts: { clusterId: string; senderWfid: string; recipient
|
|
|
453
458
|
const dispatch = dispatchAutoTurnFn;
|
|
454
459
|
setImmediate(() => {
|
|
455
460
|
try {
|
|
456
|
-
if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId) || isBusyFn?.(recipientWfid)) return;
|
|
461
|
+
if (!clusterStore.isAutoTurnOnMailboxEnabled(clusterId) || clusterStore.isAutoPickupPaused(clusterId) || isBusyFn?.(recipientWfid)) return;
|
|
457
462
|
dispatch(recipientWfid, prompt);
|
|
458
463
|
} catch (err) {
|
|
459
464
|
// Dispatch failure leaves the cooldown + rate-cap entries in place
|
|
@@ -14,7 +14,7 @@ export interface BusyReminderDeps {
|
|
|
14
14
|
}
|
|
15
15
|
function enabled(clusterId: string, workflowId: string, now: number): boolean {
|
|
16
16
|
const state = store.getClusterCached(clusterId);
|
|
17
|
-
if (state?.remindBusy !== true || !state.members.includes(workflowId)) return false;
|
|
17
|
+
if (state?.remindBusy !== true || state.autoPickupPausedAt !== undefined || !state.members.includes(workflowId)) return false;
|
|
18
18
|
const mode = store.autoPickupModeOf(state);
|
|
19
19
|
return mode === 'rule' || (mode === 'smart-auto' && (state.smartPickup?.session?.expiresAt ?? 0) > now);
|
|
20
20
|
}
|
|
@@ -112,6 +112,9 @@ export interface ClusterState {
|
|
|
112
112
|
// Rule-based), so clusters saved before the modes existed keep their
|
|
113
113
|
// behavior. autoTurnOnMailboxEnabled is kept equal to "mode is rule".
|
|
114
114
|
autoPickupMode?: AutoPickupMode;
|
|
115
|
+
// Operator pause timestamp, independent of the Rule-based wake-budget stop.
|
|
116
|
+
// The timestamp freezes Smart's remaining session time across restart.
|
|
117
|
+
autoPickupPausedAt?: number;
|
|
115
118
|
remindBusy?: boolean;
|
|
116
119
|
rulePickupLimits?: Partial<RulePickupLimits>;
|
|
117
120
|
// Smart pickup choices kept across disarm: the active evaluator, the last
|
|
@@ -1001,13 +1004,28 @@ export async function setAutoTurnOnMailbox(
|
|
|
1001
1004
|
// its own id and expiry; any other mode clears the session, which makes any
|
|
1002
1005
|
// outstanding Smart work stale. The evaluator, last explicit choice and
|
|
1003
1006
|
// limits persist across disarm so re-arming can offer them again.
|
|
1007
|
+
// Pause-only updates preserve session identity and remaining running time;
|
|
1008
|
+
// resume moves its expiry forward by the saved pause duration.
|
|
1004
1009
|
export async function setAutoPickup(
|
|
1005
1010
|
clusterId: string,
|
|
1006
|
-
opts: { mode: AutoPickupMode; evaluator?: SmartPickupEvaluator; limits?: Partial<SmartPickupLimits>; ruleLimits?: Partial<RulePickupLimits>; remindBusy?: boolean; now?: number },
|
|
1011
|
+
opts: { mode: AutoPickupMode; paused?: boolean; evaluator?: SmartPickupEvaluator; limits?: Partial<SmartPickupLimits>; ruleLimits?: Partial<RulePickupLimits>; remindBusy?: boolean; now?: number },
|
|
1007
1012
|
): Promise<ClusterState | null> {
|
|
1008
1013
|
return withClusterMetaLock(clusterId, async () => {
|
|
1009
1014
|
const state = await readCluster(clusterId);
|
|
1010
1015
|
if (!state) return null;
|
|
1016
|
+
if (typeof opts.paused === 'boolean') {
|
|
1017
|
+
if (opts.mode === 'off' || opts.mode !== autoPickupModeOf(state)) return null;
|
|
1018
|
+
const now = opts.now ?? Date.now();
|
|
1019
|
+
const pausedAt = state.autoPickupPausedAt;
|
|
1020
|
+
const session = state.smartPickup?.session;
|
|
1021
|
+
const smartPickup = !opts.paused && pausedAt !== undefined && session && isSmartPickupMode(opts.mode)
|
|
1022
|
+
? { ...state.smartPickup, session: { ...session, expiresAt: session.expiresAt + Math.max(0, now - pausedAt) } }
|
|
1023
|
+
: state.smartPickup;
|
|
1024
|
+
const next = { ...state, autoPickupPausedAt: opts.paused ? pausedAt ?? now : undefined, smartPickup };
|
|
1025
|
+
await writeMetaAtomic(next);
|
|
1026
|
+
rebuildIndexFor(next);
|
|
1027
|
+
return next;
|
|
1028
|
+
}
|
|
1011
1029
|
const now = opts.now ?? Date.now();
|
|
1012
1030
|
const prior = state.smartPickup ?? {};
|
|
1013
1031
|
const limits = opts.limits ? sanitizeSmartPickupLimits({ ...sanitizeSmartPickupLimits(prior.limits), ...opts.limits }) : prior.limits;
|
|
@@ -1033,6 +1051,9 @@ export async function setAutoPickup(
|
|
|
1033
1051
|
rulePickupLimits: opts.ruleLimits ? sanitizeRulePickupLimits({ ...sanitizeRulePickupLimits(state.rulePickupLimits), ...opts.ruleLimits }) : state.rulePickupLimits,
|
|
1034
1052
|
remindBusy: typeof opts.remindBusy === 'boolean' ? opts.remindBusy : state.remindBusy,
|
|
1035
1053
|
autoPickupMode: opts.mode === 'off' ? undefined : opts.mode,
|
|
1054
|
+
autoPickupPausedAt: opts.mode !== 'off' && opts.mode === autoPickupModeOf(state) && state.autoPickupPausedAt !== undefined
|
|
1055
|
+
? isSmartPickupMode(opts.mode) ? now : state.autoPickupPausedAt
|
|
1056
|
+
: undefined,
|
|
1036
1057
|
autoTurnOnMailboxEnabled: opts.mode === 'rule' ? true : undefined,
|
|
1037
1058
|
smartPickup: hasSmart ? smartPickup : undefined,
|
|
1038
1059
|
};
|
|
@@ -1047,6 +1068,10 @@ export function getAutoPickupMode(clusterId: string): AutoPickupMode {
|
|
|
1047
1068
|
return resolveAutoPickupMode(state?.autoPickupMode, state?.autoTurnOnMailboxEnabled);
|
|
1048
1069
|
}
|
|
1049
1070
|
|
|
1071
|
+
export function isAutoPickupPaused(clusterId: string): boolean {
|
|
1072
|
+
return cache.get(clusterId)?.autoPickupPausedAt !== undefined;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1050
1075
|
export function autoPickupModeOf(state: Pick<ClusterState, 'autoPickupMode' | 'autoTurnOnMailboxEnabled'>): AutoPickupMode {
|
|
1051
1076
|
return resolveAutoPickupMode(state.autoPickupMode, state.autoTurnOnMailboxEnabled);
|
|
1052
1077
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from '@arco/shared';
|
|
15
15
|
import * as ruleAutoTurn from './clusterAutoTurn.js';
|
|
16
16
|
import * as clusterStore from './clusterStore.js';
|
|
17
|
+
import { pickupSmartWaitingMail } from './smartPickupObserver.js';
|
|
17
18
|
import { evaluatorAdapter } from './smartPickupAdapters.js';
|
|
18
19
|
import {
|
|
19
20
|
recordSmartPickupDecision,
|
|
@@ -31,14 +32,14 @@ export const SMART_PICKUP_SWEEP_MS = (() => {
|
|
|
31
32
|
return Number.isInteger(raw) && raw >= 50 ? raw : 15_000;
|
|
32
33
|
})();
|
|
33
34
|
|
|
34
|
-
export type ArmProblem = 'unknown_cluster' | 'invalid_mode' | 'evaluator_required' | 'evaluator_provider_disabled' | 'evaluator_unavailable' | 'ledger_unreadable';
|
|
35
|
+
export type ArmProblem = 'unknown_cluster' | 'invalid_mode' | 'invalid_pause' | 'evaluator_required' | 'evaluator_provider_disabled' | 'evaluator_unavailable' | 'ledger_unreadable';
|
|
35
36
|
|
|
36
37
|
// Validate and apply an operator's AUTO-PICKUP choice. A Smart mode needs an
|
|
37
38
|
// evaluator whose provider is enabled and a readable budget ledger; arming
|
|
38
39
|
// always starts a fresh session. Every change is logged in the ledger.
|
|
39
40
|
export async function applyAutoPickup(
|
|
40
41
|
clusterId: string,
|
|
41
|
-
request: { mode: unknown; evaluator?: unknown; limits?: unknown; ruleLimits?: unknown; resumeRule?: boolean; remindBusy?: boolean },
|
|
42
|
+
request: { mode: unknown; paused?: unknown; evaluator?: unknown; limits?: unknown; ruleLimits?: unknown; resumeRule?: boolean; remindBusy?: boolean },
|
|
42
43
|
isProviderEnabled: (provider: SmartPickupEvaluator['provider']) => boolean,
|
|
43
44
|
now = Date.now(),
|
|
44
45
|
): Promise<{ ok: true; mode: AutoPickupMode } | { ok: false; problem: ArmProblem }> {
|
|
@@ -46,6 +47,27 @@ export async function applyAutoPickup(
|
|
|
46
47
|
if (mode !== 'off' && mode !== 'rule' && mode !== 'smart-observe' && mode !== 'smart-auto') return { ok: false, problem: 'invalid_mode' };
|
|
47
48
|
const state = clusterStore.getClusterCached(clusterId) ?? await clusterStore.readCluster(clusterId).catch(() => null);
|
|
48
49
|
if (!state) return { ok: false, problem: 'unknown_cluster' };
|
|
50
|
+
if (request.paused !== undefined) {
|
|
51
|
+
if (typeof request.paused !== 'boolean' || mode === 'off' || mode !== clusterStore.autoPickupModeOf(state)
|
|
52
|
+
|| request.resumeRule || request.evaluator !== undefined || request.limits !== undefined || request.ruleLimits !== undefined || request.remindBusy !== undefined) return { ok: false, problem: 'invalid_pause' };
|
|
53
|
+
const session = state.smartPickup?.session;
|
|
54
|
+
if (isSmartPickupMode(mode) && (!session || (state.autoPickupPausedAt ?? now) >= session.expiresAt)) {
|
|
55
|
+
await disarm(clusterId, session ? 'session_expired' : 'session_missing', now);
|
|
56
|
+
return { ok: true, mode: 'off' };
|
|
57
|
+
}
|
|
58
|
+
const updated = await clusterStore.setAutoPickup(clusterId, { mode, paused: request.paused, now });
|
|
59
|
+
if (!updated) return { ok: false, problem: 'invalid_pause' };
|
|
60
|
+
await recordSmartPickupDecision(clusterId, { at: now, action: null, reason: request.paused ? 'operator_paused' : 'operator_resumed', outcome: 'none' }).catch(() => undefined);
|
|
61
|
+
if (state.autoPickupPausedAt !== undefined && !request.paused) {
|
|
62
|
+
// Reply with the new control state promptly; evaluator requests may take
|
|
63
|
+
// time. Both scans use the same admission path as ordinary waiting mail.
|
|
64
|
+
setImmediate(() => {
|
|
65
|
+
void (mode === 'rule' ? ruleAutoTurn.pickupWaitingMail(clusterId) : pickupSmartWaitingMail(clusterId)).catch((error) => console.error('[arco] auto-pickup resume failed:', error));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, mode };
|
|
69
|
+
}
|
|
70
|
+
if (request.resumeRule && state.autoPickupPausedAt !== undefined) return { ok: false, problem: 'invalid_pause' };
|
|
49
71
|
let evaluator: SmartPickupEvaluator | undefined;
|
|
50
72
|
if (isSmartPickupMode(mode)) {
|
|
51
73
|
evaluator = sanitizeSmartPickupEvaluator(request.evaluator) ?? undefined;
|
|
@@ -99,6 +121,8 @@ export async function autoPickupStateFor(state: clusterStore.ClusterState, now =
|
|
|
99
121
|
const smart = state.smartPickup ?? {};
|
|
100
122
|
const out: ClusterAutoPickupState = {
|
|
101
123
|
mode,
|
|
124
|
+
paused: state.autoPickupPausedAt !== undefined,
|
|
125
|
+
...(state.autoPickupPausedAt !== undefined ? { pausedAt: state.autoPickupPausedAt } : {}),
|
|
102
126
|
remindBusy: state.remindBusy === true,
|
|
103
127
|
limits: sanitizeSmartPickupLimits(smart.limits),
|
|
104
128
|
ruleLimits: sanitizeRulePickupLimits(state.rulePickupLimits),
|
|
@@ -134,7 +158,7 @@ export async function sweepSmartPickup(now = Date.now()): Promise<void> {
|
|
|
134
158
|
if (!state || !isSmartPickupMode(clusterStore.autoPickupModeOf(state))) continue;
|
|
135
159
|
const session = state.smartPickup?.session;
|
|
136
160
|
if (!session || !state.smartPickup?.evaluator) { await disarm(clusterId, 'session_missing', now); continue; }
|
|
137
|
-
if (now >= session.expiresAt) { await disarm(clusterId, 'session_expired', now); continue; }
|
|
161
|
+
if (state.autoPickupPausedAt === undefined && now >= session.expiresAt) { await disarm(clusterId, 'session_expired', now); continue; }
|
|
138
162
|
try { await smartPickupSnapshot(clusterId, session.id, now); }
|
|
139
163
|
catch { await disarm(clusterId, 'ledger_unreadable', now); }
|
|
140
164
|
}
|
|
@@ -11,7 +11,7 @@ import { join } from 'node:path';
|
|
|
11
11
|
import { randomUUID } from 'node:crypto';
|
|
12
12
|
import type { SmartPickupCounters, SmartPickupDecisionRecord, SmartPickupLimits } from '@arco/shared';
|
|
13
13
|
import { atomicWriteFile } from './atomicFile.js';
|
|
14
|
-
import { clusterDir } from './clusterStore.js';
|
|
14
|
+
import { clusterDir, getClusterCached } from './clusterStore.js';
|
|
15
15
|
|
|
16
16
|
export type SmartPickupReservationKind = 'evaluator' | 'wake';
|
|
17
17
|
|
|
@@ -36,8 +36,9 @@ interface LedgerFile {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const HOUR_MS = 60 * 60 * 1000;
|
|
39
|
-
//
|
|
40
|
-
// of at most 8 hours), so they are dropped on the next write.
|
|
39
|
+
// Older entries normally cannot affect a limit (hour windows and sessions
|
|
40
|
+
// of at most 8 hours), so they are dropped on the next write. Pauses can
|
|
41
|
+
// extend a session's wall-clock life: retain its entries until it ends.
|
|
41
42
|
const RETAIN_MS = 9 * HOUR_MS;
|
|
42
43
|
const DECISIONS_KEPT = 50;
|
|
43
44
|
|
|
@@ -75,7 +76,8 @@ async function read(clusterId: string): Promise<LedgerFile> {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
async function write(clusterId: string, ledger: LedgerFile, now: number): Promise<void> {
|
|
78
|
-
|
|
79
|
+
const activeSession = getClusterCached(clusterId)?.smartPickup?.session?.id;
|
|
80
|
+
ledger.entries = ledger.entries.filter((e) => e.status === 'reserved' || e.sessionId === activeSession || now - e.at < RETAIN_MS);
|
|
79
81
|
ledger.decisions = ledger.decisions.slice(-DECISIONS_KEPT);
|
|
80
82
|
await fs.mkdir(clusterDir(clusterId), { recursive: true });
|
|
81
83
|
await atomicWriteFile(ledgerPath(clusterId), JSON.stringify(ledger, null, 2));
|
|
@@ -130,7 +130,7 @@ function armed(clusterId: string): { sessionId: string; mode: 'smart-observe' |
|
|
|
130
130
|
if (!state) return null;
|
|
131
131
|
const mode = clusterStore.autoPickupModeOf(state);
|
|
132
132
|
const session = state.smartPickup?.session;
|
|
133
|
-
if (!isSmartPickupMode(mode) || !session || !state.smartPickup?.evaluator) return null;
|
|
133
|
+
if (state.autoPickupPausedAt !== undefined || !isSmartPickupMode(mode) || !session || !state.smartPickup?.evaluator) return null;
|
|
134
134
|
if (deps.now() >= session.expiresAt) return null;
|
|
135
135
|
return { sessionId: session.id, mode };
|
|
136
136
|
}
|
|
@@ -139,9 +139,9 @@ function armed(clusterId: string): { sessionId: string; mode: 'smart-observe' |
|
|
|
139
139
|
// evaluation per recipient at a time; a trigger during a run schedules one
|
|
140
140
|
// more pass afterwards.
|
|
141
141
|
export function onSmartPickupMail(clusterId: string, workflowId: string, chainDepth = 0): Promise<void> {
|
|
142
|
-
if (!armed(clusterId)) return Promise.resolve();
|
|
143
142
|
const k = key(clusterId, workflowId);
|
|
144
143
|
if (chainDepth > (depthSeen.get(k) ?? 0)) depthSeen.set(k, chainDepth);
|
|
144
|
+
if (!armed(clusterId)) return Promise.resolve();
|
|
145
145
|
const current = running.get(k);
|
|
146
146
|
if (current) { rerun.add(k); return current; }
|
|
147
147
|
const run = (async () => {
|
|
@@ -205,6 +205,7 @@ export async function evaluateOnce(clusterId: string, workflowId: string): Promi
|
|
|
205
205
|
return d;
|
|
206
206
|
}
|
|
207
207
|
const evaluator = state.smartPickup!.evaluator!;
|
|
208
|
+
if (armed(clusterId)?.sessionId !== arm.sessionId) return null;
|
|
208
209
|
const slot = await reserveSmartPickup(clusterId, { kind: 'evaluator', memberId: workflowId, sessionId: arm.sessionId, limits, now: deps.now() }).catch(() => ({ ok: false as const, reason: 'ledger_unreadable' }));
|
|
209
210
|
if (!slot.ok) {
|
|
210
211
|
const d = { ...base, action: null, reason: slot.reason, outcome: 'skipped' };
|
|
@@ -219,6 +220,10 @@ export async function evaluateOnce(clusterId: string, workflowId: string): Promi
|
|
|
219
220
|
}
|
|
220
221
|
let raw: string | null = null;
|
|
221
222
|
let failure: string | null = null;
|
|
223
|
+
if (armed(clusterId)?.sessionId !== arm.sessionId) {
|
|
224
|
+
await settleSmartPickup(clusterId, slot.id, 'session_changed', deps.now()).catch(() => undefined);
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
222
227
|
try {
|
|
223
228
|
raw = await evaluatorAdapter(evaluator.provider).evaluate({
|
|
224
229
|
model: evaluator.model,
|
|
@@ -361,21 +366,25 @@ export async function sweepSmartPickupMail(): Promise<void> {
|
|
|
361
366
|
sweeping = true;
|
|
362
367
|
try {
|
|
363
368
|
for (const clusterId of clusterStore.listKnownClusterIds().sort()) {
|
|
364
|
-
|
|
365
|
-
const members = [...(clusterStore.getClusterCached(clusterId)?.members ?? [])].sort();
|
|
366
|
-
// One member at a time per cluster, in a stable order, so the
|
|
367
|
-
// in-flight limit is respected and no mailbox starves another.
|
|
368
|
-
for (const wfid of members) {
|
|
369
|
-
if (deps.isBusy(wfid)) continue;
|
|
370
|
-
const depth = await clusterMailbox.depthFor(wfid).catch(() => 0);
|
|
371
|
-
if (depth > 0) await onSmartPickupMail(clusterId, wfid).catch(() => undefined);
|
|
372
|
-
}
|
|
369
|
+
await pickupSmartWaitingMail(clusterId);
|
|
373
370
|
}
|
|
374
371
|
} finally {
|
|
375
372
|
sweeping = false;
|
|
376
373
|
}
|
|
377
374
|
}
|
|
378
375
|
|
|
376
|
+
export async function pickupSmartWaitingMail(clusterId: string): Promise<void> {
|
|
377
|
+
if (!armed(clusterId)) return;
|
|
378
|
+
const members = [...(clusterStore.getClusterCached(clusterId)?.members ?? [])].sort();
|
|
379
|
+
// One member at a time per cluster, in a stable order, so the
|
|
380
|
+
// in-flight limit is respected and no mailbox starves another.
|
|
381
|
+
for (const wfid of members) {
|
|
382
|
+
if (deps.isBusy(wfid)) continue;
|
|
383
|
+
const depth = await clusterMailbox.depthFor(wfid).catch(() => 0);
|
|
384
|
+
if (depth > 0) await onSmartPickupMail(clusterId, wfid).catch(() => undefined);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
379
388
|
let mailTimer: NodeJS.Timeout | null = null;
|
|
380
389
|
const MAIL_SWEEP_MS = (() => {
|
|
381
390
|
const raw = Number(process.env.ARCO_SMART_PICKUP_MAIL_SWEEP_MS);
|
|
@@ -2517,14 +2517,15 @@ export async function handleClusterAutoTurnToggle(
|
|
|
2517
2517
|
// Operator chose an AUTO-PICKUP mode in the cluster dialog. Smart modes need
|
|
2518
2518
|
// an evaluator from an enabled provider and start a new session; Off and
|
|
2519
2519
|
// Rule-based end any Smart session. Pushes cluster_state on success.
|
|
2520
|
+
// A pause-only request keeps the current mode, session and budgets.
|
|
2520
2521
|
export async function handleClusterAutoPickupSet(
|
|
2521
2522
|
ws: WebSocket,
|
|
2522
|
-
msg: { clusterId: string; mode: unknown; evaluator?: unknown; limits?: unknown; ruleLimits?: unknown; resumeRule?: boolean; remindBusy?: boolean },
|
|
2523
|
+
msg: { clusterId: string; mode: unknown; paused?: unknown; evaluator?: unknown; limits?: unknown; ruleLimits?: unknown; resumeRule?: boolean; remindBusy?: boolean },
|
|
2523
2524
|
): Promise<void> {
|
|
2524
2525
|
const settings = await readSettings().catch(() => null);
|
|
2525
2526
|
const result = await applyAutoPickup(
|
|
2526
2527
|
msg.clusterId,
|
|
2527
|
-
{ mode: msg.mode, evaluator: msg.evaluator, limits: msg.limits, ruleLimits: msg.ruleLimits, resumeRule: msg.resumeRule },
|
|
2528
|
+
{ mode: msg.mode, paused: msg.paused, evaluator: msg.evaluator, limits: msg.limits, ruleLimits: msg.ruleLimits, resumeRule: msg.resumeRule },
|
|
2528
2529
|
(provider) => settings?.enabledProviders?.[provider] !== false,
|
|
2529
2530
|
);
|
|
2530
2531
|
if (!result.ok) {
|
|
@@ -67,6 +67,8 @@ export interface SmartPickupCounters {
|
|
|
67
67
|
}
|
|
68
68
|
export interface ClusterAutoPickupState {
|
|
69
69
|
remindBusy?: boolean;
|
|
70
|
+
paused?: boolean;
|
|
71
|
+
pausedAt?: number;
|
|
70
72
|
mode: AutoPickupMode;
|
|
71
73
|
limits: SmartPickupLimits;
|
|
72
74
|
evaluator?: SmartPickupEvaluator;
|
|
@@ -90,6 +92,7 @@ export interface ClusterAutoPickupSetMessage {
|
|
|
90
92
|
limits?: Partial<SmartPickupLimits>;
|
|
91
93
|
ruleLimits?: Partial<RulePickupLimits>;
|
|
92
94
|
resumeRule?: boolean;
|
|
95
|
+
paused?: boolean;
|
|
93
96
|
remindBusy?: boolean;
|
|
94
97
|
}
|
|
95
98
|
export interface RulePickupLimits {
|
|
@@ -156,6 +156,8 @@ export interface SmartPickupCounters {
|
|
|
156
156
|
|
|
157
157
|
export interface ClusterAutoPickupState {
|
|
158
158
|
remindBusy?: boolean;
|
|
159
|
+
paused?: boolean;
|
|
160
|
+
pausedAt?: number;
|
|
159
161
|
mode: AutoPickupMode;
|
|
160
162
|
limits: SmartPickupLimits;
|
|
161
163
|
evaluator?: SmartPickupEvaluator;
|
|
@@ -171,6 +173,7 @@ export interface ClusterAutoPickupState {
|
|
|
171
173
|
|
|
172
174
|
// Operator sets the mode. Smart modes need an evaluator; limits are
|
|
173
175
|
// optional and default per SMART_PICKUP_LIMIT_SPECS.
|
|
176
|
+
// A pause-only request keeps the current mode and omits arming fields.
|
|
174
177
|
export interface ClusterAutoPickupSetMessage {
|
|
175
178
|
type: 'cluster_auto_pickup_set';
|
|
176
179
|
clusterId: string;
|
|
@@ -179,6 +182,8 @@ export interface ClusterAutoPickupSetMessage {
|
|
|
179
182
|
limits?: Partial<SmartPickupLimits>;
|
|
180
183
|
ruleLimits?: Partial<RulePickupLimits>;
|
|
181
184
|
resumeRule?: boolean;
|
|
185
|
+
// Pause/resume the current mode without rearming or resetting its budgets.
|
|
186
|
+
paused?: boolean;
|
|
182
187
|
remindBusy?: boolean;
|
|
183
188
|
}
|
|
184
189
|
|