Skip to content

The agent that grows with you

fix(tui): count streamed frames as heartbeat liveness

Konstantin Khlopkov1cf8a9fb417f
diff --git a/apps/shared/src/json-rpc-channel.test.ts b/apps/shared/src/json-rpc-channel.test.ts
index adc1f3b8c2f..7fc1980b083 100644
--- a/apps/shared/src/json-rpc-channel.test.ts
+++ b/apps/shared/src/json-rpc-channel.test.ts
@@ -118,10 +118,11 @@ describe('JsonRpcRequestChannel', () => {
}
})
- // TUI contract: a backend whose request loop is wedged may still stream
- // deltas; only a pong (or a response to our own request) proves it can
- // answer, so notifications alone must NOT keep the transport alive.
- it("'response' liveness (default, TUI): unanswered pings fail the heartbeat even while deltas stream", async () => {
+ // 'response' mode itself stays available (explicit opt-in): a caller that
+ // wants only a pong (or a response to its own request) to prove the
+ // backend can answer keeps that stricter contract.
+ it("'response' liveness (explicit opt-in): unanswered pings fail the heartbeat even while deltas stream", async () => {
+ // unchanged semantics for any caller that still chooses 'response'
vi.useFakeTimers()
try {
diff --git a/apps/shared/src/json-rpc-gateway.ts b/apps/shared/src/json-rpc-gateway.ts
index 676b8ab4319..a9519a30f50 100644
--- a/apps/shared/src/json-rpc-gateway.ts
+++ b/apps/shared/src/json-rpc-gateway.ts
@@ -159,8 +159,9 @@ export class JsonRpcGatewayClient {
createRequestId: this.options.createRequestId,
heartbeatDeadlineMs: this.options.heartbeatDeadlineMs,
heartbeatIntervalMs: this.options.heartbeatIntervalMs,
- // Desktop/web have always counted any inbound frame as liveness; the
- // TUI (stdio/attach owner) keeps its stricter pong-based contract.
+ // Desktop/web and the TUI alike count any inbound frame as liveness
+ // (#115251): streamed deltas are life; only a silent drop trips the
+ // deadline.
heartbeatLiveness: 'any-inbound',
onEvent: event => this.handleEvent(event),
onHeartbeatFailure: error => this.invalidate(error.message),
diff --git a/ui-tui/src/__tests__/gatewayClientHeartbeatLiveness.test.ts b/ui-tui/src/__tests__/gatewayClientHeartbeatLiveness.test.ts
new file mode 100644
index 00000000000..a91421c5bb1
--- /dev/null
+++ b/ui-tui/src/__tests__/gatewayClientHeartbeatLiveness.test.ts
@@ -0,0 +1,23 @@
+import type { JsonRpcRequestChannel } from '@hermes/shared/json-rpc-channel'
+import { describe, expect, it } from 'vitest'
+
+import { GatewayClient } from '../gatewayClient.js'
+
+// The TUI channel counts streamed deltas as liveness (#115251): a turn that
+// streams a frame per second for minutes must never trip the 45s deadline,
+// while a socket gone fully silent still fails. This pins the wiring option
+// on the only construction site outside @hermes/shared.
+describe('GatewayClient heartbeat liveness wiring', () => {
+ it('constructs the channel with heartbeatLiveness any-inbound', () => {
+ const client = new GatewayClient()
+
+ try {
+ const channel = (client as unknown as { channel: JsonRpcRequestChannel }).channel
+ const liveness = (channel as unknown as { options: { heartbeatLiveness?: string } }).options.heartbeatLiveness
+
+ expect(liveness).toBe('any-inbound')
+ } finally {
+ client.kill()
+ }
+ })
+})
diff --git a/ui-tui/src/gatewayClient.ts b/ui-tui/src/gatewayClient.ts
index 62754317e31..cdba97ff312 100644
--- a/ui-tui/src/gatewayClient.ts
+++ b/ui-tui/src/gatewayClient.ts
@@ -133,6 +133,11 @@ export class GatewayClient extends EventEmitter {
// only owns the two transports (child stdio, attached socket) and the
// buffered-event replay that Ink's mount order needs.
private readonly channel = new JsonRpcRequestChannel({
+ // A mid-turn socket streams deltas every second; killing the only
+ // transport that carried live traffic split sessions that completed
+ // server-side (#115251). Count any inbound frame as liveness, exactly
+ // like the desktop/web client; a silent drop still trips the deadline.
+ heartbeatLiveness: 'any-inbound',
onEvent: ev => this.publish(ev as AnyGatewayEvent),
onHeartbeatFailure: () => this.onHeartbeatFailure(),
onRequestHandlerError: (error, req) =>