instar 1.1.1 → 1.1.2
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 +7 -1
- package/dist/commands/server.js.map +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +19 -24
- package/dist/commands/setup.js.map +1 -1
- package/dist/core/PostUpdateMigrator.d.ts +1 -0
- package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
- package/dist/core/PostUpdateMigrator.js +69 -0
- package/dist/core/PostUpdateMigrator.js.map +1 -1
- package/dist/lifeline/TelegramLifeline.d.ts.map +1 -1
- package/dist/lifeline/TelegramLifeline.js +21 -0
- package/dist/lifeline/TelegramLifeline.js.map +1 -1
- package/dist/threadline/WakeSocketServer.d.ts +16 -0
- package/dist/threadline/WakeSocketServer.d.ts.map +1 -1
- package/dist/threadline/WakeSocketServer.js +100 -6
- package/dist/threadline/WakeSocketServer.js.map +1 -1
- package/package.json +1 -1
- package/src/data/builtin-manifest.json +18 -18
- package/upgrades/1.1.2.md +130 -0
- package/upgrades/side-effects/boot-wrapper-plist-coherence.md +176 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./builtin-manifest.schema.json",
|
|
3
3
|
"schemaVersion": 1,
|
|
4
|
-
"generatedAt": "2026-05-
|
|
5
|
-
"instarVersion": "1.1.
|
|
4
|
+
"generatedAt": "2026-05-20T22:26:32.053Z",
|
|
5
|
+
"instarVersion": "1.1.2",
|
|
6
6
|
"entryCount": 190,
|
|
7
7
|
"entries": {
|
|
8
8
|
"hook:session-start": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"domain": "identity",
|
|
12
12
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
13
13
|
"installedPath": ".instar/hooks/instar/session-start.sh",
|
|
14
|
-
"contentHash": "
|
|
14
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
15
15
|
"since": "2025-01-01"
|
|
16
16
|
},
|
|
17
17
|
"hook:dangerous-command-guard": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"domain": "safety",
|
|
21
21
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
22
22
|
"installedPath": ".instar/hooks/instar/dangerous-command-guard.sh",
|
|
23
|
-
"contentHash": "
|
|
23
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
24
24
|
"since": "2025-01-01"
|
|
25
25
|
},
|
|
26
26
|
"hook:grounding-before-messaging": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"domain": "safety",
|
|
30
30
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
31
31
|
"installedPath": ".instar/hooks/instar/grounding-before-messaging.sh",
|
|
32
|
-
"contentHash": "
|
|
32
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
33
33
|
"since": "2025-01-01"
|
|
34
34
|
},
|
|
35
35
|
"hook:compaction-recovery": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"domain": "identity",
|
|
39
39
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
40
40
|
"installedPath": ".instar/hooks/instar/compaction-recovery.sh",
|
|
41
|
-
"contentHash": "
|
|
41
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
42
42
|
"since": "2025-01-01"
|
|
43
43
|
},
|
|
44
44
|
"hook:external-operation-gate": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"domain": "safety",
|
|
48
48
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
49
49
|
"installedPath": ".instar/hooks/instar/external-operation-gate.js",
|
|
50
|
-
"contentHash": "
|
|
50
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
51
51
|
"since": "2025-01-01"
|
|
52
52
|
},
|
|
53
53
|
"hook:deferral-detector": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"domain": "safety",
|
|
57
57
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
58
58
|
"installedPath": ".instar/hooks/instar/deferral-detector.js",
|
|
59
|
-
"contentHash": "
|
|
59
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
60
60
|
"since": "2025-01-01"
|
|
61
61
|
},
|
|
62
62
|
"hook:post-action-reflection": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"domain": "evolution",
|
|
66
66
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
67
67
|
"installedPath": ".instar/hooks/instar/post-action-reflection.js",
|
|
68
|
-
"contentHash": "
|
|
68
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
69
69
|
"since": "2025-01-01"
|
|
70
70
|
},
|
|
71
71
|
"hook:external-communication-guard": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"domain": "safety",
|
|
75
75
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
76
76
|
"installedPath": ".instar/hooks/instar/external-communication-guard.js",
|
|
77
|
-
"contentHash": "
|
|
77
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
78
78
|
"since": "2025-01-01"
|
|
79
79
|
},
|
|
80
80
|
"hook:scope-coherence-collector": {
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"domain": "coherence",
|
|
84
84
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
85
85
|
"installedPath": ".instar/hooks/instar/scope-coherence-collector.js",
|
|
86
|
-
"contentHash": "
|
|
86
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
87
87
|
"since": "2025-01-01"
|
|
88
88
|
},
|
|
89
89
|
"hook:scope-coherence-checkpoint": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"domain": "coherence",
|
|
93
93
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
94
94
|
"installedPath": ".instar/hooks/instar/scope-coherence-checkpoint.js",
|
|
95
|
-
"contentHash": "
|
|
95
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
96
96
|
"since": "2025-01-01"
|
|
97
97
|
},
|
|
98
98
|
"hook:free-text-guard": {
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"domain": "safety",
|
|
102
102
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
103
103
|
"installedPath": ".instar/hooks/instar/free-text-guard.sh",
|
|
104
|
-
"contentHash": "
|
|
104
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
105
105
|
"since": "2025-01-01"
|
|
106
106
|
},
|
|
107
107
|
"hook:claim-intercept": {
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"domain": "coherence",
|
|
111
111
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
112
112
|
"installedPath": ".instar/hooks/instar/claim-intercept.js",
|
|
113
|
-
"contentHash": "
|
|
113
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
114
114
|
"since": "2025-01-01"
|
|
115
115
|
},
|
|
116
116
|
"hook:claim-intercept-response": {
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"domain": "coherence",
|
|
120
120
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
121
121
|
"installedPath": ".instar/hooks/instar/claim-intercept-response.js",
|
|
122
|
-
"contentHash": "
|
|
122
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
123
123
|
"since": "2025-01-01"
|
|
124
124
|
},
|
|
125
125
|
"hook:auto-approve-permissions": {
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"domain": "safety",
|
|
129
129
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
130
130
|
"installedPath": ".instar/hooks/instar/auto-approve-permissions.js",
|
|
131
|
-
"contentHash": "
|
|
131
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
132
132
|
"since": "2025-01-01"
|
|
133
133
|
},
|
|
134
134
|
"job:health-check": {
|
|
@@ -1464,7 +1464,7 @@
|
|
|
1464
1464
|
"type": "subsystem",
|
|
1465
1465
|
"domain": "updates",
|
|
1466
1466
|
"sourcePath": "src/core/PostUpdateMigrator.ts",
|
|
1467
|
-
"contentHash": "
|
|
1467
|
+
"contentHash": "808fbff652a75bc43ece5a00aa1f6d2ab1753d085c7ca75b3b3db6cea63a39ee",
|
|
1468
1468
|
"since": "2025-01-01"
|
|
1469
1469
|
},
|
|
1470
1470
|
"subsystem:scheduler": {
|
|
@@ -1496,7 +1496,7 @@
|
|
|
1496
1496
|
"type": "subsystem",
|
|
1497
1497
|
"domain": "communication",
|
|
1498
1498
|
"sourcePath": "src/lifeline/TelegramLifeline.ts",
|
|
1499
|
-
"contentHash": "
|
|
1499
|
+
"contentHash": "ad363d58349530646209a1ee6b97e0039449c70c6cf61c87d3c590c9e39d25e4",
|
|
1500
1500
|
"since": "2025-01-01"
|
|
1501
1501
|
},
|
|
1502
1502
|
"subsystem:orphan-process-reaper": {
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Upgrade Guide — vNEXT
|
|
2
|
+
|
|
3
|
+
<!-- bump: patch -->
|
|
4
|
+
<!-- patch = bug fixes, refactors, test additions, doc updates -->
|
|
5
|
+
|
|
6
|
+
## What Changed
|
|
7
|
+
|
|
8
|
+
**fix(boot-wrapper): plist↔wrapper extension drift no longer takes agents dark.**
|
|
9
|
+
|
|
10
|
+
Three intertwined boot-time changes that together close a "agent goes
|
|
11
|
+
silently dark and won't come back" failure mode observed in the field
|
|
12
|
+
(Echo, 2026-05-20):
|
|
13
|
+
|
|
14
|
+
1. **`installBootWrapper()` always writes `instar-boot.cjs`** (not `.js`),
|
|
15
|
+
regardless of the project's `package.json` `"type"` field. `.cjs`
|
|
16
|
+
forces CommonJS semantics in Node, so the wrapper's `require()` calls
|
|
17
|
+
work in both type=module and type=commonjs projects. Previously the
|
|
18
|
+
function picked an extension based on `package.json` AND deleted the
|
|
19
|
+
alt extension — so if a project gained `"type": "module"` after the
|
|
20
|
+
plist was generated (e.g., via a package upgrade), the next call to
|
|
21
|
+
`installBootWrapper` deleted the `.js` file the plist still pointed
|
|
22
|
+
at. launchd then exec'd a nonexistent file on every restart and none
|
|
23
|
+
of the downstream self-heal (`ServerSupervisor.preflightSelfHeal`,
|
|
24
|
+
`NativeModuleHealer`, `INSTAR_SUPERVISED` detection) ever ran because
|
|
25
|
+
the boot wrapper itself never loaded.
|
|
26
|
+
|
|
27
|
+
2. **`TelegramLifeline.selfHealPlist` adds a wrapper-existence check.**
|
|
28
|
+
The existing three checks all passed when the plist referenced
|
|
29
|
+
`instar-boot.js` but the file was deleted (the plist content still
|
|
30
|
+
matched the legacy-detection patterns). A fourth check now extracts
|
|
31
|
+
the wrapper path from `ProgramArguments` and verifies the file
|
|
32
|
+
exists on disk; if not, the plist is regenerated immediately.
|
|
33
|
+
Defense-in-depth — the always-.cjs change above eliminates the
|
|
34
|
+
creation of this state going forward, but this check rescues any
|
|
35
|
+
already-existing drift before the next launchd restart hits the
|
|
36
|
+
bad path.
|
|
37
|
+
|
|
38
|
+
3. **`WakeSocketServer.start()` recovers from EADDRINUSE.** The
|
|
39
|
+
pre-existing unlink-before-bind pass handled the common
|
|
40
|
+
"stale socket file from unclean exit" case but silently swallowed
|
|
41
|
+
unlink errors and offered no fallback if `listen()` itself fired
|
|
42
|
+
EADDRINUSE. On EADDRINUSE the server now probes the socket: if a
|
|
43
|
+
live peer answers, surface the error normally (don't clobber a real
|
|
44
|
+
second instance); if nothing answers, force-unlink and retry listen
|
|
45
|
+
once. Bounded retry — single attempt, no churn.
|
|
46
|
+
|
|
47
|
+
4. **`PostUpdateMigrator.migrateBootWrapperToCjs`** — closes the gap
|
|
48
|
+
for in-the-wild agents whose launchd plists were generated before
|
|
49
|
+
this change with `instar-boot.js` in `ProgramArguments`. On darwin,
|
|
50
|
+
if the plist exists and references `instar-boot.js`, the migration
|
|
51
|
+
regenerates via `installAutoStart` so the plist now points at
|
|
52
|
+
`instar-boot.cjs`. Idempotent — re-runs that find a `.cjs`-referencing
|
|
53
|
+
plist are silent no-ops. The migration does NOT delete the legacy
|
|
54
|
+
`.js` file; rollback safety wins over file cleanup.
|
|
55
|
+
|
|
56
|
+
Files touched (excluding tests / docs / upgrade notes):
|
|
57
|
+
- `src/commands/setup.ts` — `installBootWrapper`, `ensureBootWrapper`
|
|
58
|
+
- `src/commands/server.ts` — auto-start plist sanity check accepts `.cjs`
|
|
59
|
+
- `src/lifeline/TelegramLifeline.ts` — selfHealPlist 4th check
|
|
60
|
+
- `src/threadline/WakeSocketServer.ts` — EADDRINUSE recovery
|
|
61
|
+
- `src/core/PostUpdateMigrator.ts` — `migrateBootWrapperToCjs`
|
|
62
|
+
|
|
63
|
+
## Evidence
|
|
64
|
+
|
|
65
|
+
**Repro of the original failure** (Echo, 2026-05-20, 10:25 PT):
|
|
66
|
+
|
|
67
|
+
1. Echo's `package.json` has `"type": "module"` (instar's own package
|
|
68
|
+
has had this since v1.0.0).
|
|
69
|
+
2. Earlier `installBootWrapper` calls picked `.cjs`, deleted `.js`, and
|
|
70
|
+
the plist was generated at that point referencing `.cjs`.
|
|
71
|
+
3. A subsequent code path (`installBootWrapper` running while the boot
|
|
72
|
+
was actively crashing for a different reason — Node major-version
|
|
73
|
+
ABI break, since rolled back) wrote `.cjs` AGAIN and deleted any
|
|
74
|
+
`.js` that had been re-created by an even-older code path.
|
|
75
|
+
4. The plist on disk still referenced `.cjs`, but ALSO any plist that
|
|
76
|
+
had been generated when echo's `package.json` was missing the
|
|
77
|
+
`type: module` declaration referenced `.js` — and the `.js` file
|
|
78
|
+
was gone.
|
|
79
|
+
5. launchd's next restart exec'd the nonexistent path → process never
|
|
80
|
+
started → all downstream self-heal (`NativeModuleHealer.healBetterSqlite3`,
|
|
81
|
+
`ServerSupervisor.preflightSelfHeal`, bind-failure escalation)
|
|
82
|
+
silently never ran.
|
|
83
|
+
6. Operator intervention (Dawn, manual plist edit) was required to
|
|
84
|
+
restore the agent.
|
|
85
|
+
|
|
86
|
+
**Observed before:** `git log` shows multiple in-the-wild reports of
|
|
87
|
+
launchd plists pointing at a deleted `instar-boot.js` after a project
|
|
88
|
+
gained `"type": "module"`. The selfHealPlist check at
|
|
89
|
+
`src/lifeline/TelegramLifeline.ts:2076` reads `content.includes('instar-boot.js')`,
|
|
90
|
+
which returns `true` even after the file is deleted — so the existing
|
|
91
|
+
checks all pass and no regen fires.
|
|
92
|
+
|
|
93
|
+
**Observed after:**
|
|
94
|
+
- New test `tests/unit/boot-wrapper-plist-coherence.test.ts` exercises
|
|
95
|
+
`installBootWrapper` with package.json `type: module`, type: commonjs,
|
|
96
|
+
and no package.json — all three write `instar-boot.cjs`. A test
|
|
97
|
+
explicitly plants a pre-existing `instar-boot.js` and verifies it is
|
|
98
|
+
NOT deleted by the new code path (rollback safety).
|
|
99
|
+
- New test `tests/unit/PostUpdateMigrator-bootWrapperCjs.test.ts`
|
|
100
|
+
exercises the four migration branches (non-darwin skip, no plist
|
|
101
|
+
skip, already-.cjs idempotent skip, and the `.js → .cjs` detection +
|
|
102
|
+
regeneration path).
|
|
103
|
+
- New test `tests/unit/wake-socket-server-stale-recovery.test.ts`
|
|
104
|
+
exercises the stale-socket cleanup path and asserts that a live peer
|
|
105
|
+
is NOT clobbered (the recovery surfaces EADDRINUSE in that case).
|
|
106
|
+
- Existing test suites unchanged; `installBootWrapper` callers in
|
|
107
|
+
`installMacOSLaunchAgent` and `TelegramLifeline.selfHealPlist`
|
|
108
|
+
receive the new `.cjs` path through the unchanged `wrappers.js`
|
|
109
|
+
return field so no callsite needs adjustment.
|
|
110
|
+
|
|
111
|
+
## What to Tell Your User
|
|
112
|
+
|
|
113
|
+
- **Your agent stays online through package upgrades**: if I had an
|
|
114
|
+
internal package configuration change, my launchd entry point used
|
|
115
|
+
to risk getting renamed out from under itself. That whole class of
|
|
116
|
+
failure is closed off now — the boot file has a stable name that
|
|
117
|
+
works regardless of internal toggles.
|
|
118
|
+
- **Stale socket files don't lock me out anymore**: if I exited
|
|
119
|
+
uncleanly and a leftover socket file blocked the next start, I now
|
|
120
|
+
detect that and clean it up safely, only after first checking that
|
|
121
|
+
nothing else is actually using it.
|
|
122
|
+
|
|
123
|
+
## Summary of New Capabilities
|
|
124
|
+
|
|
125
|
+
| Capability | How to Use |
|
|
126
|
+
|-----------|-----------|
|
|
127
|
+
| Plist↔wrapper coherence guarantee | automatic (no action required) |
|
|
128
|
+
| selfHealPlist verifies wrapper-path-on-disk | automatic (runs in lifeline boot) |
|
|
129
|
+
| WakeSocketServer EADDRINUSE recovery | automatic (runs in listener startup) |
|
|
130
|
+
| PostUpdateMigrator regenerates `.js`-plists | automatic on next instar update |
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Side-Effects Review — Boot-Wrapper / Plist Coherence
|
|
2
|
+
|
|
3
|
+
**Version / slug:** `boot-wrapper-plist-coherence`
|
|
4
|
+
**Date:** `2026-05-20`
|
|
5
|
+
**Author:** Echo (instar developer agent)
|
|
6
|
+
**Trigger:** Field failure 2026-05-20, ~10:25 PT: instar agent "echo"
|
|
7
|
+
went dark, required operator intervention (Dawn — manual plist edit) to
|
|
8
|
+
recover. Root cause: launchd plist's `ProgramArguments` referenced
|
|
9
|
+
`instar-boot.js` but that file had been deleted by `installBootWrapper`
|
|
10
|
+
because `package.json` had gained `"type": "module"`.
|
|
11
|
+
|
|
12
|
+
## Summary of the change
|
|
13
|
+
|
|
14
|
+
Four interlocking edits that together eliminate the plist↔wrapper
|
|
15
|
+
extension-drift failure class:
|
|
16
|
+
|
|
17
|
+
1. **`installBootWrapper()` always writes `.cjs`.** No more reading
|
|
18
|
+
`package.json "type"` and switching extensions. No more deleting the
|
|
19
|
+
alt extension.
|
|
20
|
+
2. **`ensureBootWrapper()` looks for `.cjs`.** The presence check used
|
|
21
|
+
to look for the type-dependent extension; now it always looks for
|
|
22
|
+
`.cjs`.
|
|
23
|
+
3. **`TelegramLifeline.selfHealPlist` adds Check 4:** verify the wrapper
|
|
24
|
+
path referenced by the plist's `ProgramArguments` exists on disk. If
|
|
25
|
+
not, regenerate via `installAutoStart`. Defense-in-depth for any
|
|
26
|
+
already-drifted state.
|
|
27
|
+
4. **`PostUpdateMigrator.migrateBootWrapperToCjs`** detects existing
|
|
28
|
+
`.js`-referencing plists and regenerates them to point at `.cjs` via
|
|
29
|
+
`installAutoStart`. Idempotent.
|
|
30
|
+
5. **`WakeSocketServer.start()`** uses a probe-before-clobber pattern.
|
|
31
|
+
Previously: pre-bind unconditional `unlink`. New: listen first; on
|
|
32
|
+
EADDRINUSE, probe-connect to determine if the socket is live or
|
|
33
|
+
stale; only unlink+retry if confirmed stale. Prevents silently
|
|
34
|
+
stealing a path from a live peer.
|
|
35
|
+
|
|
36
|
+
## Decision matrix
|
|
37
|
+
|
|
38
|
+
### Over-block
|
|
39
|
+
|
|
40
|
+
| Scenario | Outcome |
|
|
41
|
+
|----------|---------|
|
|
42
|
+
| Project has package.json `"type": "module"` | Always-`.cjs` is correct (no behavioral change vs. pre-existing `.cjs`-write path) |
|
|
43
|
+
| Project has no package.json | Always-`.cjs` works (Node treats `.cjs` as CommonJS regardless of parent context) |
|
|
44
|
+
| Project has package.json `"type": "commonjs"` | Always-`.cjs` works (CommonJS is the explicit context) |
|
|
45
|
+
| Existing `.js` wrapper on disk | NOT touched (rollback-safe — old plists referencing `.js` keep working until migrator runs) |
|
|
46
|
+
| Existing `.cjs` wrapper on disk | Overwritten with current content (preserves existing behavior) |
|
|
47
|
+
|
|
48
|
+
No over-block. The `.cjs` extension is strictly broader than the previous `.js`+`.cjs` split.
|
|
49
|
+
|
|
50
|
+
### Under-block
|
|
51
|
+
|
|
52
|
+
| Scenario | Outcome |
|
|
53
|
+
|----------|---------|
|
|
54
|
+
| Plist references `.js`, no `.js` file on disk, no `.cjs` file on disk | Migrator regenerates; selfHealPlist Check 4 catches |
|
|
55
|
+
| Plist references `.cjs`, `.cjs` file deleted | selfHealPlist Check 4 catches (regenerates) |
|
|
56
|
+
| Plist references `.js`, `.js` file present, `.cjs` file present | Migrator regenerates plist to `.cjs` (idempotent on re-run) |
|
|
57
|
+
| Plist references `.js`, `.js` file present, `.cjs` file missing | Migrator regenerates plist (writes `.cjs` + updates plist) |
|
|
58
|
+
|
|
59
|
+
No under-block.
|
|
60
|
+
|
|
61
|
+
### Level of abstraction fit
|
|
62
|
+
|
|
63
|
+
- The fix lives at the WRAPPER GENERATION + WRAPPER VERIFICATION layer,
|
|
64
|
+
which is the same layer where the bug originated. Not pushed up into
|
|
65
|
+
the Remediator (out of scope for this PR — Remediator is still under
|
|
66
|
+
Tier 2 rollout per the v3 spec) and not pushed down into launchd (no
|
|
67
|
+
way to influence launchd's interpretation of the plist).
|
|
68
|
+
- `installBootWrapper`'s contract is unchanged from a caller's
|
|
69
|
+
perspective: it still returns `{ sh, js }`. The `js` field name is now
|
|
70
|
+
a slight misnomer (the file is `.cjs`) but every existing caller uses
|
|
71
|
+
it as an opaque path string, so no callsite changes.
|
|
72
|
+
|
|
73
|
+
### Signal-vs-authority compliance
|
|
74
|
+
|
|
75
|
+
| Component | Signal or Authority | Reason |
|
|
76
|
+
|-----------|--------------------|--------|
|
|
77
|
+
| `installBootWrapper` always-`.cjs` | Authority (writes files) | Deterministic, content-based decision. No judgment call. |
|
|
78
|
+
| `ensureBootWrapper` `.cjs` lookup | Signal (returns boolean) | Caller decides what to do with "wrappers missing". |
|
|
79
|
+
| `selfHealPlist` Check 4 | Authority (writes files via installAutoStart) | Existence check is deterministic. The regeneration is a documented recovery primitive. |
|
|
80
|
+
| `migrateBootWrapperToCjs` | Authority (writes files via installAutoStart) | Detection is structural (plist content matches regex). Regeneration is the same primitive other migrations use. |
|
|
81
|
+
| `WakeSocketServer` probe-then-recover | Signal-and-Authority hybrid | Probe is a signal (connect-or-not); the unlink+retry is bounded recovery (single retry, hard timeout). |
|
|
82
|
+
|
|
83
|
+
Compliant. The new authorities are bounded recovery primitives, not
|
|
84
|
+
judgmental gates. The new signals are deterministic structural checks.
|
|
85
|
+
|
|
86
|
+
### Interactions with adjacent systems
|
|
87
|
+
|
|
88
|
+
| System | Interaction | Risk |
|
|
89
|
+
|--------|-------------|------|
|
|
90
|
+
| `NativeModuleHealer` | None direct. NativeModuleHealer fires after boot wrapper loads; this fix ensures the boot wrapper CAN load. | Strictly improves NativeModuleHealer's blast radius. |
|
|
91
|
+
| `ServerSupervisor.preflightSelfHeal` | None direct. Preflight runs after boot wrapper spawns the lifeline. | Same — strictly improves preflight's coverage. |
|
|
92
|
+
| `detectLaunchdSupervised` | None. Runs inside the lifeline; the fix is upstream. | None. |
|
|
93
|
+
| `INSTAR_SUPERVISED` plist env | Compatible — `installMacOSLaunchAgent` regenerates the full plist including this env var. | None. |
|
|
94
|
+
| `RestartOrchestrator` | Same as above — fix is upstream. | None. |
|
|
95
|
+
| `DegradationReporter` | None direct. Migrator failures land in `result.errors[]` which feed the migration report, not Degradation. Acceptable: migrator runs in a known supervised window, not in production hot paths. | None. |
|
|
96
|
+
| `WakeSocketServer` listener daemon usage | The probe-before-clobber change only fires on EADDRINUSE. Normal startup path (no stale file) is unchanged. | Tested with planted-stale-file + live-peer scenarios. |
|
|
97
|
+
| Existing `.js`-wrapper-using agents | Continue to work — `.js` file is NOT deleted; old plists still load; migrator regenerates plist on next update. | Backward compatible by design. |
|
|
98
|
+
| Tests that simulate `instar-boot.js` (e2e/launchd-*) | These tests generate their OWN `.js` wrappers and do NOT go through `installBootWrapper`. Unchanged. | None — verified by reading the test files. |
|
|
99
|
+
|
|
100
|
+
### Rollback cost
|
|
101
|
+
|
|
102
|
+
- Pure code change. Revert is one git revert per affected file.
|
|
103
|
+
- No persistent state changes that block rollback. The migrator runs
|
|
104
|
+
forward-only; rolling back leaves agents on `.cjs` plists (which work
|
|
105
|
+
fine) — the old `.js` files are still around if needed.
|
|
106
|
+
- `WakeSocketServer` change: revert restores pre-bind-unlink behavior.
|
|
107
|
+
The live-peer-clobber behavior re-emerges but is rare in practice
|
|
108
|
+
(single-tenant agents on a machine).
|
|
109
|
+
- Migrator runs idempotently — rolling back and re-deploying produces
|
|
110
|
+
the same end state.
|
|
111
|
+
|
|
112
|
+
## Acceptance criteria
|
|
113
|
+
|
|
114
|
+
1. **Repro of the Echo failure mode.**
|
|
115
|
+
- Test: `tests/unit/boot-wrapper-plist-coherence.test.ts > installBootWrapper — always writes .cjs > does NOT delete a pre-existing instar-boot.js (rollback safety)`
|
|
116
|
+
- Plants a pre-existing `instar-boot.js`, runs `installBootWrapper` with `package.json type=module`. Asserts the `.js` file still exists. Pre-change behavior: file deleted. Post-change: file preserved.
|
|
117
|
+
|
|
118
|
+
2. **selfHealPlist catches drift.**
|
|
119
|
+
- Implicit in `TelegramLifeline.ts` source: `Check 4` extracts the wrapper path from `ProgramArguments` and verifies `fs.existsSync`. Covered by `Check 4` logic.
|
|
120
|
+
|
|
121
|
+
3. **Migrator handles existing `.js`-referencing plists.**
|
|
122
|
+
- Test: `tests/unit/PostUpdateMigrator-bootWrapperCjs.test.ts > detects a plist that references instar-boot.js and attempts regeneration`
|
|
123
|
+
- Plants a plist referencing `instar-boot.js`. Runs the migrator. Asserts the migrator either succeeds (`upgraded`) or surfaces an error (`errors`) — both prove the detection-and-attempt path ran.
|
|
124
|
+
|
|
125
|
+
4. **WakeSocketServer does NOT clobber live peers.**
|
|
126
|
+
- Test: `tests/unit/wake-socket-server-stale-recovery.test.ts > refuses to clobber a live peer (surfaces EADDRINUSE)`
|
|
127
|
+
- Binds a real `net.Server` to the socket path, then attempts to start a second `WakeSocketServer`. Asserts the second emits EADDRINUSE without taking the path away from the live peer.
|
|
128
|
+
|
|
129
|
+
5. **WakeSocketServer recovers from stale socket.**
|
|
130
|
+
- Test: `tests/unit/wake-socket-server-stale-recovery.test.ts > cleans up a stale socket file on start (pre-bind unlink path)` and `> recovers from EADDRINUSE when no live peer is listening`
|
|
131
|
+
- Plants an empty file at the socket path, starts the server, asserts the listen succeeds.
|
|
132
|
+
|
|
133
|
+
## Notes for second-pass reviewer
|
|
134
|
+
|
|
135
|
+
- **Why always `.cjs` and not "always write both `.js` and `.cjs`?":**
|
|
136
|
+
Considered. Always-both would allow rollback to point at `.js` if
|
|
137
|
+
needed. Rejected because: (1) `.js` in a `type=module` project is a
|
|
138
|
+
broken artifact (Node can't load it as CJS); (2) the migrator
|
|
139
|
+
regenerates plists to `.cjs` automatically, so rollback isn't a
|
|
140
|
+
user-visible scenario; (3) keeping an unused broken file invites
|
|
141
|
+
confusion. The current code leaves `.js` files alone but doesn't
|
|
142
|
+
create new ones.
|
|
143
|
+
|
|
144
|
+
- **Why not run the migrator on every lifeline boot instead of relying
|
|
145
|
+
on `PostUpdateMigrator`?** `selfHealPlist` already does the
|
|
146
|
+
equivalent on every lifeline boot — it's Check 4 of that function.
|
|
147
|
+
The migrator entry catches the case where the agent installs the new
|
|
148
|
+
instar version but hasn't yet booted the lifeline (e.g., the
|
|
149
|
+
postupdate migration runs first).
|
|
150
|
+
|
|
151
|
+
- **Why probe-then-unlink instead of just `listen()`-then-error-bubble
|
|
152
|
+
on EADDRINUSE?** Without the recovery path, a stale socket file from
|
|
153
|
+
an unclean exit blocks startup forever until the operator manually
|
|
154
|
+
removes it. The probe-then-unlink preserves correctness (don't
|
|
155
|
+
clobber live peers) while restoring the auto-recovery the original
|
|
156
|
+
pre-bind-unlink path provided.
|
|
157
|
+
|
|
158
|
+
- **Migrator side-effect on darwin only:** Linux systemd unit files
|
|
159
|
+
reference the bash wrapper (`instar-boot.sh`) which is unaffected
|
|
160
|
+
by this change. Non-darwin migrator path is a no-op skip.
|
|
161
|
+
|
|
162
|
+
## Rollback playbook
|
|
163
|
+
|
|
164
|
+
If this PR causes regressions:
|
|
165
|
+
|
|
166
|
+
1. `git revert <pr-merge-sha>` on the canonical instar repo's `main`.
|
|
167
|
+
2. Tag a patch release (e.g., `v1.1.2`) with the revert.
|
|
168
|
+
3. `npx instar` auto-update propagates the revert to all in-the-wild
|
|
169
|
+
agents on next supervision cycle.
|
|
170
|
+
4. Agents whose plists were already migrated to `.cjs` continue to
|
|
171
|
+
work — `installBootWrapper` post-revert writes `.cjs` for projects
|
|
172
|
+
with `type=module`, which matches what the migrated plists reference.
|
|
173
|
+
5. Agents whose plists were NOT yet migrated (still on `.js`)
|
|
174
|
+
continue on `.js` — unchanged from pre-PR state.
|
|
175
|
+
|
|
176
|
+
No persistent state cleanup required.
|