@@ -42,6 +42,7 @@ import {
4242} from "../subagent/index.js" ;
4343import { getProcessAdmissionQueue } from "../subagent/admission.js" ;
4444import { disposeExecRuntime , formatCaughtError } from "./dispose.js" ;
45+ import { caughtDebug } from "../logging/caught.js" ;
4546import {
4647 EXEC_MCP_CONNECT_WAIT_MS ,
4748 EXEC_MCP_HANDSHAKE_TIMEOUT_MS ,
@@ -469,7 +470,10 @@ export async function runExec(config: Config): Promise<ExecResult> {
469470 priorState = prior ?. kind === "ok" ? prior . state : undefined ;
470471 } catch ( err ) {
471472 const message = formatCaughtError ( err ) ;
472- logger . error ( "exec setup failed: {error}" , { error : message } ) ;
473+ logger . error ( "exec setup failed: {error}" , {
474+ sessionId,
475+ error : message ,
476+ } ) ;
473477 stderr . write ( `Error: ${ message } \n` ) ;
474478 liveTelemetry . capture (
475479 "session_end" ,
@@ -623,11 +627,13 @@ export async function runExec(config: Config): Promise<ExecResult> {
623627
624628 try {
625629 // Pricing seed is optional for exec; continue without rates.
626- const inferenceDeps = await assembleInferenceBase ( ( err : unknown ) => {
627- logger . debug ( "seedPricingMetadataFromCache failed: {error}" , {
628- error : sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ,
629- } ) ;
630- } ) ;
630+ const inferenceDeps = await assembleInferenceBase (
631+ caughtDebug (
632+ logger ,
633+ "seedPricingMetadataFromCache failed" ,
634+ sanitizeExecDiagnostic ,
635+ ) ,
636+ ) ;
631637
632638 // One-shot migration only when the path-trust file is absent. Headless
633639 // exec has no frame to corrupt, so skipped members write straight to stderr.
@@ -1246,22 +1252,22 @@ export async function runExec(config: Config): Promise<ExecResult> {
12461252 // entry and would write the whole reply as a spurious partial.
12471253 // Dispose is a no-op on success and a real record only if a cycle
12481254 // died without a terminal event.
1249- await activeAgent . close ( ) . catch ( ( err : unknown ) => {
1250- logger . debug (
1251- "agent.close during successful-send teardown failed: {error}" ,
1252- {
1253- error : sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ,
1254- } ,
1255- ) ;
1256- } ) ;
1257- await streamPromise . catch ( ( err : unknown ) => {
1258- logger . debug (
1259- "stream drain during successful-send teardown failed: {error}" ,
1260- {
1261- error : sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ,
1262- } ,
1255+ await activeAgent
1256+ . close ( )
1257+ . catch (
1258+ caughtDebug (
1259+ logger ,
1260+ "agent.close during successful-send teardown failed" ,
1261+ sanitizeExecDiagnostic ,
1262+ ) ,
12631263 ) ;
1264- } ) ;
1264+ await streamPromise . catch (
1265+ caughtDebug (
1266+ logger ,
1267+ "stream drain during successful-send teardown failed" ,
1268+ sanitizeExecDiagnostic ,
1269+ ) ,
1270+ ) ;
12651271 await cycleRecorder . dispose ( "cancelled" ) ;
12661272 } else {
12671273 // Failed or aborted send: close() tears down stream consumers before
@@ -1270,22 +1276,22 @@ export async function runExec(config: Config): Promise<ExecResult> {
12701276 await cycleRecorder . dispose (
12711277 sendCompleted ? "cancelled" : "send-failed" ,
12721278 ) ;
1273- await activeAgent . close ( ) . catch ( ( err : unknown ) => {
1274- logger . debug (
1275- "agent.close during failed-send teardown failed: {error}" ,
1276- {
1277- error : sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ,
1278- } ,
1279- ) ;
1280- } ) ;
1281- await streamPromise . catch ( ( err : unknown ) => {
1282- logger . debug (
1283- "stream drain during failed-send teardown failed: {error}" ,
1284- {
1285- error : sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ,
1286- } ,
1279+ await activeAgent
1280+ . close ( )
1281+ . catch (
1282+ caughtDebug (
1283+ logger ,
1284+ "agent.close during failed-send teardown failed" ,
1285+ sanitizeExecDiagnostic ,
1286+ ) ,
12871287 ) ;
1288- } ) ;
1288+ await streamPromise . catch (
1289+ caughtDebug (
1290+ logger ,
1291+ "stream drain during failed-send teardown failed" ,
1292+ sanitizeExecDiagnostic ,
1293+ ) ,
1294+ ) ;
12891295 }
12901296 }
12911297
@@ -1379,7 +1385,10 @@ export async function runExec(config: Config): Promise<ExecResult> {
13791385 return result ;
13801386 } catch ( err ) {
13811387 const diagnosticMessage = sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ;
1382- logger . error ( "exec failed: {error}" , { error : diagnosticMessage } ) ;
1388+ logger . error ( "exec failed: {error}" , {
1389+ sessionId,
1390+ error : diagnosticMessage ,
1391+ } ) ;
13831392 const userMessage = sanitizeExecDiagnostic (
13841393 execUserFailureMessage (
13851394 config ,
@@ -1420,7 +1429,10 @@ export async function runExec(config: Config): Promise<ExecResult> {
14201429 } ) ;
14211430 } catch ( err : unknown ) {
14221431 const message = sanitizeExecDiagnostic ( formatCaughtError ( err ) ) ;
1423- logger . error ( "runtime dispose failed: {error}" , { error : message } ) ;
1432+ logger . error ( "runtime dispose failed: {error}" , {
1433+ sessionId,
1434+ error : message ,
1435+ } ) ;
14241436 stderr . write ( `Error: runtime dispose failed: ${ message } \n` ) ;
14251437 if ( result !== undefined ) {
14261438 result . exitCode = 1 ;
0 commit comments