Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(review): remove mutating probe, fence HCC poll, and address all review findings

Alfredo Lopez53040e0872f2
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index d246d37fa..6b0b4c17b 100644
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@ -9,7 +9,7 @@ export type ReleaseManifest = {
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.9.0',
externalRestApiVersion: '0.1.84',
- rpcProxyVersion: '0.1.93',
+ rpcProxyVersion: '0.1.94',
desktopVersion: '0.9.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 0dfe15f5a..9921b0fb3 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.357",
+ "version": "0.1.358",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.357",
+ "version": "0.1.358",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 1acc6e655..a7da3f67a 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.357",
+ "version": "0.1.358",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/hostReconciler.ts b/host-context-controller/src/hostReconciler.ts
index 8591a1f56..74f1a3511 100644
--- a/host-context-controller/src/hostReconciler.ts
+++ b/host-context-controller/src/hostReconciler.ts
@@ -5078,7 +5078,10 @@ export class HostReconciler {
ready: ready && npFailures.length === 0,
message,
})
- if (!ready && !suspended) {
+ // Do not schedule a readiness poll when NetworkPolicy has degraded the
+ // runtime: the same-generation poll would overwrite the degraded verdict
+ // with "Running" once the Deployment alone becomes Ready.
+ if (!ready && !suspended && npFailures.length === 0) {
this.pollReadiness(host.name, host.namespace)
}
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index 0ea81ec4f..fa235616b 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.93",
+ "version": "0.1.94",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.93",
+ "version": "0.1.94",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index 6c24211c3..cbaa8cf89 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.93",
+ "version": "0.1.94",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {
diff --git a/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts b/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts
index f7309d4df..cbe9ca51e 100644
--- a/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts
+++ b/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts
@@ -113,51 +113,29 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
const response = await postMessage(makeApp()).expect(200)
expect(response.body).toEqual({ success: true, taskId: 't-1' })
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(2)
+ expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1)
expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledWith('chatllm', 'token')
expect(serviceMock.forwardHostMessageToHost).toHaveBeenCalledTimes(2)
+ expect(serviceMock.forwardHostMessageToHost.mock.calls[0][2]).toEqual({ async: false })
})
- it('starts wake after a short availability probe and admits after the Host becomes ready', async () => {
- let firstForwardStarted!: () => void
- const firstForward = new Promise<void>(resolve => {
- firstForwardStarted = resolve
- })
- let upstreamAdmits = false
- const availabilityTimeout = new Error('Initial host availability probe timed out')
- availabilityTimeout.name = 'HostAvailabilityProbeTimeoutError'
+ it('uses the normal POST timeout before wake-hold retries until the suspended Host admits', async () => {
serviceMock.forwardHostMessageToHost
- .mockImplementationOnce(
- (_host: unknown, _body: unknown, options: { timeoutMs?: number }) =>
- new Promise((_resolve, reject) => {
- vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
- expect(options.timeoutMs).toBe(750)
- firstForwardStarted()
- setTimeout(() => reject(availabilityTimeout), options.timeoutMs)
- })
- )
- .mockImplementation(async () => {
- if (!upstreamAdmits) throw hostDownError()
- return { success: true, taskId: 't-delayed' }
- })
+ .mockRejectedValueOnce(hostDownError()) // Initial POST fails quickly on the suspended Host.
+ .mockRejectedValueOnce(hostDownError()) // Wake was accepted, but admission is not ready yet.
+ .mockResolvedValueOnce({ success: true, taskId: 't-delayed' })
controlApiMock.requestHostWakeFromControlApi.mockResolvedValue({
kind: 'active',
wakeGeneration: null,
})
- const responsePromise = postMessage(makeApp())
- .expect(200)
- .then(response => response)
- await firstForward
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1)
- await vi.advanceTimersByTimeAsync(750)
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(2)
- expect(serviceMock.forwardHostMessageToHost).toHaveBeenCalledTimes(2)
- await vi.advanceTimersByTimeAsync(1_500)
- upstreamAdmits = true
- await vi.advanceTimersByTimeAsync(250)
- const response = await responsePromise
+ const response = await postMessage(makeApp()).expect(200)
+
expect(response.body).toEqual({ success: true, taskId: 't-delayed' })
+ expect(serviceMock.forwardHostMessageToHost).toHaveBeenCalledTimes(3)
+ // The first POST omits timeoutMs so the service applies its normal full upstream timeout.
+ expect(serviceMock.forwardHostMessageToHost.mock.calls[0][2]).toEqual({ async: false })
+ expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1)
expect(serviceMock.forwardHostMessageToHost.mock.calls[0][1]).toBe(
serviceMock.forwardHostMessageToHost.mock.calls.at(-1)![1]
)
@@ -268,7 +246,8 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
const response = await postMessage(makeApp()).expect(200)
expect(response.body).toEqual({ success: true, taskId: 't-2' })
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(2)
+ expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1)
+ expect(serviceMock.forwardHostMessageToHost.mock.calls[0][2]).toEqual({ async: false })
})
it('drain-cancel bounce resolves within the short retry schedule (250ms then 1s)', async () => {
@@ -295,7 +274,7 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
expect(response.body).toEqual({ error: 'Upstream host unavailable' })
expect(serviceMock.forwardHostMessageToHost.mock.calls[0][2]).toEqual({ async: false })
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(2)
+ expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1)
})
it('404 unknown host maps to a 404 for the caller', async () => {
@@ -358,7 +337,7 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
const response = await postMessage(makeApp()).expect(502)
expect(response.body).toEqual({ error: 'Upstream host unavailable' })
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1) // statelessness check only
+ expect(controlApiMock.requestHostWakeFromControlApi).not.toHaveBeenCalled()
})
it('an upstream AbortError keeps the 504 path without entering the wake hold', async () => {
@@ -369,7 +348,7 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
const response = await postMessage(makeApp()).expect(504)
expect(response.body).toEqual({ error: 'Gateway Timeout' })
- expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1) // statelessness check only
+ expect(controlApiMock.requestHostWakeFromControlApi).not.toHaveBeenCalled()
})
it('a token without wake scope keeps the original full upstream timeout', async () => {
@@ -388,15 +367,13 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
expect(controlApiMock.requestHostWakeFromControlApi).not.toHaveBeenCalled()
})
- it('uses the full upstream timeout when statelessness cannot be confirmed', async () => {
- controlApiMock.requestHostWakeFromControlApi.mockRejectedValue(
- new Error('wake API unavailable')
- )
+ it('uses the normal upstream timeout for a healthy POST without requesting a wake', async () => {
serviceMock.forwardHostMessageToHost.mockResolvedValue({ success: true, taskId: 't-stateful' })
await postMessage(makeApp()).expect(200)
expect(serviceMock.forwardHostMessageToHost.mock.calls[0][2]).toEqual({ async: false })
+ expect(controlApiMock.requestHostWakeFromControlApi).not.toHaveBeenCalled()
})
})
diff --git a/rpc-proxy/src/routes/rpc.ts b/rpc-proxy/src/routes/rpc.ts
index 8bf69f94c..57dc46258 100644
--- a/rpc-proxy/src/routes/rpc.ts
+++ b/rpc-proxy/src/routes/rpc.ts
@@ -48,7 +48,6 @@ const RFC1123_RE = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/
const SESSIONS_LIMIT_CAP = 100
const MESSAGES_LIMIT_CAP = 200
/** A confirmed stateless host may be suspended and spend seconds failing DNS/connect. */
-const MESSAGE_AVAILABILITY_PROBE_MS = 750
function isSafeUpstreamPathSegment(value: string): boolean {
return (
@@ -443,28 +442,14 @@ export function createRpcRouter(): Router {
)
let upstreamResponse: Record<string, unknown> | null = null
const wakeCapable = isWakeCapable(auth, hostRef, Date.now())
- let statelessHostConfirmed = false
- if (wakeCapable) {
- try {
- const wakeStatus = await requestHostWakeFromControlApi(hostRef, rpcAccessToken)
- // The wake API checks lifecycle.spec.stateless before returning either
- // status. Unknown, rate-limited, unauthorized, and failed checks do not
- // authorize a short timeout for a mutating message request.
- statelessHostConfirmed =
- wakeStatus.kind === 'active' || wakeStatus.kind === 'wake-requested'
- } catch {
- // A failed statelessness check must not turn a healthy stateful send
- // into a short, aborting POST. The normal timeout still allows the
- // existing wake path to handle a genuine upstream availability error.
- }
- }
try {
- // This is a mutating POST. Its short availability probe is safe only
- // after the wake API confirms a stateless Host, where deliveryMessageId
- // lets mcp-host deduplicate an interrupted send and its retry.
+ // Always use the configured upstream timeout for the first POST.
+ // A separate statelessness pre-check would double-charge the
+ // rate-limited wake endpoint and risk aborting a healthy send.
+ // The wake path below already checks statelessness when a
+ // connection-level failure triggers it.
upstreamResponse = await forwardHostMessageToHost(host, forwardedBody, {
async: isAsync,
- ...(statelessHostConfirmed ? { timeoutMs: MESSAGE_AVAILABILITY_PROBE_MS } : {}),
})
} catch (error) {
console.warn(
@@ -472,12 +457,7 @@ export function createRpcRouter(): Router {
error instanceof Error ? error.message : String(error)
}`
)
- if (
- isWakeEligibleHostError(error) ||
- (wakeCapable &&
- error instanceof Error &&
- error.name === 'HostAvailabilityProbeTimeoutError')
- ) {
+ if (isWakeEligibleHostError(error)) {
// Stateless wake-and-hold: a down or draining host triggers a
// control-api wake (and possibly a bounded hold) instead of the
// generic 502. Non-stateless hosts fall back to the legacy path.
diff --git a/rpc-proxy/src/services/wakeAndHold.ts b/rpc-proxy/src/services/wakeAndHold.ts
index d4c885f33..fd6d67180 100644
--- a/rpc-proxy/src/services/wakeAndHold.ts
+++ b/rpc-proxy/src/services/wakeAndHold.ts
@@ -352,6 +352,14 @@ export class WakeAndHoldCoordinator {
// bounded by the per-waiter deadlines and the entry TTL.
return
}
+ await this.processWakeResponse(entry, response, options)
+ }
+
+ private async processWakeResponse(
+ entry: HostWakeEntry,
+ response: HostWakeApiResponse,
+ options: { initial: boolean }
+ ): Promise<void> {
if (entry.settled) {
console.debug(
`[RPC_PROXY] late wake-hold artifact ignored (already resolved) host=${entry.hostRef} artifact=wake-response kind=${response.kind}`