fix: guard threadId with same session check as deliveryContext in restart

opts.agentThreadId belongs to the current agent's thread. When the
restart action targets a different sessionKey, forwarding it into the
sentinel would cause scheduleRestartSentinelWake to deliver the
post-restart reply to the wrong thread.

Apply the same isTargetingOtherSession guard used for deliveryContext:
only take opts.agentThreadId when the restart targets the current
session; otherwise use extracted.threadId from extractDeliveryInfo,
which correctly derives threadId from the target session key.
This commit is contained in:
Bryan Marty 2026-03-04 18:17:59 +00:00
parent 292546cb09
commit 331f09b82d
No known key found for this signature in database

View File

@ -129,8 +129,14 @@ export function createGatewayTool(opts?: {
: undefined;
const extracted = extractDeliveryInfo(sessionKey);
const deliveryContext = liveContext ?? extracted.deliveryContext;
// Guard threadId with the same session check as deliveryContext. When
// targeting another session, opts.agentThreadId belongs to the current
// session's thread and must not be written into the sentinel — it would
// cause scheduleRestartSentinelWake to deliver to the wrong thread.
const threadId =
opts?.agentThreadId != null ? String(opts.agentThreadId) : extracted.threadId;
!isTargetingOtherSession && opts?.agentThreadId != null
? String(opts.agentThreadId)
: extracted.threadId;
const payload: RestartSentinelPayload = {
kind: "restart",
status: "ok",