Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions hermes-plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,14 @@ def ensure_origin(sidecar: Dict[str, str]) -> Optional[str]:
deadline = time.monotonic() + SPAWN_WAIT_S
while time.monotonic() < deadline:
inst = read_instance_file()
if inst and inst.get("launch_token") == token and probe_proxy(inst["origin"]):
_state.update(origin=inst["origin"], mode="spawn")
return inst["origin"]
candidates = ([inst] if inst else []) + read_registry_entries()
for candidate in candidates:
if candidate.get("launch_token") != token:
continue
if not pid_alive(candidate.get("pid")) or not probe_proxy(candidate["origin"]):
continue
_state.update(origin=candidate["origin"], mode="spawn", instance_id=candidate["instance_id"])
return candidate["origin"]
if child.poll() is not None:
logger.warning("billion-context: proxy child exited before becoming healthy "
"(code %s); log: %s", child.returncode,
Expand Down
36 changes: 36 additions & 0 deletions tests/hermes-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,29 @@ elif SCENARIO == "no-sidecar":
elif SCENARIO == "spawn-fail":
install_sidecar(True)
mod.register(ctx)
elif SCENARIO.startswith("spawn-registry-"):
install_sidecar(False)
class Child:
returncode = None
def poll(self):
return None
def terminate(self):
self.returncode = -15
child = Child()
def spawn(sidecar, port, token):
own = inst_rec(False, token=token if SCENARIO != "spawn-registry-wrong-token" else "foreign")
own["instanceId"] = "own-child"
if SCENARIO == "spawn-registry-dead":
own["pid"] = -1
write_registry("own-child", own)
write_origin(inst_rec(False, token="foreign", instance_id="last-writer"))
return child
mod._spawn_child = spawn
mod.pid_alive = lambda pid: pid == os.getpid()
mod.SPAWN_WAIT_S = 0.3
origin = mod.ensure_origin(mod.load_sidecar())
out["env_before_ready"] = origin
out["state_after_fail"] = "terminated" if child.returncode == -15 else "running"
elif SCENARIO.startswith("attach-window"):
# #3261: the host knows the model window (context_length_cache.yaml) — verify it now
# rides both report channels; the ambiguous leg pins "no guess" on conflicting entries.
Expand Down Expand Up @@ -679,6 +702,8 @@ print(json.dumps(out))
`;

interface DriverOut {
env_before_ready?: string | null;
state_after_fail?: string;
scenario: string;
origin: string;
pid: number;
Expand Down Expand Up @@ -1044,6 +1069,17 @@ describe("python plugin runtime (subprocess)", () => {
assert.equal(out!.env_https_proxy, null);
});

for (const scenario of ["spawn-registry-ready", "spawn-registry-wrong-token", "spawn-registry-dead"]) {
test(`${scenario}: spawn readiness survives a foreign proxy-origin without accepting foreign or dead entries`, () => {
if (!PY) return;
const { out, err } = runDriver(scenario);
assert.ok(out, err);
const ready = scenario === "spawn-registry-ready";
assert.equal(out.env_before_ready, ready ? out.origin : null);
assert.equal(out.state_after_fail, ready ? "running" : "terminated");
});
}

test("spawn failure: child dies -> inert, env untouched, starting marker cleaned up", () => {
if (!PY) {
console.warn("skip: no python3/python interpreter on this machine (hermes requires Python 3.11+)");
Expand Down
Loading