fix: forward resolved session key in agent delivery (follow-up #27584 by @qualiobra)

Co-authored-by: Lucas Teixeira Campos Araujo <lucas@MacBook-Pro-de-Lucas.local>
This commit is contained in:
Peter Steinberger
2026-02-26 21:14:03 +00:00
parent eaa9e1c661
commit 7ef6623bf3
2 changed files with 12 additions and 6 deletions

View File

@@ -27,9 +27,9 @@ type RunResult = Awaited<
const NESTED_LOG_PREFIX = "[agent:nested]";
function formatNestedLogPrefix(opts: AgentCommandOpts): string {
function formatNestedLogPrefix(opts: AgentCommandOpts, sessionKey?: string): string {
const parts = [NESTED_LOG_PREFIX];
const session = opts.sessionKey ?? opts.sessionId;
const session = sessionKey ?? opts.sessionKey ?? opts.sessionId;
if (session) {
parts.push(`session=${session}`);
}
@@ -49,8 +49,13 @@ function formatNestedLogPrefix(opts: AgentCommandOpts): string {
return parts.join(" ");
}
function logNestedOutput(runtime: RuntimeEnv, opts: AgentCommandOpts, output: string) {
const prefix = formatNestedLogPrefix(opts);
function logNestedOutput(
runtime: RuntimeEnv,
opts: AgentCommandOpts,
output: string,
sessionKey?: string,
) {
const prefix = formatNestedLogPrefix(opts, sessionKey);
for (const line of output.split(/\r?\n/)) {
if (!line) {
continue;
@@ -70,6 +75,7 @@ export async function deliverAgentCommandResult(params: {
payloads: RunResult["payloads"];
}) {
const { cfg, deps, runtime, opts, outboundSession, sessionEntry, payloads, result } = params;
const effectiveSessionKey = outboundSession?.key ?? opts.sessionKey;
const deliver = opts.deliver === true;
const bestEffortDeliver = opts.bestEffortDeliver === true;
const turnSourceChannel = opts.runContext?.messageChannel ?? opts.messageChannel;
@@ -201,7 +207,7 @@ export async function deliverAgentCommandResult(params: {
return;
}
if (opts.lane === AGENT_LANE_NESTED) {
logNestedOutput(runtime, opts, output);
logNestedOutput(runtime, opts, output, effectiveSessionKey);
return;
}
runtime.log(output);