@@ -130,6 +130,7 @@ interface SseController {
130130
131131interface ActiveSession {
132132 payload : JwtPayload ;
133+ acpSessionId : string ;
133134 acpConnection : InProcessAcpConnection ;
134135 clientConnection : ClientSideConnection ;
135136 treeTracker : TreeTracker ;
@@ -409,7 +410,7 @@ export class AgentServer {
409410 ) ;
410411
411412 const result = await this . session . clientConnection . prompt ( {
412- sessionId : this . session . payload . run_id ,
413+ sessionId : this . session . acpSessionId ,
413414 prompt : [ { type : "text" , text : content } ] ,
414415 } ) ;
415416
@@ -418,9 +419,11 @@ export class AgentServer {
418419
419420 case POSTHOG_NOTIFICATIONS . CANCEL :
420421 case "cancel" : {
421- this . logger . info ( "Cancel requested" ) ;
422+ this . logger . info ( "Cancel requested" , {
423+ acpSessionId : this . session . acpSessionId ,
424+ } ) ;
422425 await this . session . clientConnection . cancel ( {
423- sessionId : this . session . payload . run_id ,
426+ sessionId : this . session . acpSessionId ,
424427 } ) ;
425428 return { cancelled : true } ;
426429 }
@@ -515,7 +518,7 @@ export class AgentServer {
515518 clientCapabilities : { } ,
516519 } ) ;
517520
518- await clientConnection . newSession ( {
521+ const sessionResponse = await clientConnection . newSession ( {
519522 cwd : this . config . repositoryPath ,
520523 mcpServers : [ ] ,
521524 _meta : {
@@ -525,8 +528,15 @@ export class AgentServer {
525528 } ,
526529 } ) ;
527530
531+ const acpSessionId = sessionResponse . sessionId ;
532+ this . logger . info ( "ACP session created" , {
533+ acpSessionId,
534+ runId : payload . run_id ,
535+ } ) ;
536+
528537 this . session = {
529538 payload,
539+ acpSessionId,
530540 acpConnection,
531541 clientConnection,
532542 treeTracker,
@@ -567,33 +577,19 @@ export class AgentServer {
567577 } ) ;
568578
569579 const result = await this . session . clientConnection . prompt ( {
570- sessionId : payload . run_id ,
580+ sessionId : this . session . acpSessionId ,
571581 prompt : [ { type : "text" , text : task . description } ] ,
572582 } ) ;
573583
574584 this . logger . info ( "Initial task message completed" , {
575585 stopReason : result . stopReason ,
576586 } ) ;
577-
578- // Only auto-complete for background mode
579- const mode = this . getEffectiveMode ( payload ) ;
580- if ( mode === "background" ) {
581- // Flush all pending session logs before signaling completion,
582- await this . session . logWriter . flushAll ( ) ;
583- await this . signalTaskComplete ( payload , result . stopReason ) ;
584- } else {
585- this . logger . info ( "Interactive mode - staying open for conversation" ) ;
586- }
587587 } catch ( error ) {
588588 this . logger . error ( "Failed to send initial task message" , error ) ;
589- // Signal failure for background mode
590- const mode = this . getEffectiveMode ( payload ) ;
591- if ( mode === "background" ) {
592- if ( this . session ) {
593- await this . session . logWriter . flushAll ( ) ;
594- }
595- await this . signalTaskComplete ( payload , "error" ) ;
589+ if ( this . session ) {
590+ await this . session . logWriter . flushAll ( ) ;
596591 }
592+ await this . signalTaskComplete ( payload , "error" ) ;
597593 }
598594 }
599595
@@ -630,12 +626,14 @@ Important:
630626 }
631627 }
632628
633- const status =
634- stopReason === "cancelled"
635- ? "cancelled"
636- : stopReason === "error"
637- ? "failed"
638- : "completed" ;
629+ if ( stopReason !== "error" ) {
630+ this . logger . info ( "Skipping status update for non-error stop reason" , {
631+ stopReason,
632+ } ) ;
633+ return ;
634+ }
635+
636+ const status = "failed" ;
639637
640638 try {
641639 await this . posthogAPI . updateTaskRun ( payload . task_id , payload . run_id , {
0 commit comments