fix: restore remote conversation recovery and clean obsolete agents
Wait for model delivery acknowledgements before completing remote prompts and preserve completed outcomes when idle Runtime cleanup fails. Explicit messages after an unknown outcome now open a fresh binding with history instead of reusing the failed session; recovery remains attach-only. Run obsolete payload cleanup through the current Agent after activation, retaining history and unresolved process ownership. Live legacy daemons and shared Runtime versions remain deferred. Includes focused regressions, local OpenCode simulation, and isolated Linux validation evidence. Typecheck and lint passed; the full test run timed out. Release note: Remote conversations can continue after an uncertain result, and completed answers no longer fail solely because Runtime cleanup fails. Updates remove verified inactive Agent payloads and owned orphan processes while retaining active or uncertain installations and conversation history.
This commit is contained in:
@@ -159,6 +159,7 @@ export class ModelBridgeBrokerServer {
|
||||
readonly #maximumConnections: number
|
||||
readonly #requestTimeoutMs: number
|
||||
readonly #connections = new Set<Socket>()
|
||||
readonly #requests = new Set<Promise<void>>()
|
||||
#server?: Server
|
||||
#socketIdentity?: FileIdentity
|
||||
#closing = false
|
||||
@@ -227,7 +228,9 @@ export class ModelBridgeBrokerServer {
|
||||
socket.once('close', () => {
|
||||
this.#connections.delete(socket)
|
||||
})
|
||||
void this.#serveOne(socket)
|
||||
const request = this.#serveOne(socket)
|
||||
this.#requests.add(request)
|
||||
void request.finally(() => this.#requests.delete(request))
|
||||
}
|
||||
)
|
||||
this.#server = server
|
||||
@@ -249,12 +252,12 @@ export class ModelBridgeBrokerServer {
|
||||
}
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
async close(options: { waitForDelivery?: boolean } = {}): Promise<void> {
|
||||
if (this.#closePromise !== undefined) {
|
||||
await this.#closePromise
|
||||
return
|
||||
}
|
||||
const closePromise = this.#close()
|
||||
const closePromise = this.#close(options.waitForDelivery === true)
|
||||
this.#closePromise = closePromise
|
||||
try {
|
||||
await closePromise
|
||||
@@ -265,20 +268,31 @@ export class ModelBridgeBrokerServer {
|
||||
}
|
||||
}
|
||||
|
||||
async #close(): Promise<void> {
|
||||
async #close(waitForDelivery: boolean): Promise<void> {
|
||||
const server = this.#server
|
||||
this.#server = undefined
|
||||
this.#closing = true
|
||||
try {
|
||||
for (const connection of this.#connections) {
|
||||
connection.destroy()
|
||||
try {
|
||||
if (waitForDelivery) {
|
||||
// Runtime can finish its prompt before the helper's delivery ACK arrives.
|
||||
await raceWithAbort(
|
||||
Promise.all([...this.#requests]),
|
||||
AbortSignal.timeout(CLOSE_TIMEOUT_MS)
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
for (const connection of this.#connections) {
|
||||
connection.destroy()
|
||||
}
|
||||
await settleWithin(
|
||||
Promise.all([
|
||||
server === undefined ? Promise.resolve() : closeServer(server),
|
||||
...this.#requests
|
||||
]),
|
||||
CLOSE_TIMEOUT_MS
|
||||
)
|
||||
}
|
||||
await settleWithin(
|
||||
server === undefined
|
||||
? Promise.resolve()
|
||||
: closeServer(server),
|
||||
CLOSE_TIMEOUT_MS
|
||||
)
|
||||
} finally {
|
||||
this.#connections.clear()
|
||||
removeSocketIfIdentityMatches(
|
||||
|
||||
Reference in New Issue
Block a user