fix bridge first-turn disconnect during Hermes bootstrap
This commit is contained in:
@@ -312,6 +312,24 @@ export function resolveAgentBridgeCommand(options: AgentBridgeManagerOptions = {
|
||||
return { command: fallback, argsPrefix: [], agentRoot, hermesHome }
|
||||
}
|
||||
|
||||
export function buildAgentBridgeLaunchArgs(command: BridgeCommand, script: string): string[] {
|
||||
const root = command.agentRoot
|
||||
if (!root || !existsSync(join(root, 'hermes_bootstrap.py'))) {
|
||||
return [...command.argsPrefix, script]
|
||||
}
|
||||
// Bootstrap may exec into Hermes's managed Python. Do that before the broker
|
||||
// forks workers or opens sockets, so the first request survives initialization.
|
||||
// Keep sys.argv[0] as -c until bootstrap returns so its relaunch replays this code.
|
||||
const bootstrap = [
|
||||
'import sys, runpy',
|
||||
'sys.path.insert(0, ' + JSON.stringify(root) + ')',
|
||||
'import hermes_bootstrap',
|
||||
'sys.argv = sys.argv[1:]',
|
||||
"runpy.run_path(sys.argv[0], run_name='__main__')",
|
||||
].join('; ')
|
||||
return [...command.argsPrefix, '-c', bootstrap, script]
|
||||
}
|
||||
|
||||
function bridgeScriptPath(): string {
|
||||
const candidates = [
|
||||
// Built server: dist/server/index.js -> dist/server/agent-bridge/python/hermes_bridge.py
|
||||
@@ -922,7 +940,7 @@ export class AgentBridgeManager {
|
||||
const script = bridgeScriptPath()
|
||||
const command = resolveAgentBridgeCommand(this.options)
|
||||
await this.prepareEndpoint()
|
||||
const args = [...command.argsPrefix, script, '--endpoint', this.endpoint]
|
||||
const args = [...buildAgentBridgeLaunchArgs(command, script), '--endpoint', this.endpoint]
|
||||
const agentRoot = command.agentRoot
|
||||
const hermesHome = command.hermesHome
|
||||
if (agentRoot) args.push('--agent-root', agentRoot)
|
||||
|
||||
Reference in New Issue
Block a user