@myclaw163/clawclaw-cli 0.7.15 → 0.7.16
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/package.json +1 -1
- package/skills/clawclaw/SKILL.md +1 -1
- package/src/lib/game-client.ts +2 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +1 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +1 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +181 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +195 -0
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始、匹配、创建或加入好友房、继续或游玩一局龙虾杀。Use when the user asks to play/start/join/continue a ClawClaw match or friend room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.80
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
package/src/lib/game-client.ts
CHANGED
|
@@ -93,6 +93,7 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
93
93
|
['speech', ['communication']],
|
|
94
94
|
['vote', ['meeting_vote']],
|
|
95
95
|
['think', []],
|
|
96
|
+
['strategy', []],
|
|
96
97
|
['future_action', ['*']],
|
|
97
98
|
])('maps %s onto generic control domains', (action, domains) => {
|
|
98
99
|
expect(describeClawclawActionControl({ action: { action } })).toEqual({
|
|
@@ -167,6 +167,30 @@ function actionContext(actions: Array<{ epoch: number; action: Record<string, un
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
function successfulStrategyReportResult() {
|
|
171
|
+
return {
|
|
172
|
+
scope,
|
|
173
|
+
actionId: 'strategy-report-action',
|
|
174
|
+
status: 'success' as const,
|
|
175
|
+
source: 'backend' as const,
|
|
176
|
+
actionOutcome: 'confirmed' as const,
|
|
177
|
+
value: { success: true, data: { ok: true } },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function reportingPlugin(): ClawclawStrategyPlugin {
|
|
182
|
+
return new ClawclawStrategyPlugin({
|
|
183
|
+
executorFactory: () => ({
|
|
184
|
+
runtimeInstanceId: 'strategy-reporting-test',
|
|
185
|
+
isAlive: true,
|
|
186
|
+
async start() {},
|
|
187
|
+
async reset() {},
|
|
188
|
+
async update() { return {}; },
|
|
189
|
+
async stop() {},
|
|
190
|
+
}),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
170
194
|
async function run(
|
|
171
195
|
plugin: ClawclawStrategyPlugin,
|
|
172
196
|
pluginInput: RuntimeEpochPluginInput<Record<string, any>>,
|
|
@@ -235,6 +259,163 @@ describe('ClawClaw Strategy plugin scheduling', () => {
|
|
|
235
259
|
await plugin.stop('shutdown');
|
|
236
260
|
});
|
|
237
261
|
|
|
262
|
+
it('reports the effective strategy asynchronously and suppresses repeats after the exact ack', async () => {
|
|
263
|
+
vi.useFakeTimers();
|
|
264
|
+
try {
|
|
265
|
+
let resolveReport!: (value: ReturnType<typeof successfulStrategyReportResult>) => void;
|
|
266
|
+
const pendingReport = new Promise<ReturnType<typeof successfulStrategyReportResult>>((resolve) => {
|
|
267
|
+
resolveReport = resolve;
|
|
268
|
+
});
|
|
269
|
+
const performAction = vi.fn(() => pendingReport);
|
|
270
|
+
const baseContext = context(() => {});
|
|
271
|
+
const pluginContext: RuntimeEpochPluginContext<Record<string, any>> = {
|
|
272
|
+
...baseContext,
|
|
273
|
+
capabilities: {
|
|
274
|
+
...baseContext.capabilities,
|
|
275
|
+
performAction: performAction as RuntimeEpochPluginContext<Record<string, any>>[
|
|
276
|
+
'capabilities'
|
|
277
|
+
]['performAction'],
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
const plugin = reportingPlugin();
|
|
281
|
+
plugin.select({
|
|
282
|
+
id: 'task-only',
|
|
283
|
+
name: 'Task only',
|
|
284
|
+
description: 'Complete assigned tasks.',
|
|
285
|
+
localizations: {
|
|
286
|
+
'zh-CN': { name: '纯任务', description: '专心完成分配的任务。' },
|
|
287
|
+
},
|
|
288
|
+
sourcePath: 'unused',
|
|
289
|
+
sourceRoot: 'unused',
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
await expect(run(plugin, input(1), pluginContext)).resolves.toMatchObject({
|
|
293
|
+
outcome: 'processed',
|
|
294
|
+
});
|
|
295
|
+
expect(performAction).not.toHaveBeenCalled();
|
|
296
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
297
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
298
|
+
expect(performAction).toHaveBeenCalledWith('clawclaw.action', {
|
|
299
|
+
route: 'game',
|
|
300
|
+
action: {
|
|
301
|
+
action: 'strategy',
|
|
302
|
+
name: '纯任务',
|
|
303
|
+
description: '专心完成分配的任务。',
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
resolveReport(successfulStrategyReportResult());
|
|
308
|
+
await Promise.resolve();
|
|
309
|
+
await Promise.resolve();
|
|
310
|
+
await run(plugin, input(2), pluginContext);
|
|
311
|
+
await vi.advanceTimersByTimeAsync(5_000);
|
|
312
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
313
|
+
await plugin.stop('shutdown');
|
|
314
|
+
} finally {
|
|
315
|
+
vi.useRealTimers();
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('retries an incorrect strategy report response once per second until acknowledged', async () => {
|
|
320
|
+
vi.useFakeTimers();
|
|
321
|
+
try {
|
|
322
|
+
const performAction = vi.fn()
|
|
323
|
+
.mockResolvedValueOnce({
|
|
324
|
+
...successfulStrategyReportResult(),
|
|
325
|
+
value: { success: true, data: { ok: false } },
|
|
326
|
+
})
|
|
327
|
+
.mockResolvedValue(successfulStrategyReportResult());
|
|
328
|
+
const baseContext = context(() => {});
|
|
329
|
+
const pluginContext: RuntimeEpochPluginContext<Record<string, any>> = {
|
|
330
|
+
...baseContext,
|
|
331
|
+
capabilities: {
|
|
332
|
+
...baseContext.capabilities,
|
|
333
|
+
performAction: performAction as RuntimeEpochPluginContext<Record<string, any>>[
|
|
334
|
+
'capabilities'
|
|
335
|
+
]['performAction'],
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
const plugin = reportingPlugin();
|
|
339
|
+
plugin.select({
|
|
340
|
+
id: 'patrol',
|
|
341
|
+
name: '巡逻',
|
|
342
|
+
description: '按房间顺序巡逻。',
|
|
343
|
+
sourcePath: 'unused',
|
|
344
|
+
sourceRoot: 'unused',
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
await run(plugin, input(1), pluginContext);
|
|
348
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
349
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
350
|
+
await vi.advanceTimersByTimeAsync(999);
|
|
351
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
352
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
353
|
+
expect(performAction).toHaveBeenCalledTimes(2);
|
|
354
|
+
await vi.advanceTimersByTimeAsync(5_000);
|
|
355
|
+
expect(performAction).toHaveBeenCalledTimes(2);
|
|
356
|
+
await plugin.stop('shutdown');
|
|
357
|
+
} finally {
|
|
358
|
+
vi.useRealTimers();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('does not let an old in-flight acknowledgement confirm a newly selected strategy', async () => {
|
|
363
|
+
vi.useFakeTimers();
|
|
364
|
+
try {
|
|
365
|
+
let resolveFirst!: (value: ReturnType<typeof successfulStrategyReportResult>) => void;
|
|
366
|
+
const first = new Promise<ReturnType<typeof successfulStrategyReportResult>>((resolve) => {
|
|
367
|
+
resolveFirst = resolve;
|
|
368
|
+
});
|
|
369
|
+
const performAction = vi.fn()
|
|
370
|
+
.mockImplementationOnce(() => first)
|
|
371
|
+
.mockResolvedValue(successfulStrategyReportResult());
|
|
372
|
+
const baseContext = context(() => {});
|
|
373
|
+
const pluginContext: RuntimeEpochPluginContext<Record<string, any>> = {
|
|
374
|
+
...baseContext,
|
|
375
|
+
capabilities: {
|
|
376
|
+
...baseContext.capabilities,
|
|
377
|
+
performAction: performAction as RuntimeEpochPluginContext<Record<string, any>>[
|
|
378
|
+
'capabilities'
|
|
379
|
+
]['performAction'],
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
const plugin = reportingPlugin();
|
|
383
|
+
plugin.select({
|
|
384
|
+
id: 'first',
|
|
385
|
+
name: '策略甲',
|
|
386
|
+
description: '策略甲描述。',
|
|
387
|
+
sourcePath: 'unused',
|
|
388
|
+
sourceRoot: 'unused',
|
|
389
|
+
});
|
|
390
|
+
await run(plugin, input(1), pluginContext);
|
|
391
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
392
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
393
|
+
|
|
394
|
+
plugin.select({
|
|
395
|
+
id: 'second',
|
|
396
|
+
name: '策略乙',
|
|
397
|
+
description: '策略乙描述。',
|
|
398
|
+
sourcePath: 'unused',
|
|
399
|
+
sourceRoot: 'unused',
|
|
400
|
+
});
|
|
401
|
+
await run(plugin, input(2), pluginContext);
|
|
402
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
403
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
404
|
+
|
|
405
|
+
resolveFirst(successfulStrategyReportResult());
|
|
406
|
+
await Promise.resolve();
|
|
407
|
+
await Promise.resolve();
|
|
408
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
409
|
+
expect(performAction).toHaveBeenCalledTimes(2);
|
|
410
|
+
expect(performAction.mock.calls[1]?.[1]).toMatchObject({
|
|
411
|
+
action: { action: 'strategy', name: '策略乙', description: '策略乙描述。' },
|
|
412
|
+
});
|
|
413
|
+
await plugin.stop('shutdown');
|
|
414
|
+
} finally {
|
|
415
|
+
vi.useRealTimers();
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
238
419
|
it('releases each Strategy activation, including a same-id parameter generation', async () => {
|
|
239
420
|
const releases: Array<{ capability: string; id: string; reason?: string }> = [];
|
|
240
421
|
const baseContext = context(() => {});
|
|
@@ -45,6 +45,18 @@ export const CLAWCLAW_STRATEGY_PLUGIN_ID = 'clawclaw.strategy';
|
|
|
45
45
|
export const CLAWCLAW_STRATEGY_STATE_TOPIC = 'strategy.status';
|
|
46
46
|
export const CLAWCLAW_STRATEGY_EVENT_TYPES = ['strategy_alert', 'robot_speak_rule'] as const;
|
|
47
47
|
|
|
48
|
+
const STRATEGY_REPORT_LOCALE = 'zh-CN';
|
|
49
|
+
const STRATEGY_REPORT_RETRY_MS = 1_000;
|
|
50
|
+
|
|
51
|
+
interface StrategyReportTarget extends ClawclawResolvedResourceMetadata {
|
|
52
|
+
readonly fingerprint: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface StrategyReportAttempt {
|
|
56
|
+
readonly lifecycleGeneration: number;
|
|
57
|
+
readonly fingerprint: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
export interface ClawclawStrategySelection extends StrategySource {
|
|
49
61
|
readonly parameters?: Readonly<Record<string, unknown>>;
|
|
50
62
|
readonly controls?: readonly StrategyControlSpec[];
|
|
@@ -220,6 +232,25 @@ function diagnosticErrorCode(error: unknown, fallback: string): string {
|
|
|
220
232
|
return /^([A-Za-z][A-Za-z0-9_.-]{0,119})(?::|$)/.exec(message.trim())?.[1] ?? fallback;
|
|
221
233
|
}
|
|
222
234
|
|
|
235
|
+
function isSuccessfulStrategyReportResponse(value: unknown): boolean {
|
|
236
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
237
|
+
const result = value as Record<string, unknown>;
|
|
238
|
+
if (
|
|
239
|
+
result.status !== 'success'
|
|
240
|
+
|| result.source !== 'backend'
|
|
241
|
+
|| result.actionOutcome !== 'confirmed'
|
|
242
|
+
) return false;
|
|
243
|
+
const response = result.value;
|
|
244
|
+
if (!response || typeof response !== 'object' || Array.isArray(response)) return false;
|
|
245
|
+
const root = response as Record<string, unknown>;
|
|
246
|
+
const data = root.data;
|
|
247
|
+
return root.success === true
|
|
248
|
+
&& !!data
|
|
249
|
+
&& typeof data === 'object'
|
|
250
|
+
&& !Array.isArray(data)
|
|
251
|
+
&& (data as Record<string, unknown>).ok === true;
|
|
252
|
+
}
|
|
253
|
+
|
|
223
254
|
function strategyActionControllerId(strategyId: string, generation: number): string {
|
|
224
255
|
return `${strategyId}@activation-${generation}`;
|
|
225
256
|
}
|
|
@@ -417,6 +448,13 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
417
448
|
private selectedGeneration = 0;
|
|
418
449
|
private parameterGeneration = 0;
|
|
419
450
|
private readonly committedActionDedupeKeys = new Map<string, number>();
|
|
451
|
+
private strategyReportTarget?: StrategyReportTarget;
|
|
452
|
+
private strategyReportAcknowledgedFingerprint?: string;
|
|
453
|
+
private strategyReportInFlight?: StrategyReportAttempt;
|
|
454
|
+
private strategyReportTimer?: ReturnType<typeof setTimeout>;
|
|
455
|
+
private strategyReportContext?: RuntimeEpochPluginContext<Record<string, any>>;
|
|
456
|
+
private strategyReportEligible = false;
|
|
457
|
+
private strategyReportLifecycleGeneration = 0;
|
|
420
458
|
|
|
421
459
|
constructor(options: ClawclawStrategyPluginOptions = {}) {
|
|
422
460
|
this.after = [...(options.after ?? [])];
|
|
@@ -503,6 +541,160 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
503
541
|
}, locale);
|
|
504
542
|
}
|
|
505
543
|
|
|
544
|
+
private refreshStrategyReportRuntime(
|
|
545
|
+
input: RuntimeEpochPluginInput<Record<string, any>>,
|
|
546
|
+
context: RuntimeEpochPluginContext<Record<string, any>>,
|
|
547
|
+
): void {
|
|
548
|
+
const wasEligible = this.strategyReportEligible;
|
|
549
|
+
const state = input.epoch.state;
|
|
550
|
+
this.strategyReportContext = context;
|
|
551
|
+
this.strategyReportEligible = isClawclawRuntimeState(state)
|
|
552
|
+
&& state.connection === 'connected'
|
|
553
|
+
&& freshWanderingEpoch(input);
|
|
554
|
+
|
|
555
|
+
const descriptor = this.activeResourceDescriptor(STRATEGY_REPORT_LOCALE);
|
|
556
|
+
const nextTarget = descriptor
|
|
557
|
+
? {
|
|
558
|
+
...descriptor,
|
|
559
|
+
fingerprint: JSON.stringify([descriptor.id, descriptor.name, descriptor.description]),
|
|
560
|
+
}
|
|
561
|
+
: undefined;
|
|
562
|
+
const targetChanged = nextTarget?.fingerprint !== this.strategyReportTarget?.fingerprint;
|
|
563
|
+
if (targetChanged) {
|
|
564
|
+
this.strategyReportTarget = nextTarget;
|
|
565
|
+
this.clearStrategyReportTimer();
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
const target = this.strategyReportTarget;
|
|
569
|
+
if (!target || this.strategyReportAcknowledgedFingerprint === target.fingerprint) {
|
|
570
|
+
this.clearStrategyReportTimer();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (targetChanged || (!wasEligible && this.strategyReportEligible)) {
|
|
574
|
+
this.scheduleStrategyReport(0, true);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
private clearStrategyReportTimer(): void {
|
|
579
|
+
if (!this.strategyReportTimer) return;
|
|
580
|
+
clearTimeout(this.strategyReportTimer);
|
|
581
|
+
this.strategyReportTimer = undefined;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
private scheduleStrategyReport(delayMs: number, replace = false): void {
|
|
585
|
+
const target = this.strategyReportTarget;
|
|
586
|
+
if (
|
|
587
|
+
!target
|
|
588
|
+
|| this.strategyReportAcknowledgedFingerprint === target.fingerprint
|
|
589
|
+
|| this.strategyReportInFlight
|
|
590
|
+
) return;
|
|
591
|
+
if (this.strategyReportTimer) {
|
|
592
|
+
if (!replace) return;
|
|
593
|
+
this.clearStrategyReportTimer();
|
|
594
|
+
}
|
|
595
|
+
const lifecycleGeneration = this.strategyReportLifecycleGeneration;
|
|
596
|
+
this.strategyReportTimer = setTimeout(() => {
|
|
597
|
+
this.strategyReportTimer = undefined;
|
|
598
|
+
if (lifecycleGeneration !== this.strategyReportLifecycleGeneration) return;
|
|
599
|
+
this.startStrategyReportAttempt();
|
|
600
|
+
}, delayMs);
|
|
601
|
+
this.strategyReportTimer.unref?.();
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** Starts one host-owned report without extending the ordered Strategy commit. */
|
|
605
|
+
private startStrategyReportAttempt(): void {
|
|
606
|
+
const target = this.strategyReportTarget;
|
|
607
|
+
const context = this.strategyReportContext;
|
|
608
|
+
if (
|
|
609
|
+
!target
|
|
610
|
+
|| this.strategyReportAcknowledgedFingerprint === target.fingerprint
|
|
611
|
+
|| this.strategyReportInFlight
|
|
612
|
+
) return;
|
|
613
|
+
if (!this.strategyReportEligible || !context || context.signal.aborted) {
|
|
614
|
+
this.scheduleStrategyReport(STRATEGY_REPORT_RETRY_MS);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const attempt: StrategyReportAttempt = {
|
|
619
|
+
lifecycleGeneration: this.strategyReportLifecycleGeneration,
|
|
620
|
+
fingerprint: target.fingerprint,
|
|
621
|
+
};
|
|
622
|
+
this.strategyReportInFlight = attempt;
|
|
623
|
+
context.diagnostic('strategy.report.started', {
|
|
624
|
+
strategy_id: target.id,
|
|
625
|
+
}, 'debug');
|
|
626
|
+
|
|
627
|
+
let pending: Promise<unknown>;
|
|
628
|
+
try {
|
|
629
|
+
pending = context.capabilities.performAction(
|
|
630
|
+
CLAWCLAW_ACTION_CAPABILITY,
|
|
631
|
+
{
|
|
632
|
+
route: 'game',
|
|
633
|
+
action: {
|
|
634
|
+
action: 'strategy',
|
|
635
|
+
name: target.name,
|
|
636
|
+
description: target.description,
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
);
|
|
640
|
+
} catch (error) {
|
|
641
|
+
this.finishStrategyReportAttempt(attempt, false, error);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
void pending.then(
|
|
645
|
+
(result) => this.finishStrategyReportAttempt(
|
|
646
|
+
attempt,
|
|
647
|
+
isSuccessfulStrategyReportResponse(result),
|
|
648
|
+
result,
|
|
649
|
+
),
|
|
650
|
+
(error) => this.finishStrategyReportAttempt(attempt, false, error),
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
private finishStrategyReportAttempt(
|
|
655
|
+
attempt: StrategyReportAttempt,
|
|
656
|
+
successful: boolean,
|
|
657
|
+
result: unknown,
|
|
658
|
+
): void {
|
|
659
|
+
if (
|
|
660
|
+
attempt.lifecycleGeneration !== this.strategyReportLifecycleGeneration
|
|
661
|
+
|| this.strategyReportInFlight?.fingerprint !== attempt.fingerprint
|
|
662
|
+
) return;
|
|
663
|
+
this.strategyReportInFlight = undefined;
|
|
664
|
+
const target = this.strategyReportTarget;
|
|
665
|
+
if (successful && target?.fingerprint === attempt.fingerprint) {
|
|
666
|
+
this.strategyReportAcknowledgedFingerprint = attempt.fingerprint;
|
|
667
|
+
this.clearStrategyReportTimer();
|
|
668
|
+
this.strategyReportContext?.diagnostic('strategy.report.completed', {
|
|
669
|
+
strategy_id: target.id,
|
|
670
|
+
}, 'info');
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (target?.fingerprint === attempt.fingerprint) {
|
|
675
|
+
this.strategyReportContext?.diagnostic('strategy.report.retry_scheduled', {
|
|
676
|
+
strategy_id: target.id,
|
|
677
|
+
retry_ms: STRATEGY_REPORT_RETRY_MS,
|
|
678
|
+
error_code: diagnosticErrorCode(result, 'STRATEGY_REPORT_RESPONSE_INVALID'),
|
|
679
|
+
}, 'warn');
|
|
680
|
+
this.scheduleStrategyReport(STRATEGY_REPORT_RETRY_MS);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (target && this.strategyReportAcknowledgedFingerprint !== target.fingerprint) {
|
|
684
|
+
this.scheduleStrategyReport(0);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
private resetStrategyReporting(): void {
|
|
689
|
+
this.strategyReportLifecycleGeneration += 1;
|
|
690
|
+
this.clearStrategyReportTimer();
|
|
691
|
+
this.strategyReportTarget = undefined;
|
|
692
|
+
this.strategyReportAcknowledgedFingerprint = undefined;
|
|
693
|
+
this.strategyReportInFlight = undefined;
|
|
694
|
+
this.strategyReportContext = undefined;
|
|
695
|
+
this.strategyReportEligible = false;
|
|
696
|
+
}
|
|
697
|
+
|
|
506
698
|
async update(
|
|
507
699
|
input: RuntimeEpochPluginInput<Record<string, any>>,
|
|
508
700
|
context: RuntimeEpochPluginContext<Record<string, any>>,
|
|
@@ -652,6 +844,7 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
652
844
|
context: RuntimeEpochPluginContext<Record<string, any>>,
|
|
653
845
|
): Promise<RuntimeEpochPluginResult> {
|
|
654
846
|
const proposal = strategyProposal(computation.proposal);
|
|
847
|
+
this.refreshStrategyReportRuntime(input, context);
|
|
655
848
|
const previousInvokedEpochSeq = this.lastInvokedEpochSeq;
|
|
656
849
|
this.lastInvokedEpochSeq = input.epoch.epochSeq;
|
|
657
850
|
if (previousInvokedEpochSeq !== null && input.epoch.epochSeq > previousInvokedEpochSeq + 1) {
|
|
@@ -679,6 +872,7 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
679
872
|
return { outcome: 'noop', reason: 'strategy_computation_superseded' };
|
|
680
873
|
}
|
|
681
874
|
await this.applyPendingSelection(context);
|
|
875
|
+
this.refreshStrategyReportRuntime(input, context);
|
|
682
876
|
if (!this.selected || this.selectedGeneration !== proposal.generation) {
|
|
683
877
|
return { outcome: 'noop', reason: 'strategy_computation_superseded' };
|
|
684
878
|
}
|
|
@@ -797,6 +991,7 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
797
991
|
}
|
|
798
992
|
|
|
799
993
|
async stop(reason: 'segment_ending' | 'shutdown'): Promise<void> {
|
|
994
|
+
this.resetStrategyReporting();
|
|
800
995
|
const executor = this.executor;
|
|
801
996
|
this.executor = undefined;
|
|
802
997
|
const parallelExecutor = this.parallelExecutor;
|