@volter/supercode-orchestrator 0.4.11 → 0.4.13
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/bin/orchestrator.mjs +10 -0
- package/package.json +1 -1
- package/reducer.mjs +14 -3
package/bin/orchestrator.mjs
CHANGED
|
@@ -69,6 +69,9 @@ import * as events from '../events.mjs';
|
|
|
69
69
|
import { httpJobExecutor } from '../hosted.mjs';
|
|
70
70
|
import { SupercodeHarnessClient } from '@volter/supercode-harness-sdk';
|
|
71
71
|
|
|
72
|
+
/** How long a starting daemon waits for a stopping predecessor to release the home's lease. */
|
|
73
|
+
const LEASE_HANDOFF_MS = 20_000;
|
|
74
|
+
|
|
72
75
|
/// Adapter selector -> constructor. A `platforms:` block picks its adapter by
|
|
73
76
|
/// `extra.adapter` when it has one and by the block's own name otherwise, so
|
|
74
77
|
/// `platforms.slack.extra.adapter: chat-sdk` and `platforms.api_server` both
|
|
@@ -596,6 +599,13 @@ async function main() {
|
|
|
596
599
|
if (!args.once) {
|
|
597
600
|
// Serialize lease replacement before loading state. An acquisition guard
|
|
598
601
|
// left by a crash fails closed; inspect it before removing it manually.
|
|
602
|
+
// A service manager's restart starts this one while the last is still stopping (launchd's kickstart -k did, and
|
|
603
|
+
// this one exited 'already serving'): a live predecessor gets a moment to let go before it counts as serving.
|
|
604
|
+
for (let waited = 0; waited < LEASE_HANDOFF_MS; waited += 250) {
|
|
605
|
+
const previous = readLock(root);
|
|
606
|
+
if (!previous || previous.pid === process.pid || !leaseIsLive(previous)) break;
|
|
607
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
608
|
+
}
|
|
599
609
|
const guard = join(root, 'orchestrator.acquire');
|
|
600
610
|
mkdirSync(guard);
|
|
601
611
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-orchestrator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The orchestrator runtime over the Volter Harness ontology: one typed operational model whose folder is its serialization, read and written through the harness orchestration doors (docs/ORCHESTRATOR-IR.md)",
|
|
6
6
|
"exports": {
|
package/reducer.mjs
CHANGED
|
@@ -549,8 +549,8 @@ function handleTick(state, ev, effects) {
|
|
|
549
549
|
// ---------------------------------------------------------------- restart / adapter / operator
|
|
550
550
|
|
|
551
551
|
// §4.7 on a clean stop: the daemon closes every runtime, so each binding that held one keeps it as the runtime to
|
|
552
|
-
// resume, as a crash's pass marks it, and the
|
|
553
|
-
// on its surface; an idle binding is not.
|
|
552
|
+
// resume, as a crash's pass marks it, and the restart reopens the same session (a clean stop is a restart's). A turn
|
|
553
|
+
// cut off mid-way is told so on its surface; an idle binding is not.
|
|
554
554
|
function handleStopping(state, ev, effects) {
|
|
555
555
|
const rt = ensureRuntime(state);
|
|
556
556
|
for (const profile of Object.values(state.profiles)) {
|
|
@@ -558,6 +558,8 @@ function handleStopping(state, ev, effects) {
|
|
|
558
558
|
if (b.ended_at || ks.includes('#') || !b.residue?.runtime_id) continue;
|
|
559
559
|
b.residue.resume_runtime_id = b.residue.runtime_id;
|
|
560
560
|
delete b.residue.runtime_id;
|
|
561
|
+
// a stop for a restart: what was live now is live again once the daemon is back (handleRestart)
|
|
562
|
+
if (b.key.platform !== 'webhook' && b.key.platform !== 'cron') b.residue.reopen_at_start = true;
|
|
561
563
|
if (rt.turns[leaseId(profile.name, ks)] && !b.recurrence && b.key.platform !== 'webhook' && b.key.platform !== 'cron') {
|
|
562
564
|
b.residue.interrupted_at = ev.at;
|
|
563
565
|
reply(state, profile, b.key, REPLY.interrupted, ev.at, effects);
|
|
@@ -579,7 +581,16 @@ function handleRestart(state, ev, effects) {
|
|
|
579
581
|
// attaches where the worker's door allows it and marks the rest
|
|
580
582
|
// interrupted (`binding_interrupted` below).
|
|
581
583
|
for (const [ks, b] of Object.entries(profile.bindings)) {
|
|
582
|
-
if (b.ended_at || ks.includes('#')
|
|
584
|
+
if (b.ended_at || ks.includes('#')) continue;
|
|
585
|
+
// one the clean stop closed reopens its own session now, so its conversation stays reachable (a message, a
|
|
586
|
+
// voice line) rather than waiting for its next inbound
|
|
587
|
+
if (!b.residue?.runtime_id) {
|
|
588
|
+
if (!b.residue?.reopen_at_start) continue;
|
|
589
|
+
delete b.residue.reopen_at_start;
|
|
590
|
+
live += 1;
|
|
591
|
+
startWorker(state, profile, ks, effects);
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
583
594
|
live += 1;
|
|
584
595
|
// a message arriving while the attach is in flight queues behind it,
|
|
585
596
|
// rather than starting a fresh runtime that would replace the session
|