Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions src/lib/hermes-tool-gateway-broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const HERMES_TOOL_GATEWAY_CONTROL_CONTRACT_PATH = path.join(
);
const HERMES_TOOL_GATEWAY_RUNTIME_MISMATCH_RECOVERY =
"Reauthorize every managed-tool Hermes sandbox, then retry.";
const HERMES_TOOL_GATEWAY_UNOWNED_LISTENER_RECOVERY =
"Stop the process holding that port, then retry.";
const HERMES_TOOL_GATEWAY_CONTROL_CLIENT_SOURCE = [
'const http = require("node:http");',
"const [socketPath, route, timeoutValue] = process.argv.slice(1);",
Expand Down Expand Up @@ -739,7 +741,22 @@ function ensureHermesToolGatewayBroker(options = {}) {
const hashMatches = readBrokerHash() === desiredHash;
const pid = readPid();
const currentBrokerOwned = isHermesToolGatewayBrokerProcess(pid) || brokerStartedThisRun;
const currentBrokerHealthy = currentBrokerOwned && isHermesToolGatewayBrokerHealthy();
const brokerHealthy = isHermesToolGatewayBrokerHealthy();
const currentBrokerHealthy = currentBrokerOwned && brokerHealthy;
// `/health` is unauthenticated on a fixed port, so reachability proves
// liveness and never identity. Refuse before any path can adopt, restart
// around, or stage credentials against a listener NemoClaw cannot prove it
// owns. The clone preflight already rejects this state; every entry point has
// to agree, because a single adopting path latches `brokerStartedThisRun` and
// thereby satisfies the ownership test for the rest of the process.
if (brokerHealthy && !currentBrokerOwned) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
console.error(
"Hermes managed-tool broker health endpoint is not owned by NemoClaw; " +
`refusing to reuse the listener on port ${HERMES_TOOL_GATEWAY_PORT}. ` +
HERMES_TOOL_GATEWAY_UNOWNED_LISTENER_RECOVERY,
);
return false;
}
if (options.startWithoutCredential) {
if (currentBrokerHealthy) {
return hashMatches && fs.existsSync(HERMES_TOOL_GATEWAY_CONTROL_SOCKET_PATH);
Expand Down Expand Up @@ -799,24 +816,9 @@ function ensureHermesToolGatewayBroker(options = {}) {
return false;
}

if (
!options.forceRestart &&
hashMatches &&
brokerStartedThisRun &&
isHermesToolGatewayBrokerHealthy()
) {
return true;
}
if (
!options.forceRestart &&
hashMatches &&
isHermesToolGatewayBrokerProcess(pid) &&
isHermesToolGatewayBrokerHealthy()
) {
brokerStartedThisRun = true;
return true;
}
if (!options.forceRestart && hashMatches && isHermesToolGatewayBrokerHealthy()) {
// `currentBrokerHealthy` already requires ownership, covering both proofs the
// three former branches tested separately, so reuse is one condition.
if (!options.forceRestart && hashMatches && currentBrokerHealthy) {
brokerStartedThisRun = true;
return true;
}
Expand Down
Loading
Loading