@geohar/pi-mcp-combiner 0.24.2 → 0.24.5
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/CHANGELOG.md +101 -0
- package/dist/client/footer.d.ts +10 -2
- package/dist/client/footer.d.ts.map +1 -1
- package/dist/client/footer.js +15 -6
- package/dist/client/footer.js.map +1 -1
- package/dist/combiner-process.d.ts +160 -0
- package/dist/combiner-process.d.ts.map +1 -0
- package/dist/combiner-process.js +721 -0
- package/dist/combiner-process.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +140 -306
- package/dist/index.js.map +1 -1
- package/dist/native/combiner-connection.d.ts +84 -0
- package/dist/native/combiner-connection.d.ts.map +1 -1
- package/dist/native/combiner-connection.js +194 -5
- package/dist/native/combiner-connection.js.map +1 -1
- package/dist/native/index.d.ts +32 -4
- package/dist/native/index.d.ts.map +1 -1
- package/dist/native/index.js +94 -6
- package/dist/native/index.js.map +1 -1
- package/dist/native/resources.d.ts +3 -0
- package/dist/native/resources.d.ts.map +1 -1
- package/dist/native/resources.js +6 -1
- package/dist/native/resources.js.map +1 -1
- package/dist/native/tool-surface.d.ts +31 -2
- package/dist/native/tool-surface.d.ts.map +1 -1
- package/dist/native/tool-surface.js +62 -18
- package/dist/native/tool-surface.js.map +1 -1
- package/dist/pi.d.ts +9 -1
- package/dist/pi.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/client/footer.ts +16 -4
- package/src/client/panel.ts +1 -1
- package/src/client/renderers.ts +2 -2
- package/src/combiner-process.ts +813 -0
- package/src/index.ts +142 -355
- package/src/native/combiner-connection.ts +220 -10
- package/src/native/index.ts +119 -18
- package/src/native/resources.ts +8 -1
- package/src/native/tool-surface.ts +80 -18
- package/src/pi.ts +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,107 @@ tagged `vX.Y.Z`. The extension runs the matching mcp-combiner release, so each
|
|
|
6
6
|
entry also summarises the combiner's changes; the full list is in
|
|
7
7
|
[the combiner's changelog](https://github.com/georgeharker/mcp-combiner/blob/main/combiner/CHANGELOG.md).
|
|
8
8
|
|
|
9
|
+
## [0.24.5] - 2026-11-21
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **No more typing freeze after startup.** pi rebuilds its whole tool registry
|
|
14
|
+
on every `registerTool`, and with codemode on that re-renders every tool's
|
|
15
|
+
declaration, so registering the combiner's ~1,000 tools in one go froze the
|
|
16
|
+
editor for 10 seconds or more. Tools (and removals of tools) now register in
|
|
17
|
+
batches of about 50 ms each, yielding to pi between them. A time budget
|
|
18
|
+
rather than a fixed count keeps the batches even, since each call gets
|
|
19
|
+
slower as the registry grows. Typing lag during registration is now about
|
|
20
|
+
55 ms (worst seen: 156 ms); all the tools arrive over about 10 s.
|
|
21
|
+
- A newer catalog (a `tools/list_changed` mid-registration) supersedes the
|
|
22
|
+
pass in progress at its next batch, and `/new`, `/resume`, `/fork` or
|
|
23
|
+
`/reload` stops it before pi retires the session's extension API.
|
|
24
|
+
- **Cold start no longer leaves the session without tools for 30 seconds.** The
|
|
25
|
+
first connect used to start before the combiner was attached, and
|
|
26
|
+
`sharedserver use` returns once the combiner is launched, not once it
|
|
27
|
+
listens. A refused connect then failed for good until the 30-second footer
|
|
28
|
+
refresh happened to reconnect. Connects now wait for the attach, and a
|
|
29
|
+
refused first connect is retried (100 ms backoff up to 1 s, for up to 15 s).
|
|
30
|
+
Once connected, a refused reconnect (a combiner restart) is retried for up
|
|
31
|
+
to 3 s. Between retries pi checks the combiner process itself (see below:
|
|
32
|
+
it respawns a dead one, or attaches to a new one). In a cold start test, the
|
|
33
|
+
tools arrived at 3.8 s instead of 31.5 s.
|
|
34
|
+
- **A prompt sent while tools are still arriving waits for them.** A turn that
|
|
35
|
+
started mid-registration, or while a combiner we just launched was still
|
|
36
|
+
coming up, saw only part of the catalog. Now the turn waits (up to 30 s)
|
|
37
|
+
until registration finishes. Waits longer than 250 ms show a notice (unless
|
|
38
|
+
`PI_MCP_COMBINER_NOTIFY=false`). The registration keeps yielding while it
|
|
39
|
+
waits, so the UI stays live. Esc, Ctrl+D or a double Ctrl+C end the wait at
|
|
40
|
+
once; `/quit` and signals wait for it to finish (pi gives extensions no abort
|
|
41
|
+
at this point). A combiner that is down and not ours to launch doesn't hold
|
|
42
|
+
up the turn.
|
|
43
|
+
- **The combiner process is managed in one place** (`combiner-process.ts`):
|
|
44
|
+
one attach function (`sharedserver use`) is the only way pi launches the
|
|
45
|
+
combiner or takes its reference. Every pi process holds its own reference.
|
|
46
|
+
- `use` runs once per pi process, unless the combiner changes. It used to run
|
|
47
|
+
again after every connect and every new session, re-running the combiner
|
|
48
|
+
version probes each time.
|
|
49
|
+
- When the combiner becomes a different process (someone else restarted
|
|
50
|
+
it, which drops every client's reference), pi attaches to the new one with
|
|
51
|
+
the same function, so it keeps its reference.
|
|
52
|
+
- When the combiner dies, pi notices within about 2 s (it watches the
|
|
53
|
+
process it holds a reference on), reconnects, and respawns it with the
|
|
54
|
+
same function. Several pi processes respawning at once is fine: sharedserver
|
|
55
|
+
launches one and the rest attach to it. Respawning is capped at 2 a minute:
|
|
56
|
+
a third death inside the minute stops respawning and reports it, with the
|
|
57
|
+
combiner's log files. A new pi session lifts the stop.
|
|
58
|
+
- If `sharedserver info` gives no answer (it normally answers in a few ms,
|
|
59
|
+
so that's a sharedserver problem and pi says so once), pi judges the
|
|
60
|
+
combiner by its own process check: gone means dead. pi never respawns a
|
|
61
|
+
combiner it never managed to attach to.
|
|
62
|
+
- **The connection keeps itself up**, for managed and host-owned combiners
|
|
63
|
+
alike: after a drop it reconnects on its own (500 ms, backing off to 30 s if
|
|
64
|
+
connections keep dropping right after connecting), and after a failed
|
|
65
|
+
connect it keeps retrying in the background (every 1 s, backing off to
|
|
66
|
+
10 s) instead of waiting for the next request. A combiner someone else
|
|
67
|
+
starts is picked up within seconds. A connect failure is reported once per
|
|
68
|
+
outage, and recovery is logged.
|
|
69
|
+
- `use` is retried when sharedserver reports the combiner as shutting down
|
|
70
|
+
("defunct ... Retry shortly"), and never after pi has started quitting.
|
|
71
|
+
- The footer could keep showing a stale `registering tools N/M` when an
|
|
72
|
+
earlier refresh finished after a later one.
|
|
73
|
+
|
|
74
|
+
### Changed
|
|
75
|
+
|
|
76
|
+
- **Requires sharedserver 0.9.6 or newer** (the pi, OpenCode and Claude plugins
|
|
77
|
+
alike; was 0.6.7 / 0.6.6). 0.9.6 adds a launch lock: several clients calling
|
|
78
|
+
`use` on a stopped combiner at once now start exactly one and keep every
|
|
79
|
+
reference (0.9.5 could start two and lose references), which the automatic
|
|
80
|
+
respawn relies on. An older sharedserver found on your PATH makes the plugins
|
|
81
|
+
fetch the current release, unless you set `SHAREDSERVER_BIN` explicitly.
|
|
82
|
+
- The footer shows `registering tools N/M` while a registration pass runs.
|
|
83
|
+
- Depends on `@earendil-works/pi-mcp` `^1.6.0` (was `^1.2.0`).
|
|
84
|
+
|
|
85
|
+
## [0.24.4] - 2026-11-20
|
|
86
|
+
|
|
87
|
+
### Fixed
|
|
88
|
+
|
|
89
|
+
- **pi exits promptly.** Every connect left an 8-second connect-timeout timer
|
|
90
|
+
running (it was never stored, so it was never cleared), which held pi's
|
|
91
|
+
process open after shutdown. The timer is now cleared and `unref`'d.
|
|
92
|
+
- **Faster startup.** With the combiner's faster `--version` (combiner
|
|
93
|
+
changelog), the version check pi runs while starting takes about 0.1 s
|
|
94
|
+
instead of 1.2 s, so startup drops from about 1.2 s to about 0.2 s when
|
|
95
|
+
the combiner is installed.
|
|
96
|
+
|
|
97
|
+
## [0.24.3] - 2026-11-20 (not published; included in 0.24.4)
|
|
98
|
+
|
|
99
|
+
### Fixed
|
|
100
|
+
|
|
101
|
+
- Compatible with pi 1.6.0's TUI contract: the extension's components
|
|
102
|
+
declare `render()` as returning `readonly string[]`, so they typecheck
|
|
103
|
+
against `@earendil-works/pi-tui` 1.6, whose `Container.render` returns a
|
|
104
|
+
cached read-only array. No behaviour change. The `pi-tui` peer range now
|
|
105
|
+
includes the 1.x releases (`^0.85.1 || ^1.0.0`).
|
|
106
|
+
- `npm run smoke` builds first: it tests the built `dist/`, and a stale build
|
|
107
|
+
had produced false failures. Its token-filter check now treats
|
|
108
|
+
`open_widget` as a combiner tool, which no server filter hides.
|
|
109
|
+
|
|
9
110
|
## [0.24.2] - 2026-11-15
|
|
10
111
|
|
|
11
112
|
No extension changes. The combiner it runs now requires fastmcp 4.2.0.
|
package/dist/client/footer.d.ts
CHANGED
|
@@ -9,9 +9,17 @@ export type FooterCounts = {
|
|
|
9
9
|
/** Derive enabled/ready/disabled counts from a /health snapshot. Tolerates both
|
|
10
10
|
* the object-keyed shape (what the combiner serves) and an array (defensive). */
|
|
11
11
|
export declare function countsFromHealth(health: unknown): FooterCounts;
|
|
12
|
+
/** A native tool-registration pass in progress: tools registered so far / to register. */
|
|
13
|
+
export type RegisterProgress = {
|
|
14
|
+
done: number;
|
|
15
|
+
total: number;
|
|
16
|
+
};
|
|
12
17
|
/** Render the footer text for a mode (undefined = clear the slot). */
|
|
13
|
-
export declare function footerText(mode: FooterStatus, counts: FooterCounts, connectionState: string, toolCount?: number): string | undefined;
|
|
18
|
+
export declare function footerText(mode: FooterStatus, counts: FooterCounts, connectionState: string, toolCount?: number, registering?: RegisterProgress): string | undefined;
|
|
14
19
|
/** Refresh the footer from live health + this session's tool view. Never throws;
|
|
15
20
|
* logs (once) when the UI cannot take a status so a dead label is diagnosable. */
|
|
16
|
-
export declare function updateFooter(connection: CombinerConnection, ui: ExtensionUIContext | undefined, key: string, mode: FooterStatus
|
|
21
|
+
export declare function updateFooter(connection: CombinerConnection, ui: ExtensionUIContext | undefined, key: string, mode: FooterStatus,
|
|
22
|
+
/** Read AFTER the /health and tools/list awaits, so a slow paint that resolves
|
|
23
|
+
* last shows the progress as it is then, not as it was when it started. */
|
|
24
|
+
registering?: () => RegisterProgress | undefined): Promise<void>;
|
|
17
25
|
//# sourceMappingURL=footer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../src/client/footer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAajD,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AAE/E;kFACkF;AAClF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAyB9D;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CACtB,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,MAAM,EACvB,SAAS,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../src/client/footer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAajD,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AAE/E;kFACkF;AAClF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAyB9D;AAED,0FAA0F;AAC1F,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9D,sEAAsE;AACtE,wBAAgB,UAAU,CACtB,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,MAAM,EACvB,SAAS,CAAC,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,gBAAgB,GAC/B,MAAM,GAAG,SAAS,CAapB;AAID;mFACmF;AACnF,wBAAsB,YAAY,CAC9B,UAAU,EAAE,kBAAkB,EAC9B,EAAE,EAAE,kBAAkB,GAAG,SAAS,EAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,YAAY;AAClB;4EAC4E;AAC5E,WAAW,CAAC,EAAE,MAAM,gBAAgB,GAAG,SAAS,GACjD,OAAO,CAAC,IAAI,CAAC,CA8Bf"}
|
package/dist/client/footer.js
CHANGED
|
@@ -44,7 +44,7 @@ export function countsFromHealth(health) {
|
|
|
44
44
|
return { enabled, ready, disabled };
|
|
45
45
|
}
|
|
46
46
|
/** Render the footer text for a mode (undefined = clear the slot). */
|
|
47
|
-
export function footerText(mode, counts, connectionState, toolCount) {
|
|
47
|
+
export function footerText(mode, counts, connectionState, toolCount, registering) {
|
|
48
48
|
if (mode === "off")
|
|
49
49
|
return undefined;
|
|
50
50
|
if (mode === "compact")
|
|
@@ -54,7 +54,10 @@ export function footerText(mode, counts, connectionState, toolCount) {
|
|
|
54
54
|
text += ` (${counts.ready} ready)`;
|
|
55
55
|
if (counts.disabled > 0)
|
|
56
56
|
text += ` (${counts.disabled} disabled)`;
|
|
57
|
-
if (
|
|
57
|
+
if (registering && registering.done < registering.total) {
|
|
58
|
+
text += ` · registering tools ${registering.done}/${registering.total}`;
|
|
59
|
+
}
|
|
60
|
+
else if (typeof toolCount === "number" && toolCount > 0)
|
|
58
61
|
text += ` · ${toolCount} tools`;
|
|
59
62
|
if (connectionState !== "connected" && connectionState !== "disconnected") {
|
|
60
63
|
text += ` — ${connectionState}`;
|
|
@@ -64,7 +67,10 @@ export function footerText(mode, counts, connectionState, toolCount) {
|
|
|
64
67
|
let warnedNoSetStatus = false;
|
|
65
68
|
/** Refresh the footer from live health + this session's tool view. Never throws;
|
|
66
69
|
* logs (once) when the UI cannot take a status so a dead label is diagnosable. */
|
|
67
|
-
export async function updateFooter(connection, ui, key, mode
|
|
70
|
+
export async function updateFooter(connection, ui, key, mode,
|
|
71
|
+
/** Read AFTER the /health and tools/list awaits, so a slow paint that resolves
|
|
72
|
+
* last shows the progress as it is then, not as it was when it started. */
|
|
73
|
+
registering) {
|
|
68
74
|
if (mode === "off")
|
|
69
75
|
return;
|
|
70
76
|
const setStatus = ui?.setStatus;
|
|
@@ -80,9 +86,12 @@ export async function updateFooter(connection, ui, key, mode) {
|
|
|
80
86
|
}
|
|
81
87
|
let text;
|
|
82
88
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
// List tools only on a live connection: a footer repaint must never start a
|
|
90
|
+
// connect itself (it would bypass the connection's reconnect backoff).
|
|
91
|
+
const tools = connection.state === "connected" ? connection.listTools().catch(() => undefined) : undefined;
|
|
92
|
+
const [health, toolList] = await Promise.all([connection.health(), tools]);
|
|
93
|
+
const toolCount = toolList?.length;
|
|
94
|
+
text = footerText(mode, countsFromHealth(health), connection.state, toolCount, registering?.());
|
|
86
95
|
}
|
|
87
96
|
catch {
|
|
88
97
|
// Combiner unreachable: report our connection state honestly, still occupying
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.js","sourceRoot":"","sources":["../../src/client/footer.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,uFAAuF;AACvF,oFAAoF;AACpF,uEAAuE;AACvE,8EAA8E;AAM9E,mFAAmF;AACnF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;AAEpD;;4DAE4D;AAC5D,MAAM,IAAI,GAAG,QAAQ,CAAA;AAOrB;kFACkF;AAClF,MAAM,UAAU,gBAAgB,CAAC,MAAe;IAC5C,MAAM,GAAG,GAAI,MAAgC,EAAE,OAAO,CAAA;IACtD,MAAM,OAAO,GA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A;QAC1E,MAAM,SAAS,GAAG,QAAQ,EAAE,MAAM,CAAA;QAClC,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,CAAC,CAAA;IACnG,CAAC;IAAC,MAAM,CAAC;QACL,8EAA8E;QAC9E,iDAAiD;QACjD,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACpF,CAAC;IACD,IAAI,CAAC;QACD,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACxB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IAC1G,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { Liveness } from "./native/combiner-connection.js";
|
|
2
|
+
export type LogFn = (level: "info" | "warn" | "error", message: string) => void;
|
|
3
|
+
export declare const DEFAULT_PORT = 9741;
|
|
4
|
+
/** Respawn cap: at most RESPAWN_LIMIT respawns in any RESPAWN_WINDOW_MS; one more
|
|
5
|
+
* inside the window means the combiner keeps dying, so stop and report. */
|
|
6
|
+
export declare const RESPAWN_LIMIT = 2;
|
|
7
|
+
export declare const RESPAWN_WINDOW_MS = 60000;
|
|
8
|
+
/** How often watch() checks that the combiner process still exists. */
|
|
9
|
+
export declare const WATCH_INTERVAL_MS = 2000;
|
|
10
|
+
/** Every this many watch ticks (~30 s), also re-read sharedserver's view: catches a
|
|
11
|
+
* reused pid and a different combiner process replacing ours. */
|
|
12
|
+
export declare const WATCH_STATUS_EVERY = 15;
|
|
13
|
+
/** How long after this pi launched the combiner it counts as still booting (the
|
|
14
|
+
* connection's first-connect budget). */
|
|
15
|
+
export declare const COLD_START_MS = 15000;
|
|
16
|
+
export declare function env(name: string): string | undefined;
|
|
17
|
+
/** A combiner process: its pid and start time, so a reused pid isn't mistaken for
|
|
18
|
+
* the same process. */
|
|
19
|
+
export type CombinerIdentity = {
|
|
20
|
+
pid: number;
|
|
21
|
+
startTime: number | undefined;
|
|
22
|
+
};
|
|
23
|
+
/** What sharedserver says about `name` (`sharedserver info <name> --json`):
|
|
24
|
+
* - running: active or in its grace period, with the real server process;
|
|
25
|
+
* - stopped: not running, or defunct (it died; sharedserver is cleaning up);
|
|
26
|
+
* - unknown: a start is still publishing its process (`watcher_pid` null), or the
|
|
27
|
+
* lookup got no answer (`noAnswer`: timed out, errored, or unparseable output).
|
|
28
|
+
* sharedserver answers in a few ms with a definite state, so no answer is a
|
|
29
|
+
* sharedserver bug: callers report it and fall back to checking the pid. */
|
|
30
|
+
export type CombinerStatus = {
|
|
31
|
+
kind: "running";
|
|
32
|
+
identity: CombinerIdentity;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "stopped";
|
|
35
|
+
} | {
|
|
36
|
+
kind: "unknown";
|
|
37
|
+
noAnswer?: string;
|
|
38
|
+
};
|
|
39
|
+
/** How long to wait for `sharedserver info` (it normally answers in ~4 ms). */
|
|
40
|
+
export declare const STATUS_TIMEOUT_MS = 500;
|
|
41
|
+
/** Parse `sharedserver info --json` output (exported for tests). */
|
|
42
|
+
export declare function parseCombinerStatus(out: string): CombinerStatus;
|
|
43
|
+
/** The port to serve on, reconciling PI_MCP_COMBINER_PORT with any explicit
|
|
44
|
+
* MCP_COMPANION_COMBINER_URL. */
|
|
45
|
+
export declare function resolvePort(log: LogFn): number;
|
|
46
|
+
/** The combiner process this pi holds its ref on. `identity` is undefined until
|
|
47
|
+
* known (filled in lazily when the attach-time lookup came back unknown). */
|
|
48
|
+
export type Attachment = {
|
|
49
|
+
binary: string;
|
|
50
|
+
name: string;
|
|
51
|
+
identity: CombinerIdentity | undefined;
|
|
52
|
+
};
|
|
53
|
+
export type ProcessState = {
|
|
54
|
+
attachment: Attachment | null;
|
|
55
|
+
/** Set at quit: an attach in flight must not re-take the combiner afterwards. */
|
|
56
|
+
quitting: boolean;
|
|
57
|
+
/** attach()'s single flight, so concurrent callers share one `use`; and whether
|
|
58
|
+
* that flight may launch (a launching caller never settles for an attach-only
|
|
59
|
+
* flight that failed). */
|
|
60
|
+
attaching?: Promise<boolean>;
|
|
61
|
+
attachingLaunches?: boolean;
|
|
62
|
+
/** The respawn in flight, keyed by the dead process: concurrent callers for the
|
|
63
|
+
* same death share it, so one death counts once. */
|
|
64
|
+
respawning?: {
|
|
65
|
+
key: string;
|
|
66
|
+
promise: Promise<Liveness>;
|
|
67
|
+
};
|
|
68
|
+
/** When this pi respawned a dead combiner (ms timestamps, newest last). */
|
|
69
|
+
respawns: number[];
|
|
70
|
+
/** Set once the respawn cap was hit (or restarts kept failing); cleared by start(). */
|
|
71
|
+
respawnStopped: boolean;
|
|
72
|
+
/** Consecutive restarts whose attach failed (no combiner launched). */
|
|
73
|
+
respawnFailures: number;
|
|
74
|
+
/** When this pi's own `use` launched the combiner (it said "Started server"):
|
|
75
|
+
* a combiner that young is still booting, so connects get the cold-start budget. */
|
|
76
|
+
launchedAt?: number;
|
|
77
|
+
/** How many times this pi's `use` launched the combiner (vs only attached). */
|
|
78
|
+
launches: number;
|
|
79
|
+
/** The combiner's log files, for the report when respawning stops. */
|
|
80
|
+
logs: string[];
|
|
81
|
+
};
|
|
82
|
+
/** The globalThis key of the per-process state (tests reset it). */
|
|
83
|
+
export declare const COMBINER_PROCESS_STATE: unique symbol;
|
|
84
|
+
export declare class CombinerProcess {
|
|
85
|
+
protected readonly state: ProcessState;
|
|
86
|
+
private log;
|
|
87
|
+
private releaseReady;
|
|
88
|
+
/** Resolves once this instance's start() has run, whatever its outcome. Connects
|
|
89
|
+
* wait on it, so the first connect never races the launch. */
|
|
90
|
+
readonly ready: Promise<void>;
|
|
91
|
+
/** Set when a connect succeeded with no attachment (start()'s attach failed):
|
|
92
|
+
* attach once then, not on every reconnect (the attach runs synchronous probes). */
|
|
93
|
+
private reconnectAttachTried;
|
|
94
|
+
constructor(log: LogFn);
|
|
95
|
+
/** True while this pi process holds a ref on a combiner process. */
|
|
96
|
+
get attached(): boolean;
|
|
97
|
+
/** session_start: attach (launching if needed) unless this pi process already
|
|
98
|
+
* holds a ref; always releases `ready`. An explicit start also lifts a respawn
|
|
99
|
+
* stop and clears the respawn history. */
|
|
100
|
+
start(log: LogFn): Promise<void>;
|
|
101
|
+
/** session_shutdown("quit"): release the ref; no attach after this. */
|
|
102
|
+
quit(): void;
|
|
103
|
+
/** After a successful (re)connect. Attached: if the combiner is now a different
|
|
104
|
+
* process, attach() again (same function, same ref). Not attached (start()'s
|
|
105
|
+
* attach failed, or respawning stopped): attach once, to a running combiner. */
|
|
106
|
+
onReconnected(): Promise<void>;
|
|
107
|
+
/** Between refused-connect retries (the connection's liveness check):
|
|
108
|
+
* - ours, alive: "alive" (a blip), or "relaunched" while our own fresh launch
|
|
109
|
+
* is still booting, so the connect gets the cold-start budget;
|
|
110
|
+
* - a different process: attach to it (same function, same ref), "alive";
|
|
111
|
+
* - ours, stopped: respawn within the cap ("relaunched" / "gone");
|
|
112
|
+
* - unknown, or never attached: "alive". An unknown lookup is never dead, and
|
|
113
|
+
* with nothing of ours to judge there is nothing to respawn. */
|
|
114
|
+
onRefused(): Promise<Liveness>;
|
|
115
|
+
/** Respawn our dead combiner with the one attach function, within the cap.
|
|
116
|
+
* Concurrent callers for the same death share one respawn. */
|
|
117
|
+
private respawn;
|
|
118
|
+
/** Set after reporting that sharedserver gave no answer; cleared by an answer. */
|
|
119
|
+
private noAnswerReported;
|
|
120
|
+
private reportNoAnswer;
|
|
121
|
+
/** Stop respawning and report why, once. The dead process's ref died with it;
|
|
122
|
+
* dropping the attachment lets a combiner someone else starts later be picked up
|
|
123
|
+
* (onReconnected attaches to it). */
|
|
124
|
+
private stopRespawning;
|
|
125
|
+
/** Record that this pi's attach launched the combiner (rather than attaching to
|
|
126
|
+
* a running one). Protected so a test subclass's scripted launch can call it. */
|
|
127
|
+
protected noteLaunched(): void;
|
|
128
|
+
/** True while a combiner this pi launched is younger than COLD_START_MS. */
|
|
129
|
+
private booting;
|
|
130
|
+
/** The process our ref is on; fills it in if the attach-time lookup was unknown. */
|
|
131
|
+
private attachedIdentity;
|
|
132
|
+
/** Watch the combiner process this pi holds its ref on. Every WATCH_INTERVAL_MS,
|
|
133
|
+
* check its pid still exists (a syscall, no child process); every
|
|
134
|
+
* WATCH_STATUS_EVERY ticks also ask sharedserver, which catches a reused pid and
|
|
135
|
+
* a different process replacing ours. When ours is gone, call `onGone` once for
|
|
136
|
+
* that process: the caller reconnects, and the reconnect asks onRefused /
|
|
137
|
+
* onReconnected. A dropped connection isn't reliably reported when the combiner
|
|
138
|
+
* dies, so this is what makes recovery prompt. Returns a stop function; nothing
|
|
139
|
+
* is reported after it's called. */
|
|
140
|
+
watch(onGone: () => void): () => void;
|
|
141
|
+
/** Whether process `pid` exists (a seam for tests). EPERM means it exists but
|
|
142
|
+
* isn't ours to signal. */
|
|
143
|
+
protected isAlive(pid: number): boolean;
|
|
144
|
+
/** What sharedserver says about the combiner now (a seam for tests). */
|
|
145
|
+
protected statusOf(binary: string, name: string): Promise<CombinerStatus>;
|
|
146
|
+
/** The ONE attach procedure: `sharedserver use` (launches the combiner when it
|
|
147
|
+
* isn't running, else just takes this pi process's ref), then records which
|
|
148
|
+
* process the ref is on. `onlyIfRunning`: attach to a running combiner, never
|
|
149
|
+
* launch one. Single-flight; resolves true when attached. */
|
|
150
|
+
attach(opts?: {
|
|
151
|
+
onlyIfRunning?: boolean;
|
|
152
|
+
}): Promise<boolean>;
|
|
153
|
+
/** The attach itself (resolve sharedserver + the combiner, `sharedserver use`,
|
|
154
|
+
* record the identity). Protected so tests can subclass it; nothing else
|
|
155
|
+
* overrides it. */
|
|
156
|
+
protected attachOnce(opts: {
|
|
157
|
+
onlyIfRunning?: boolean;
|
|
158
|
+
}): Promise<boolean>;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=combiner-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combiner-process.d.ts","sourceRoot":"","sources":["../src/combiner-process.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAE/D,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;AAE/E,eAAO,MAAM,YAAY,OAAO,CAAA;AAiBhC;4EAC4E;AAC5E,eAAO,MAAM,aAAa,IAAI,CAAA;AAC9B,eAAO,MAAM,iBAAiB,QAAS,CAAA;AACvC,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,OAAQ,CAAA;AACtC;kEACkE;AAClE,eAAO,MAAM,kBAAkB,KAAK,CAAA;AACpC;0CAC0C;AAC1C,eAAO,MAAM,aAAa,QAAS,CAAA;AAQnC,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGpD;AAgJD;wBACwB;AACxB,MAAM,MAAM,gBAAgB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAE7E;;;;;;6EAM6E;AAC7E,MAAM,MAAM,cAAc,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAM5C,+EAA+E;AAC/E,eAAO,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