UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

50 lines • 2.39 kB
import { busyLegacyHostDetail, describeSessions, provenLegacyOwner } from "./host-legacy.js"; import { holdSessionCount } from "./host-probe.js"; import { startSuccessor } from "./host-successor.js"; /** One session count; an unregistered host is counted twice (before the swap and over the held connection after). */ const SESSION_COUNT_TIMEOUT_MS = 10_000; export async function handoffUnregisteredHost(options, paths, host) { const counted = await holdSessionCount(options.socket, SESSION_COUNT_TIMEOUT_MS); try { const legacy = await provenLegacyOwner(paths, options.socket); const sessions = counted?.sessions; if (sessions !== 0) { if (legacy !== undefined) { return { action: "refuse", reason: "legacy_host", upgradeable: true, detail: busyLegacyHostDetail(legacy.pid, options.socket, sessions), }; } return { action: "refuse", reason: "unknown_owner", upgradeable: true, detail: `${options.socket} has no provable owner and holds ${describeSessions(sessions)}; it is never signalled - let that work finish, then retry`, }; } const result = await startSuccessor({ options, paths, host, owner: legacy, drainGate: async () => (await counted?.recount(SESSION_COUNT_TIMEOUT_MS)) === 0, }); if (result.action === "handoff" && legacy === undefined) warnUnsignalledPredecessor(options.socket, host); return result; } finally { counted?.close(); } } /** * The one record of a predecessor nobody could prove, on the caller's stderr: the endpoint's log belongs * to the generations writing it. Its pid is not known: no record proves it, and a Unix socket's peer * credentials are not readable from this runtime. */ function warnUnsignalledPredecessor(socket, host) { process.stderr.write(`generation handoff: no provable owner for ${socket}; the host it replaced (instance ${host.instanceId ?? "unknown"}, engine ${host.engineVersion ?? "unknown"}) listed 0 sessions and was not signalled; it drains itself on losing the public socket\n`); } //# sourceMappingURL=host-handoff-unregistered.js.map