@@ -90,10 +90,20 @@ class TerminalSubprocessCheckError extends Schema.TaggedErrorClass<TerminalSubpr
9090 {
9191 cause : Schema . optional ( Schema . Defect ( ) ) ,
9292 command : Schema . Literals ( [ "powershell" , "ps" ] ) ,
93+ exitCode : Schema . optional ( Schema . NullOr ( Schema . Number ) ) ,
94+ timedOut : Schema . optional ( Schema . Boolean ) ,
95+ stdoutTruncated : Schema . optional ( Schema . Boolean ) ,
9396 } ,
9497) {
9598 override get message ( ) : string {
96- return `Failed to inspect terminal subprocesses with ${ this . command } ` ;
99+ const details = [
100+ this . exitCode !== undefined && this . exitCode !== null ? `exit code ${ this . exitCode } ` : null ,
101+ this . timedOut ? "timed out" : null ,
102+ this . stdoutTruncated ? "output truncated" : null ,
103+ ]
104+ . filter ( ( detail ) => detail !== null )
105+ . join ( ", " ) ;
106+ return `Failed to inspect terminal subprocesses with ${ this . command } ${ details . length > 0 ? ` (${ details } )` : "" } ` ;
97107 }
98108}
99109
@@ -614,21 +624,6 @@ interface TerminalProcessTableSnapshot {
614624 readonly commandById : ReadonlyMap < number , string > ;
615625}
616626
617- // A failed, timed-out, or truncated snapshot is not authoritative: treating it
618- // as an empty table would mark every terminal idle and clear its registered
619- // process ids. Fail instead so the poll tick is skipped and prior state kept.
620- function snapshotFailure (
621- command : "powershell" | "ps" ,
622- result : ProcessRunner . ProcessRunOutput ,
623- ) : TerminalSubprocessCheckError {
624- return new TerminalSubprocessCheckError ( {
625- command,
626- cause : new Error (
627- `process table snapshot unusable (code ${ result . code } , timedOut ${ result . timedOut } , truncated ${ result . stdoutTruncated } )` ,
628- ) ,
629- } ) ;
630- }
631-
632627function parsePosixProcessTable ( stdout : string ) : TerminalProcessTableSnapshot {
633628 const childrenByParent = new Map < number , number [ ] > ( ) ;
634629 const commandById = new Map < number , string > ( ) ;
@@ -733,7 +728,14 @@ const posixProcessTableSnapshot = Effect.fn("terminal.posixProcessTableSnapshot"
733728 ) ,
734729 ) ;
735730 if ( result . code !== 0 || result . timedOut || result . stdoutTruncated ) {
736- return yield * snapshotFailure ( "ps" , result ) ;
731+ // Not authoritative: an empty or partial table would mark every terminal
732+ // idle and clear its registered process ids. Failing skips the tick.
733+ return yield * new TerminalSubprocessCheckError ( {
734+ command : "ps" ,
735+ exitCode : result . code ,
736+ timedOut : result . timedOut ,
737+ stdoutTruncated : result . stdoutTruncated ,
738+ } ) ;
737739 }
738740 return parsePosixProcessTable ( result . stdout ) ;
739741} ) ;
@@ -769,7 +771,14 @@ const windowsProcessTableSnapshot = Effect.fn("terminal.windowsProcessTableSnaps
769771 ) ,
770772 ) ;
771773 if ( result . code !== 0 || result . timedOut || result . stdoutTruncated ) {
772- return yield * snapshotFailure ( "powershell" , result ) ;
774+ // Not authoritative: an empty or partial table would mark every terminal
775+ // idle and clear its registered process ids. Failing skips the tick.
776+ return yield * new TerminalSubprocessCheckError ( {
777+ command : "powershell" ,
778+ exitCode : result . code ,
779+ timedOut : result . timedOut ,
780+ stdoutTruncated : result . stdoutTruncated ,
781+ } ) ;
773782 }
774783 return parseWindowsProcessTable ( result . stdout ) ;
775784 } ,
0 commit comments