@rivet-dev/agentos-runtime-core 0.2.6 → 0.2.8-rc.1
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/commands/bash +0 -0
- package/commands/sh +0 -0
- package/dist/correlation.d.ts +1 -4
- package/dist/correlation.js +7 -10
- package/dist/frame-rpc.d.ts +9 -4
- package/dist/frame-rpc.js +19 -2
- package/dist/kernel-proxy.d.ts +1 -1
- package/dist/kernel-proxy.js +17 -7
- package/dist/native-client.d.ts +6 -2
- package/dist/native-client.js +13 -3
- package/dist/protocol-client.d.ts +19 -2
- package/dist/protocol-client.js +67 -6
- package/dist/response-payloads.d.ts +1 -1
- package/dist/response-payloads.js +1 -1
- package/dist/sidecar-errors.d.ts +15 -0
- package/dist/sidecar-errors.js +17 -0
- package/dist/sidecar-process.d.ts +8 -4
- package/dist/sidecar-process.js +2 -3
- package/dist/state.d.ts +6 -6
- package/dist/state.js +10 -11
- package/dist/test-runtime.d.ts +3 -0
- package/dist/test-runtime.js +1 -2
- package/package.json +2 -2
package/commands/bash
CHANGED
|
Binary file
|
package/commands/sh
CHANGED
|
Binary file
|
package/dist/correlation.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
export declare class PendingResponseRegistry<TResponse> {
|
|
2
2
|
private readonly pending;
|
|
3
|
-
waitForResponse(requestId: number
|
|
4
|
-
timeoutMs: number;
|
|
5
|
-
timeoutMessage: () => string;
|
|
6
|
-
}): Promise<TResponse>;
|
|
3
|
+
waitForResponse(requestId: number): Promise<TResponse>;
|
|
7
4
|
resolve(requestId: number, frame: TResponse): boolean;
|
|
8
5
|
reject(requestId: number, error: Error): boolean;
|
|
9
6
|
rejectAll(error: Error): void;
|
package/dist/correlation.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
export class PendingResponseRegistry {
|
|
2
2
|
pending = new Map();
|
|
3
|
-
|
|
3
|
+
// Deliberately no per-request timer: local framed stdio never loses frames,
|
|
4
|
+
// so a response is bounded by the transport's silence watchdog (a dead or
|
|
5
|
+
// wedged sidecar rejects all pending requests through `rejectAll`) rather
|
|
6
|
+
// than by guessing how long any one request should take.
|
|
7
|
+
waitForResponse(requestId) {
|
|
4
8
|
if (this.pending.has(requestId)) {
|
|
5
9
|
throw new Error(`response waiter already registered for request ${requestId}`);
|
|
6
10
|
}
|
|
7
11
|
return new Promise((resolve, reject) => {
|
|
8
|
-
|
|
12
|
+
this.pending.set(requestId, {
|
|
9
13
|
resolve: (frame) => {
|
|
10
|
-
clearTimeout(entry.timer);
|
|
11
14
|
this.pending.delete(requestId);
|
|
12
15
|
resolve(frame);
|
|
13
16
|
},
|
|
14
17
|
reject: (error) => {
|
|
15
|
-
clearTimeout(entry.timer);
|
|
16
18
|
this.pending.delete(requestId);
|
|
17
19
|
reject(error);
|
|
18
20
|
},
|
|
19
|
-
|
|
20
|
-
this.pending.delete(requestId);
|
|
21
|
-
reject(new Error(options.timeoutMessage()));
|
|
22
|
-
}, options.timeoutMs),
|
|
23
|
-
};
|
|
24
|
-
this.pending.set(requestId, entry);
|
|
21
|
+
});
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
24
|
resolve(requestId, frame) {
|
package/dist/frame-rpc.d.ts
CHANGED
|
@@ -24,15 +24,20 @@ export declare class FrameRpcTransport<TReadFrame, TWriteFrame, TResponseFrame,
|
|
|
24
24
|
private readonly pendingResponses;
|
|
25
25
|
private readonly eventListeners;
|
|
26
26
|
private readonly sidecarRequestListeners;
|
|
27
|
+
private readonly frameActivityListeners;
|
|
27
28
|
constructor(options: FrameRpcTransportOptions<TReadFrame, TWriteFrame, TResponseFrame, TEventFrame, TSidecarRequestFrame>);
|
|
28
29
|
onEvent(handler: (event: TEventFrame) => void): () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Observe every classified inbound frame (response, event, or sidecar
|
|
32
|
+
* request) before it is routed. This is the transport's liveness signal:
|
|
33
|
+
* the silence watchdog resets on each invocation, so ANY inbound traffic —
|
|
34
|
+
* not just heartbeats — proves the sidecar is alive.
|
|
35
|
+
*/
|
|
36
|
+
onFrameActivity(handler: () => void): () => void;
|
|
29
37
|
onSidecarRequest(handler: (request: TSidecarRequestFrame) => void): () => void;
|
|
30
38
|
onError(handler: (error: Error) => void): () => void;
|
|
31
39
|
onEnd(handler: () => void): () => void;
|
|
32
|
-
sendFrame(requestId: number, frame: TWriteFrame
|
|
33
|
-
timeoutMs: number;
|
|
34
|
-
timeoutMessage: () => string;
|
|
35
|
-
}): Promise<TResponseFrame>;
|
|
40
|
+
sendFrame(requestId: number, frame: TWriteFrame): Promise<TResponseFrame>;
|
|
36
41
|
writeFrame(frame: TWriteFrame): Promise<void>;
|
|
37
42
|
rejectAll(error: Error): void;
|
|
38
43
|
dispose(): void;
|
package/dist/frame-rpc.js
CHANGED
|
@@ -5,6 +5,7 @@ export class FrameRpcTransport {
|
|
|
5
5
|
pendingResponses = new PendingResponseRegistry();
|
|
6
6
|
eventListeners = new Set();
|
|
7
7
|
sidecarRequestListeners = new Set();
|
|
8
|
+
frameActivityListeners = new Set();
|
|
8
9
|
constructor(options) {
|
|
9
10
|
if (options.frameTransport) {
|
|
10
11
|
this.frameTransport = options.frameTransport;
|
|
@@ -30,6 +31,18 @@ export class FrameRpcTransport {
|
|
|
30
31
|
this.eventListeners.delete(handler);
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Observe every classified inbound frame (response, event, or sidecar
|
|
36
|
+
* request) before it is routed. This is the transport's liveness signal:
|
|
37
|
+
* the silence watchdog resets on each invocation, so ANY inbound traffic —
|
|
38
|
+
* not just heartbeats — proves the sidecar is alive.
|
|
39
|
+
*/
|
|
40
|
+
onFrameActivity(handler) {
|
|
41
|
+
this.frameActivityListeners.add(handler);
|
|
42
|
+
return () => {
|
|
43
|
+
this.frameActivityListeners.delete(handler);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
33
46
|
onSidecarRequest(handler) {
|
|
34
47
|
this.sidecarRequestListeners.add(handler);
|
|
35
48
|
return () => {
|
|
@@ -42,8 +55,8 @@ export class FrameRpcTransport {
|
|
|
42
55
|
onEnd(handler) {
|
|
43
56
|
return this.frameTransport.onEnd(handler);
|
|
44
57
|
}
|
|
45
|
-
async sendFrame(requestId, frame
|
|
46
|
-
const response = this.pendingResponses.waitForResponse(requestId
|
|
58
|
+
async sendFrame(requestId, frame) {
|
|
59
|
+
const response = this.pendingResponses.waitForResponse(requestId);
|
|
47
60
|
void this.writeFrame(frame).catch((error) => {
|
|
48
61
|
this.pendingResponses.reject(requestId, error instanceof Error ? error : new Error(String(error)));
|
|
49
62
|
});
|
|
@@ -60,8 +73,12 @@ export class FrameRpcTransport {
|
|
|
60
73
|
this.pendingResponses.rejectAll(new Error("frame rpc transport disposed"));
|
|
61
74
|
this.eventListeners.clear();
|
|
62
75
|
this.sidecarRequestListeners.clear();
|
|
76
|
+
this.frameActivityListeners.clear();
|
|
63
77
|
}
|
|
64
78
|
dispatchFrame(classified) {
|
|
79
|
+
for (const listener of this.frameActivityListeners) {
|
|
80
|
+
listener();
|
|
81
|
+
}
|
|
65
82
|
switch (classified.kind) {
|
|
66
83
|
case "response":
|
|
67
84
|
this.pendingResponses.resolve(classified.requestId, classified.frame);
|
package/dist/kernel-proxy.d.ts
CHANGED
|
@@ -163,4 +163,4 @@ export declare class NativeSidecarKernelProxy {
|
|
|
163
163
|
private updateTrackedProcessSnapshot;
|
|
164
164
|
}
|
|
165
165
|
export type { AuthenticatedSession, CreatedVm, GuestFilesystemStat, SidecarSpawnOptions, RootFilesystemEntry, SidecarEventSelector, SidecarPermissionsPolicy, SidecarRegisteredHostCallbackDefinition, SidecarRequestFrame, SidecarRequestHandler, SidecarResponsePayload, SidecarSessionState, SidecarSignalHandlerRegistration, SidecarSocketStateEntry, } from "./sidecar-process.js";
|
|
166
|
-
export {
|
|
166
|
+
export { SidecarProcess, SidecarEventBufferOverflow, SidecarProcessError, SidecarProcessExited, } from "./sidecar-process.js";
|
package/dist/kernel-proxy.js
CHANGED
|
@@ -985,6 +985,10 @@ export class NativeSidecarKernelProxy {
|
|
|
985
985
|
}
|
|
986
986
|
return this.client.rename(this.session, this.vm, oldPath, newPath);
|
|
987
987
|
}
|
|
988
|
+
// Test-runtime only: runtime mounts registered here stay host-side local
|
|
989
|
+
// compat mounts and are not delivered to the sidecar. The production proxy
|
|
990
|
+
// in @rivet-dev/agentos-core reconfigures sidecar mounts on every
|
|
991
|
+
// mountFs/unmountFs.
|
|
988
992
|
mountFs(path, driver, options) {
|
|
989
993
|
this.localMounts.unshift({
|
|
990
994
|
path: posixPath.normalize(path),
|
|
@@ -1727,21 +1731,27 @@ function isMissingHostProcessError(error) {
|
|
|
1727
1731
|
function errnoError(code, message) {
|
|
1728
1732
|
return Object.assign(new Error(`${code}: ${message}`), { code });
|
|
1729
1733
|
}
|
|
1734
|
+
// VirtualStat is a numeric, Node-default-shaped view: u64 fields above
|
|
1735
|
+
// Number.MAX_SAFE_INTEGER lose precision here, same as Node's non-bigint
|
|
1736
|
+
// fs.stat on the host.
|
|
1730
1737
|
function toVirtualStat(stat) {
|
|
1731
1738
|
return {
|
|
1732
1739
|
mode: stat.mode,
|
|
1733
|
-
size: stat.size,
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1740
|
+
size: Number(stat.size),
|
|
1741
|
+
sizeExact: stat.size,
|
|
1742
|
+
blocks: Number(stat.blocks),
|
|
1743
|
+
dev: Number(stat.dev),
|
|
1744
|
+
rdev: Number(stat.rdev),
|
|
1737
1745
|
isDirectory: stat.is_directory,
|
|
1738
1746
|
isSymbolicLink: stat.is_symbolic_link,
|
|
1739
1747
|
atimeMs: stat.atime_ms,
|
|
1740
1748
|
mtimeMs: stat.mtime_ms,
|
|
1741
1749
|
ctimeMs: stat.ctime_ms,
|
|
1742
1750
|
birthtimeMs: stat.birthtime_ms,
|
|
1743
|
-
ino: stat.ino,
|
|
1744
|
-
|
|
1751
|
+
ino: Number(stat.ino),
|
|
1752
|
+
inoExact: stat.ino,
|
|
1753
|
+
nlink: Number(stat.nlink),
|
|
1754
|
+
nlinkExact: stat.nlink,
|
|
1745
1755
|
uid: stat.uid,
|
|
1746
1756
|
gid: stat.gid,
|
|
1747
1757
|
};
|
|
@@ -1774,4 +1784,4 @@ function socketLookupKey(kind, request) {
|
|
|
1774
1784
|
path: request.path ?? null,
|
|
1775
1785
|
});
|
|
1776
1786
|
}
|
|
1777
|
-
export {
|
|
1787
|
+
export { SidecarProcess, SidecarEventBufferOverflow, SidecarProcessError, SidecarProcessExited, } from "./sidecar-process.js";
|
package/dist/native-client.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { LiveEventFrame, LiveResponseFrame, LiveSidecarRequestHandler, Prot
|
|
|
4
4
|
import type { LiveOwnershipScope } from "./ownership.js";
|
|
5
5
|
import type { LiveRequestPayload } from "./request-payloads.js";
|
|
6
6
|
import type { LiveSidecarEventSelector } from "./event-buffer.js";
|
|
7
|
-
export declare const DEFAULT_SIDECAR_FRAME_TIMEOUT_MS = 120000;
|
|
8
7
|
export declare const DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY = 4096;
|
|
9
8
|
export declare const DEFAULT_SIDECAR_GRACEFUL_EXIT_MS = 5000;
|
|
10
9
|
export declare const DEFAULT_SIDECAR_FORCE_EXIT_MS = 2000;
|
|
@@ -12,12 +11,17 @@ export interface StdioSidecarProtocolClientSpawnOptions {
|
|
|
12
11
|
cwd?: string;
|
|
13
12
|
command?: string;
|
|
14
13
|
args?: string[];
|
|
15
|
-
frameTimeoutMs?: number;
|
|
16
14
|
eventBufferCapacity?: number;
|
|
17
15
|
gracefulExitMs?: number;
|
|
18
16
|
forceExitMs?: number;
|
|
19
17
|
disposedErrorMessage?: string;
|
|
20
18
|
payloadCodec?: ProtocolFramePayloadCodec;
|
|
19
|
+
/**
|
|
20
|
+
* Override the silence watchdog window (default 30s). Tests only — the
|
|
21
|
+
* window is a fixed protocol constant paired with the sidecar's 10s
|
|
22
|
+
* heartbeat cadence, not an operator tunable.
|
|
23
|
+
*/
|
|
24
|
+
silenceTimeoutMs?: number;
|
|
21
25
|
}
|
|
22
26
|
export declare class StdioSidecarProtocolClient implements SidecarProcessTransport {
|
|
23
27
|
readonly child: StdioSidecarProcess["child"];
|
package/dist/native-client.js
CHANGED
|
@@ -2,7 +2,6 @@ import { resolvePublishedSidecarBinary } from "./binary.js";
|
|
|
2
2
|
import { SidecarProcessExited, StdioSidecarProcess, } from "./process.js";
|
|
3
3
|
import { SidecarProtocolClient } from "./protocol-client.js";
|
|
4
4
|
import { registerSidecarProcessSpawnFactory } from "./sidecar-process.js";
|
|
5
|
-
export const DEFAULT_SIDECAR_FRAME_TIMEOUT_MS = 120_000;
|
|
6
5
|
export const DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY = 4_096;
|
|
7
6
|
export const DEFAULT_SIDECAR_GRACEFUL_EXIT_MS = 5_000;
|
|
8
7
|
export const DEFAULT_SIDECAR_FORCE_EXIT_MS = 2_000;
|
|
@@ -22,9 +21,20 @@ export class StdioSidecarProtocolClient {
|
|
|
22
21
|
this.protocolClient = new SidecarProtocolClient({
|
|
23
22
|
stdin: this.child.stdin,
|
|
24
23
|
stdout: this.child.stdout,
|
|
25
|
-
frameTimeoutMs: options.frameTimeoutMs,
|
|
26
24
|
eventBufferCapacity: options.eventBufferCapacity,
|
|
27
25
|
payloadCodec: options.payloadCodec,
|
|
26
|
+
silenceTimeoutMs: options.silenceTimeoutMs,
|
|
27
|
+
// A silent sidecar is dead or wedged; reap the process so it cannot
|
|
28
|
+
// linger as a zombie holding VM resources. The watchdog then rejects
|
|
29
|
+
// all in-flight requests with `SidecarSilenceTimeout`.
|
|
30
|
+
onSilenceExpired: () => {
|
|
31
|
+
try {
|
|
32
|
+
this.child.kill("SIGKILL");
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// The child may have exited between the check and the kill.
|
|
36
|
+
}
|
|
37
|
+
},
|
|
28
38
|
stderrText: () => this.sidecarProcess.stderrText(),
|
|
29
39
|
streamEndedError: () => this.sidecarProcess.currentExitError() ??
|
|
30
40
|
new SidecarProcessExited({
|
|
@@ -47,7 +57,7 @@ export class StdioSidecarProtocolClient {
|
|
|
47
57
|
args: options.args ?? [],
|
|
48
58
|
cwd: options.cwd,
|
|
49
59
|
}), {
|
|
50
|
-
|
|
60
|
+
silenceTimeoutMs: options.silenceTimeoutMs,
|
|
51
61
|
eventBufferCapacity: options.eventBufferCapacity ??
|
|
52
62
|
DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY,
|
|
53
63
|
gracefulExitMs: options.gracefulExitMs ?? DEFAULT_SIDECAR_GRACEFUL_EXIT_MS,
|
|
@@ -8,17 +8,25 @@ export interface SidecarProtocolClientOptions {
|
|
|
8
8
|
frameTransport?: FrameTransport<LiveResponseFrame | LiveEventFrame | LiveSidecarRequestFrame, LiveProtocolFrame>;
|
|
9
9
|
stdin?: Writable;
|
|
10
10
|
stdout?: Readable;
|
|
11
|
-
frameTimeoutMs: number;
|
|
12
11
|
eventBufferCapacity: number;
|
|
13
12
|
payloadCodec?: ProtocolFramePayloadCodec;
|
|
14
13
|
stderrText?: () => string;
|
|
15
14
|
frameError?: (error: Error) => Error;
|
|
16
15
|
streamEndedError?: () => Error;
|
|
16
|
+
/** Override the silence watchdog window. Tests only; production uses the default. */
|
|
17
|
+
silenceTimeoutMs?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Runs when the silence watchdog fires, before pending work is rejected.
|
|
20
|
+
* The stdio layer uses it to SIGKILL the sidecar child.
|
|
21
|
+
*/
|
|
22
|
+
onSilenceExpired?: () => void;
|
|
17
23
|
}
|
|
18
24
|
export declare class SidecarProtocolClient {
|
|
19
25
|
private readonly eventBuffer;
|
|
20
26
|
private readonly eventListeners;
|
|
21
|
-
private readonly
|
|
27
|
+
private readonly silenceTimeoutMs;
|
|
28
|
+
private silenceTimer;
|
|
29
|
+
private lastInboundAtMs;
|
|
22
30
|
private readonly payloadCodec;
|
|
23
31
|
private readonly stderrText;
|
|
24
32
|
private readonly hostFrameFactory;
|
|
@@ -27,6 +35,15 @@ export declare class SidecarProtocolClient {
|
|
|
27
35
|
private readonly eventWaiters;
|
|
28
36
|
private sidecarRequestHandler;
|
|
29
37
|
constructor(options: SidecarProtocolClientOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Arm the silence watchdog: ANY inbound frame resets the clock (see the
|
|
40
|
+
* `onFrameActivity` tap above), and the sidecar heartbeats every 10s even
|
|
41
|
+
* while busy, so sustained silence for the full window means the process
|
|
42
|
+
* is dead or wedged — not slow. The check interval is unref'd so an idle
|
|
43
|
+
* host process can still exit naturally.
|
|
44
|
+
*/
|
|
45
|
+
private startSilenceWatchdog;
|
|
46
|
+
private stopSilenceWatchdog;
|
|
30
47
|
setSidecarRequestHandler(handler: LiveSidecarRequestHandler | null): void;
|
|
31
48
|
onEvent(handler: (event: LiveEventFrame) => void): () => void;
|
|
32
49
|
sendRequest(input: {
|
package/dist/protocol-client.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { SidecarEventBuffer, SidecarEventBufferOverflow, normalizeSidecarEventMatcher, sidecarEventWaitAbortError, } from "./event-buffer.js";
|
|
2
2
|
import { FrameRpcTransport } from "./frame-rpc.js";
|
|
3
3
|
import { HostProtocolFrameFactory, classifySidecarWrittenProtocolFrame, decodeProtocolFramePayload, encodeProtocolFramePayload, resolveSidecarRequestFramePayload, } from "./protocol-frames.js";
|
|
4
|
+
import { SidecarSilenceTimeout } from "./sidecar-errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* How long the host tolerates TOTAL inbound silence (no responses, events,
|
|
7
|
+
* sidecar requests, or heartbeats) before declaring the sidecar dead. The
|
|
8
|
+
* sidecar heartbeats every 10s from a dedicated thread, so this allows two
|
|
9
|
+
* missed beats plus margin; it bounds "sidecar is dead or wedged", never "this
|
|
10
|
+
* request is slow" — individual requests have no deadline of their own.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_SIDECAR_SILENCE_TIMEOUT_MS = 30_000;
|
|
4
13
|
export class SidecarProtocolClient {
|
|
5
14
|
eventBuffer;
|
|
6
15
|
eventListeners = new Set();
|
|
7
|
-
|
|
16
|
+
silenceTimeoutMs;
|
|
17
|
+
silenceTimer = null;
|
|
18
|
+
lastInboundAtMs = 0;
|
|
8
19
|
payloadCodec;
|
|
9
20
|
stderrText;
|
|
10
21
|
hostFrameFactory = new HostProtocolFrameFactory();
|
|
@@ -13,7 +24,8 @@ export class SidecarProtocolClient {
|
|
|
13
24
|
eventWaiters = new Set();
|
|
14
25
|
sidecarRequestHandler = null;
|
|
15
26
|
constructor(options) {
|
|
16
|
-
this.
|
|
27
|
+
this.silenceTimeoutMs =
|
|
28
|
+
options.silenceTimeoutMs ?? DEFAULT_SIDECAR_SILENCE_TIMEOUT_MS;
|
|
17
29
|
this.eventBuffer = new SidecarEventBuffer(options.eventBufferCapacity);
|
|
18
30
|
this.payloadCodec = options.payloadCodec ?? "bare";
|
|
19
31
|
this.stderrText = options.stderrText ?? (() => "");
|
|
@@ -38,6 +50,45 @@ export class SidecarProtocolClient {
|
|
|
38
50
|
this.failPermanently(options.streamEndedError?.() ??
|
|
39
51
|
new Error("sidecar protocol stream ended"));
|
|
40
52
|
});
|
|
53
|
+
this.frameTransport.onFrameActivity(() => {
|
|
54
|
+
this.lastInboundAtMs = performance.now();
|
|
55
|
+
});
|
|
56
|
+
this.startSilenceWatchdog(options.onSilenceExpired);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Arm the silence watchdog: ANY inbound frame resets the clock (see the
|
|
60
|
+
* `onFrameActivity` tap above), and the sidecar heartbeats every 10s even
|
|
61
|
+
* while busy, so sustained silence for the full window means the process
|
|
62
|
+
* is dead or wedged — not slow. The check interval is unref'd so an idle
|
|
63
|
+
* host process can still exit naturally.
|
|
64
|
+
*/
|
|
65
|
+
startSilenceWatchdog(onExpired) {
|
|
66
|
+
this.lastInboundAtMs = performance.now();
|
|
67
|
+
const checkIntervalMs = Math.max(Math.min(this.silenceTimeoutMs / 4, 1_000), 10);
|
|
68
|
+
this.silenceTimer = setInterval(() => {
|
|
69
|
+
const silenceMs = performance.now() - this.lastInboundAtMs;
|
|
70
|
+
if (silenceMs < this.silenceTimeoutMs) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.stopSilenceWatchdog();
|
|
74
|
+
const error = new SidecarSilenceTimeout({
|
|
75
|
+
silenceMs,
|
|
76
|
+
stderr: this.stderrText(),
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
onExpired?.();
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
this.failPermanently(error);
|
|
83
|
+
}
|
|
84
|
+
}, checkIntervalMs);
|
|
85
|
+
this.silenceTimer.unref?.();
|
|
86
|
+
}
|
|
87
|
+
stopSilenceWatchdog() {
|
|
88
|
+
if (this.silenceTimer !== null) {
|
|
89
|
+
clearInterval(this.silenceTimer);
|
|
90
|
+
this.silenceTimer = null;
|
|
91
|
+
}
|
|
41
92
|
}
|
|
42
93
|
setSidecarRequestHandler(handler) {
|
|
43
94
|
this.sidecarRequestHandler = handler;
|
|
@@ -53,10 +104,10 @@ export class SidecarProtocolClient {
|
|
|
53
104
|
throw this.closedError;
|
|
54
105
|
}
|
|
55
106
|
const request = this.hostFrameFactory.createRequestFrame(input);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
107
|
+
// No per-request deadline: only the caller knows whether an operation is
|
|
108
|
+
// legitimately long (a whole agent turn is one request). A dead or
|
|
109
|
+
// wedged sidecar rejects this via the silence watchdog instead.
|
|
110
|
+
const response = await this.frameTransport.sendFrame(request.request_id, request);
|
|
60
111
|
if (response.payload.type === "rejected") {
|
|
61
112
|
throw new Error(`sidecar rejected request ${request.request_id}: ${response.payload.code}: ${response.payload.message}`);
|
|
62
113
|
}
|
|
@@ -126,9 +177,11 @@ export class SidecarProtocolClient {
|
|
|
126
177
|
}
|
|
127
178
|
}
|
|
128
179
|
this.closedError = error;
|
|
180
|
+
this.stopSilenceWatchdog();
|
|
129
181
|
this.rejectPending(error);
|
|
130
182
|
}
|
|
131
183
|
dispose() {
|
|
184
|
+
this.stopSilenceWatchdog();
|
|
132
185
|
this.frameTransport.dispose();
|
|
133
186
|
}
|
|
134
187
|
async writeFrame(frame) {
|
|
@@ -148,6 +201,14 @@ export class SidecarProtocolClient {
|
|
|
148
201
|
}
|
|
149
202
|
}
|
|
150
203
|
dispatchEvent(event) {
|
|
204
|
+
// Transport-level liveness beats from the sidecar. Their arrival already
|
|
205
|
+
// reset the silence watchdog at the frame layer; they carry no meaning
|
|
206
|
+
// for consumers and must never reach the bounded event buffer, where a
|
|
207
|
+
// long-idle VM would accumulate one every 10s until overflow.
|
|
208
|
+
if (event.payload.type === "structured" &&
|
|
209
|
+
event.payload.name === "heartbeat") {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
151
212
|
for (const listener of this.eventListeners) {
|
|
152
213
|
try {
|
|
153
214
|
listener(event);
|
|
@@ -95,7 +95,7 @@ export function fromGeneratedResponsePayload(payload) {
|
|
|
95
95
|
path: entry.path,
|
|
96
96
|
isDirectory: entry.isDirectory,
|
|
97
97
|
isSymbolicLink: entry.isSymbolicLink,
|
|
98
|
-
size:
|
|
98
|
+
size: entry.size,
|
|
99
99
|
})),
|
|
100
100
|
}
|
|
101
101
|
: {}),
|
package/dist/sidecar-errors.d.ts
CHANGED
|
@@ -8,6 +8,21 @@ export declare class SidecarProcessExited extends Error {
|
|
|
8
8
|
stderr: string;
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* The silence watchdog fired: the sidecar produced no protocol frames at all —
|
|
13
|
+
* not even its 10s liveness heartbeats — for the full silence window, so the
|
|
14
|
+
* process is dead or wedged (not merely busy: a busy sidecar still heartbeats
|
|
15
|
+
* from a dedicated thread). The host kills the sidecar and rejects every
|
|
16
|
+
* in-flight request with this error.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SidecarSilenceTimeout extends Error {
|
|
19
|
+
readonly silenceMs: number;
|
|
20
|
+
readonly stderr: string;
|
|
21
|
+
constructor(options: {
|
|
22
|
+
silenceMs: number;
|
|
23
|
+
stderr: string;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
11
26
|
export declare class SidecarProcessError extends Error {
|
|
12
27
|
readonly childError: Error;
|
|
13
28
|
readonly stderr: string;
|
package/dist/sidecar-errors.js
CHANGED
|
@@ -18,6 +18,23 @@ export class SidecarProcessExited extends Error {
|
|
|
18
18
|
this.stderr = options.stderr;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The silence watchdog fired: the sidecar produced no protocol frames at all —
|
|
23
|
+
* not even its 10s liveness heartbeats — for the full silence window, so the
|
|
24
|
+
* process is dead or wedged (not merely busy: a busy sidecar still heartbeats
|
|
25
|
+
* from a dedicated thread). The host kills the sidecar and rejects every
|
|
26
|
+
* in-flight request with this error.
|
|
27
|
+
*/
|
|
28
|
+
export class SidecarSilenceTimeout extends Error {
|
|
29
|
+
silenceMs;
|
|
30
|
+
stderr;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
super(`sidecar unresponsive: no protocol frames or heartbeats for ${Math.round(options.silenceMs)}ms; killing sidecar${formatSidecarStderrSuffix(options.stderr)}`);
|
|
33
|
+
this.name = "SidecarSilenceTimeout";
|
|
34
|
+
this.silenceMs = options.silenceMs;
|
|
35
|
+
this.stderr = options.stderr;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
export class SidecarProcessError extends Error {
|
|
22
39
|
childError;
|
|
23
40
|
stderr;
|
|
@@ -9,10 +9,9 @@ import type { LiveFilesystemOperation, LiveGuestRuntimeKind, LiveWasmPermissionT
|
|
|
9
9
|
import { type LiveEventFrame, type LiveSidecarRequestHandler, type LiveSidecarRequestFrame, type LiveSidecarResponseFrame, type ProtocolFramePayloadCodec } from "./protocol-frames.js";
|
|
10
10
|
import type { LiveGuestDirEntry } from "./response-payloads.js";
|
|
11
11
|
import { type LiveGuestFilesystemStat } from "./state.js";
|
|
12
|
-
export { SidecarProcessError, SidecarProcessExited, } from "./sidecar-errors.js";
|
|
12
|
+
export { SidecarProcessError, SidecarProcessExited, SidecarSilenceTimeout, } from "./sidecar-errors.js";
|
|
13
13
|
export { SidecarEventBufferOverflow } from "./event-buffer.js";
|
|
14
14
|
export { SidecarProcess as Sidecar };
|
|
15
|
-
export declare const NATIVE_SIDECAR_FRAME_TIMEOUT_MS = 120000;
|
|
16
15
|
type GuestRuntimeKind = Extract<LiveGuestRuntimeKind, "java_script" | "python" | "web_assembly">;
|
|
17
16
|
type WasmPermissionTier = LiveWasmPermissionTier;
|
|
18
17
|
export interface RootFilesystemEntry extends LiveRootFilesystemEntry {
|
|
@@ -105,20 +104,25 @@ export interface SidecarSpawnOptions {
|
|
|
105
104
|
cwd?: string;
|
|
106
105
|
command?: string;
|
|
107
106
|
args?: string[];
|
|
108
|
-
frameTimeoutMs?: number;
|
|
109
107
|
eventBufferCapacity?: number;
|
|
110
108
|
payloadCodec?: NativeTransportPayloadCodec;
|
|
109
|
+
/**
|
|
110
|
+
* Override the sidecar silence watchdog window (default 30s). Tests only —
|
|
111
|
+
* it is a fixed protocol constant paired with the sidecar's 10s heartbeat
|
|
112
|
+
* cadence, not an operator tunable.
|
|
113
|
+
*/
|
|
114
|
+
silenceTimeoutMs?: number;
|
|
111
115
|
}
|
|
112
116
|
export interface ResolvedSidecarSpawnOptions {
|
|
113
117
|
cwd?: string;
|
|
114
118
|
command?: string;
|
|
115
119
|
args: string[];
|
|
116
|
-
frameTimeoutMs: number;
|
|
117
120
|
eventBufferCapacity: number;
|
|
118
121
|
gracefulExitMs: number;
|
|
119
122
|
forceExitMs: number;
|
|
120
123
|
disposedErrorMessage: string;
|
|
121
124
|
payloadCodec: NativeTransportPayloadCodec;
|
|
125
|
+
silenceTimeoutMs?: number;
|
|
122
126
|
}
|
|
123
127
|
type SidecarProcessSpawnFactory = (options: ResolvedSidecarSpawnOptions) => SidecarProcessTransport;
|
|
124
128
|
export declare function registerSidecarProcessSpawnFactory(factory: SidecarProcessSpawnFactory): void;
|
package/dist/sidecar-process.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { decodeGuestFilesystemContent, encodeGuestFilesystemContent, } from "./filesystem.js";
|
|
2
2
|
import { SIDECAR_PROTOCOL_SCHEMA } from "./protocol-schema.js";
|
|
3
|
-
export { SidecarProcessError, SidecarProcessExited, } from "./sidecar-errors.js";
|
|
3
|
+
export { SidecarProcessError, SidecarProcessExited, SidecarSilenceTimeout, } from "./sidecar-errors.js";
|
|
4
4
|
export { SidecarEventBufferOverflow } from "./event-buffer.js";
|
|
5
5
|
// `Sidecar` is the public name for the native sidecar process client. The class
|
|
6
6
|
// is `SidecarProcess` internally; consumers import it as `Sidecar` via the
|
|
7
7
|
// `@rivet-dev/agentos-runtime-core/sidecar-client` subpath and the package root.
|
|
8
8
|
export { SidecarProcess as Sidecar };
|
|
9
9
|
const BRIDGE_CONTRACT_VERSION = 1;
|
|
10
|
-
export const NATIVE_SIDECAR_FRAME_TIMEOUT_MS = 120_000;
|
|
11
10
|
const DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY = 4_096;
|
|
12
11
|
const DEFAULT_SIDECAR_GRACEFUL_EXIT_MS = 5_000;
|
|
13
12
|
const DEFAULT_SIDECAR_FORCE_EXIT_MS = 2_000;
|
|
@@ -31,7 +30,7 @@ export class SidecarProcess {
|
|
|
31
30
|
command: options.command,
|
|
32
31
|
args: options.args ?? [],
|
|
33
32
|
cwd: options.cwd,
|
|
34
|
-
|
|
33
|
+
silenceTimeoutMs: options.silenceTimeoutMs,
|
|
35
34
|
eventBufferCapacity: options.eventBufferCapacity ?? DEFAULT_SIDECAR_EVENT_BUFFER_CAPACITY,
|
|
36
35
|
gracefulExitMs: DEFAULT_SIDECAR_GRACEFUL_EXIT_MS,
|
|
37
36
|
forceExitMs: DEFAULT_SIDECAR_FORCE_EXIT_MS,
|
package/dist/state.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as protocol from "./generated-protocol.js";
|
|
2
2
|
export interface LiveGuestFilesystemStat {
|
|
3
3
|
mode: number;
|
|
4
|
-
size:
|
|
5
|
-
blocks:
|
|
6
|
-
dev:
|
|
7
|
-
rdev:
|
|
4
|
+
size: bigint;
|
|
5
|
+
blocks: bigint;
|
|
6
|
+
dev: bigint;
|
|
7
|
+
rdev: bigint;
|
|
8
8
|
is_directory: boolean;
|
|
9
9
|
is_symbolic_link: boolean;
|
|
10
10
|
atime_ms: number;
|
|
11
11
|
mtime_ms: number;
|
|
12
12
|
ctime_ms: number;
|
|
13
13
|
birthtime_ms: number;
|
|
14
|
-
ino:
|
|
15
|
-
nlink:
|
|
14
|
+
ino: bigint;
|
|
15
|
+
nlink: bigint;
|
|
16
16
|
uid: number;
|
|
17
17
|
gid: number;
|
|
18
18
|
}
|
package/dist/state.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { bigIntToSafeNumber } from "./numbers.js";
|
|
2
1
|
import { fromGeneratedProcessSnapshotStatus } from "./protocol-maps.js";
|
|
3
2
|
export function fromGeneratedGuestFilesystemStat(stat) {
|
|
4
3
|
return {
|
|
5
4
|
mode: stat.mode,
|
|
6
|
-
size:
|
|
7
|
-
blocks:
|
|
8
|
-
dev:
|
|
9
|
-
rdev:
|
|
5
|
+
size: stat.size,
|
|
6
|
+
blocks: stat.blocks,
|
|
7
|
+
dev: stat.dev,
|
|
8
|
+
rdev: stat.rdev,
|
|
10
9
|
is_directory: stat.isDirectory,
|
|
11
10
|
is_symbolic_link: stat.isSymbolicLink,
|
|
12
|
-
atime_ms:
|
|
13
|
-
mtime_ms:
|
|
14
|
-
ctime_ms:
|
|
15
|
-
birthtime_ms:
|
|
16
|
-
ino:
|
|
17
|
-
nlink:
|
|
11
|
+
atime_ms: Number(stat.atimeMs),
|
|
12
|
+
mtime_ms: Number(stat.mtimeMs),
|
|
13
|
+
ctime_ms: Number(stat.ctimeMs),
|
|
14
|
+
birthtime_ms: Number(stat.birthtimeMs),
|
|
15
|
+
ino: stat.ino,
|
|
16
|
+
nlink: stat.nlink,
|
|
18
17
|
uid: stat.uid,
|
|
19
18
|
gid: stat.gid,
|
|
20
19
|
};
|
package/dist/test-runtime.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface VirtualDirEntry {
|
|
|
23
23
|
export interface VirtualStat {
|
|
24
24
|
mode: number;
|
|
25
25
|
size: number;
|
|
26
|
+
sizeExact?: bigint;
|
|
26
27
|
blocks: number;
|
|
27
28
|
dev: number;
|
|
28
29
|
rdev: number;
|
|
@@ -33,7 +34,9 @@ export interface VirtualStat {
|
|
|
33
34
|
ctimeMs: number;
|
|
34
35
|
birthtimeMs: number;
|
|
35
36
|
ino: number;
|
|
37
|
+
inoExact?: bigint;
|
|
36
38
|
nlink: number;
|
|
39
|
+
nlinkExact?: bigint;
|
|
37
40
|
uid: number;
|
|
38
41
|
gid: number;
|
|
39
42
|
}
|
package/dist/test-runtime.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as path from "node:path";
|
|
|
5
5
|
import * as posixPath from "node:path/posix";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import "./native-client.js";
|
|
8
|
-
import {
|
|
8
|
+
import { NativeSidecarKernelProxy, SidecarProcess, serializeMountConfigForSidecar, } from "./kernel-proxy.js";
|
|
9
9
|
import { resolvePublishedSidecarBinary } from "./binary.js";
|
|
10
10
|
import { findCargoBinary, resolveCargoBinary } from "./cargo.js";
|
|
11
11
|
export const AF_INET = 2;
|
|
@@ -2062,7 +2062,6 @@ class NativeKernel {
|
|
|
2062
2062
|
cwd: REPO_ROOT,
|
|
2063
2063
|
command: ensureNativeSidecarBinary(),
|
|
2064
2064
|
args: [],
|
|
2065
|
-
frameTimeoutMs: NATIVE_SIDECAR_FRAME_TIMEOUT_MS,
|
|
2066
2065
|
}));
|
|
2067
2066
|
const session = await this.measureBoot("session_open", () => client.authenticateAndOpenSession());
|
|
2068
2067
|
const vm = await this.measureBoot("vm_create", () => client.createVm(session, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivet-dev/agentos-runtime-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8-rc.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
"test": "vitest run"
|
|
193
193
|
},
|
|
194
194
|
"dependencies": {
|
|
195
|
-
"@rivet-dev/agentos-runtime-sidecar": "0.2.
|
|
195
|
+
"@rivet-dev/agentos-runtime-sidecar": "0.2.8-rc.1",
|
|
196
196
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
197
197
|
"zod": "^4.1.11"
|
|
198
198
|
},
|