instar 1.3.143 → 1.3.144
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/dist/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +8 -4
- package/dist/commands/server.js.map +1 -1
- package/dist/lifeline/ServerSupervisor.d.ts +18 -0
- package/dist/lifeline/ServerSupervisor.d.ts.map +1 -1
- package/dist/lifeline/ServerSupervisor.js +149 -0
- package/dist/lifeline/ServerSupervisor.js.map +1 -1
- package/dist/lifeline/TelegramLifeline.d.ts +8 -0
- package/dist/lifeline/TelegramLifeline.d.ts.map +1 -1
- package/dist/lifeline/TelegramLifeline.js +22 -0
- package/dist/lifeline/TelegramLifeline.js.map +1 -1
- package/dist/lifeline/agentSleepWake.d.ts +6 -0
- package/dist/lifeline/agentSleepWake.d.ts.map +1 -0
- package/dist/lifeline/agentSleepWake.js +33 -0
- package/dist/lifeline/agentSleepWake.js.map +1 -0
- package/dist/monitoring/SleepController.d.ts +8 -0
- package/dist/monitoring/SleepController.d.ts.map +1 -1
- package/dist/monitoring/SleepController.js +25 -0
- package/dist/monitoring/SleepController.js.map +1 -1
- package/package.json +1 -1
- package/src/data/builtin-manifest.json +3 -3
- package/upgrades/1.3.144.md +53 -0
- package/upgrades/side-effects/agent-hard-sleep-mechanism.md +115 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Upgrade Guide — vNEXT
|
|
2
|
+
|
|
3
|
+
<!-- bump: patch -->
|
|
4
|
+
|
|
5
|
+
## What Changed
|
|
6
|
+
|
|
7
|
+
**Agent hard-sleep can now actually stop and wake the server (dark + dry-run).**
|
|
8
|
+
The previous step taught an idle agent how to DECIDE whether it is safe to sleep but
|
|
9
|
+
never acted. This step builds the mechanism that acts on that decision: when sleep is
|
|
10
|
+
enabled and the agent is deeply idle and safe, its heavy background server is
|
|
11
|
+
stopped to save the machine's resources, and it wakes the instant a message arrives.
|
|
12
|
+
|
|
13
|
+
The handshake reuses the proven restart lifecycle: the decision layer writes a
|
|
14
|
+
sleep-request file, the supervisor stops the server and marks it intentionally
|
|
15
|
+
asleep (so it is NOT treated as a crash and is NOT auto-restarted), and an inbound
|
|
16
|
+
message makes the lifeline write a wake-request that the supervisor honors by
|
|
17
|
+
respawning the server. The waiting message is held in the existing durable queue and
|
|
18
|
+
delivered once the server is healthy, so nothing is lost. A safety marker means that
|
|
19
|
+
even if an outside watchdog force-restarts the agent mid-sleep, it reads the marker
|
|
20
|
+
on startup and stays asleep instead of fighting it. The existing crash-recovery
|
|
21
|
+
behavior is unchanged except in the one case where the agent chose to sleep, proven
|
|
22
|
+
by the existing supervisor tests staying green.
|
|
23
|
+
|
|
24
|
+
## What to Tell Your User
|
|
25
|
+
|
|
26
|
+
Nothing changes on any normal agent — this ships off by default, and the file that
|
|
27
|
+
triggers a sleep is only ever written when sleep is explicitly turned on. The future
|
|
28
|
+
ability it builds toward: a completely idle agent quiets its server to save your
|
|
29
|
+
machine, then wakes the moment you message it, holding your message until it is back
|
|
30
|
+
up. Turning it on is a deliberate step we would validate on one test agent first.
|
|
31
|
+
|
|
32
|
+
## Summary of New Capabilities
|
|
33
|
+
|
|
34
|
+
- ServerSupervisor honors a sleep-request by stopping the server and entering an
|
|
35
|
+
intentionally-asleep state that suppresses auto-respawn; honors a wake-request by
|
|
36
|
+
respawning. A slept-marker keeps a rebooted (or watchdog-bounced) supervisor asleep.
|
|
37
|
+
- The decision layer writes a TTL-stamped sleep-request only in live mode.
|
|
38
|
+
- The lifeline writes a wake-request on the next inbound message when the server is
|
|
39
|
+
asleep; the existing forward-retry queue replays the held message after wake.
|
|
40
|
+
- All gated by the existing monitoring.agentSleep config — OFF + dry-run by default.
|
|
41
|
+
|
|
42
|
+
## Evidence
|
|
43
|
+
|
|
44
|
+
- `tests/unit/ServerSupervisor-sleep-wake.test.ts` — sleep stops + marks + enters
|
|
45
|
+
slept; no-request no-op; expired-request ignored; wake respawns + clears; wake-when-
|
|
46
|
+
not-slept no-op; idempotent re-sleep; boot-marker signal.
|
|
47
|
+
- `tests/unit/agentSleepWake.test.ts` — marker present writes the wake-request; no
|
|
48
|
+
marker is a no-op (steady-state awake never writes).
|
|
49
|
+
- `tests/unit/SleepController.test.ts` — sleepRequestWriter writes the TTL-stamped flag.
|
|
50
|
+
- Regression: the existing ServerSupervisor-handshake / supervisor-health-check /
|
|
51
|
+
supervisor-cpu-starvation suites stay green — the slept short-circuit is the only
|
|
52
|
+
loop-flow change and is a no-op until a live sleep-request is honored.
|
|
53
|
+
- Side-effects: `upgrades/side-effects/agent-hard-sleep-mechanism.md`.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Side-Effects Review — Agent hard-sleep stop+wake mechanism (Stage B, slice 2)
|
|
2
|
+
|
|
3
|
+
**Version / slug:** `agent-hard-sleep-mechanism`
|
|
4
|
+
**Date:** `2026-05-31`
|
|
5
|
+
**Author:** `echo`
|
|
6
|
+
**Second-pass reviewer:** `adversarial review performed — found a critical brick (wake-trigger gated on health) + a broken manual escape hatch; BOTH fixed + tested before commit. Concurs the dark code is inert. Enablement remains the reviewed gate (live on a test agent with Justin watching).`
|
|
7
|
+
|
|
8
|
+
## Summary of the change
|
|
9
|
+
|
|
10
|
+
Acts on the slice-1 SleepController verdict: in live mode it writes
|
|
11
|
+
`state/sleep-requested.json`; the ServerSupervisor honors it by stopping the server
|
|
12
|
+
tmux session and entering a `slept` state; the health loop then short-circuits
|
|
13
|
+
(suppressing auto-respawn) and only watches for `state/wake-requested.json`, which
|
|
14
|
+
the TelegramLifeline writes on the next inbound message → the supervisor respawns
|
|
15
|
+
the server and the existing forward-retry queue replays the buffered message. Files:
|
|
16
|
+
`SleepController.ts` (+`sleepRequestWriter`), `ServerSupervisor.ts`
|
|
17
|
+
(checkSleepRequest/checkWakeRequest/`slept` guard/boot-marker), `TelegramLifeline.ts`
|
|
18
|
+
(+`requestWakeIfSlept` via the pure `agentSleepWake.ts` helper). No new config (the
|
|
19
|
+
slice-1 `monitoring.agentSleep` gates it), no new route, no agent-installed file.
|
|
20
|
+
|
|
21
|
+
## Decision-point inventory
|
|
22
|
+
|
|
23
|
+
- `ServerSupervisor` health-loop control flow — modify — adds ONE short-circuit: `if (slept) { checkWakeRequest(); return; }` at the loop top.
|
|
24
|
+
- `ServerSupervisor.checkSleepRequest` / `checkWakeRequest` — add — the stop/respawn handlers (mirror checkRestartRequest).
|
|
25
|
+
- `ServerSupervisor` boot — modify — reads `slept-marker.json` to stay asleep across a supervisor reboot.
|
|
26
|
+
- `SleepController.requestSleep` consumer — add — `sleepRequestWriter` (live-mode only).
|
|
27
|
+
- `TelegramLifeline.forwardToServer` — pass-through — prepends a non-blocking `requestWakeIfSlept()` side-call.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 1. Over-block
|
|
32
|
+
|
|
33
|
+
No block/allow surface over messages. The only "blocking-like" behavior is the
|
|
34
|
+
`slept` short-circuit suppressing auto-respawn — which is exactly intended and gated
|
|
35
|
+
on `slept`, set only after a live sleep-request is honored. A genuine crash (slept
|
|
36
|
+
=== false) still flows through the unchanged `evaluateUnhealthyServer` path.
|
|
37
|
+
|
|
38
|
+
## 2. Under-block
|
|
39
|
+
|
|
40
|
+
Could the server fail to wake (the brick risk)? **The adversarial second-pass review
|
|
41
|
+
caught a real brick in the first cut and it was fixed:** the wake-trigger was
|
|
42
|
+
originally placed inside `forwardToServer()`, which is gated on `supervisor.healthy`
|
|
43
|
+
— but a slept server is not healthy, so an inbound message took the "server down →
|
|
44
|
+
queue" path and never wrote `wake-requested.json` → the server would never wake.
|
|
45
|
+
**Fix:** `requestWakeIfSlept()` now runs at the TOP of `processUpdate()`, before any
|
|
46
|
+
health gate, so EVERY inbound update writes the wake flag when slept (covered by the
|
|
47
|
+
helper test + the corrected call-site). The review also caught that `/lifeline
|
|
48
|
+
restart` (the manual escape hatch) didn't clear the slept-marker, so a manual restart
|
|
49
|
+
re-read the marker and re-slept — **fixed** via `ServerSupervisor.wakeFromSleep()`,
|
|
50
|
+
called from both `/lifeline restart` and `/lifeline reset` (tested).
|
|
51
|
+
|
|
52
|
+
Remaining wake robustness: the supervisor checks the wake flag every 10s while slept;
|
|
53
|
+
a single missed flag write self-heals on the next inbound; a fleet-watchdog mid-sleep
|
|
54
|
+
bounce stays asleep via the boot-marker AND wakes on the next inbound. The
|
|
55
|
+
scheduler-wake (a cron job due during sleep) is the one tracked gap (conservative-null
|
|
56
|
+
for now), enablement-gated — dark default means no real agent is affected.
|
|
57
|
+
|
|
58
|
+
## 3. Level-of-abstraction fit
|
|
59
|
+
|
|
60
|
+
Correct. The mechanism reuses the proven `restart-requested.json` lifecycle shape
|
|
61
|
+
(file flag consumed in the health loop) rather than inventing a new lifecycle; the
|
|
62
|
+
stop is the existing tmux `kill-session`, the wake is the existing `spawnServer()`.
|
|
63
|
+
The lifeline wake-trigger is extracted into a pure, unit-tested helper
|
|
64
|
+
(`writeWakeRequestIfSlept`) rather than buried in the un-testable heavy class.
|
|
65
|
+
|
|
66
|
+
## 4. Signal vs authority compliance
|
|
67
|
+
|
|
68
|
+
**Required reference:** [docs/signal-vs-authority.md](../../docs/signal-vs-authority.md)
|
|
69
|
+
|
|
70
|
+
- [x] No — the SleepController remains the decision-maker (signal, with all guards);
|
|
71
|
+
this slice is the mechanism it drives. The stop IS an authority (stops a process),
|
|
72
|
+
but it is gated exactly like a planned restart: positive proof (the slice-1
|
|
73
|
+
would-sleep verdict with every guard), ships OFF + dry-run, never fires unless
|
|
74
|
+
enabled && !dryRun, and KEEPs-awake on any ambiguity upstream.
|
|
75
|
+
|
|
76
|
+
## 5. Interactions
|
|
77
|
+
|
|
78
|
+
- **Shadowing:** the `slept` short-circuit runs before the health/restart logic; it
|
|
79
|
+
is a no-op when `slept===false` (always, until a live sleep-request lands), so it
|
|
80
|
+
cannot shadow the existing restart/health paths in normal operation. Verified by
|
|
81
|
+
the unchanged `ServerSupervisor-handshake` + `supervisor-health-check` suites.
|
|
82
|
+
- **Double-fire:** sleep is idempotent (`checkSleepRequest` early-returns when
|
|
83
|
+
already slept); wake is idempotent (early-returns when not slept). The
|
|
84
|
+
`sleep-requested`/`wake-requested` flags are consumed on read.
|
|
85
|
+
- **Races:** the fleet watchdog vs sleep — resolved by the boot-marker (reboot stays
|
|
86
|
+
asleep). The lifeline writing a wake flag while the supervisor is mid-respawn —
|
|
87
|
+
harmless (the supervisor clears `slept` first, so a redundant wake flag is consumed
|
|
88
|
+
next tick as a no-op).
|
|
89
|
+
- **Feedback loops:** none — the flags are one-shot, consumed by the consumer.
|
|
90
|
+
|
|
91
|
+
## 6. External surfaces
|
|
92
|
+
|
|
93
|
+
- **Install base:** pure additive source, no config/route/agent-installed-file
|
|
94
|
+
change → every agent picks it up on update; behavior is byte-identical until
|
|
95
|
+
`monitoring.agentSleep` is enabled live. The slice-1 dark default holds.
|
|
96
|
+
- **Other agents / external systems:** none.
|
|
97
|
+
- **Persistent state:** three transient `state/*.json` flags + one `slept-marker.json`
|
|
98
|
+
(best-effort, consumed/removed by the supervisor).
|
|
99
|
+
- **Timing:** the existing 10s health tick; no new timer.
|
|
100
|
+
|
|
101
|
+
## 7. Rollback cost
|
|
102
|
+
|
|
103
|
+
Pure additive code, no config/migration. Revert → `checkSleepRequest` /
|
|
104
|
+
`checkWakeRequest` / the `slept` guard / the lifeline side-call disappear; the
|
|
105
|
+
supervisor + lifeline behave exactly as before. No persistent state needs cleanup
|
|
106
|
+
(the flags are transient). No user-visible change during rollback (dark by default).
|
|
107
|
+
|
|
108
|
+
## Conclusion
|
|
109
|
+
|
|
110
|
+
This review confirmed the mechanism is a tightly-scoped, additive layer on the
|
|
111
|
+
proven restart lifecycle, with ONE load-bearing change (the `slept` short-circuit)
|
|
112
|
+
that is a no-op until a live sleep-request is honored and is regression-covered by
|
|
113
|
+
the existing supervisor suites. The brick risk is closed at multiple layers
|
|
114
|
+
(per-forward wake re-write, 10s wake poll, boot-stay-asleep marker). It ships dark;
|
|
115
|
+
the enablement (turning sleep ON) is the reviewed validation step on a test agent.
|