| 498 | let observedExitCode: number | null = null; |
| 499 | let observedExitSignal: NodeJS.Signals | null = null; |
| 500 | const buildWebhookFailureMessage = (reason: 'timeout' | 'exit-before-webhook' | 'process-error-before-webhook'): string => { |
| 501 | let message = ''; |
| 502 | if (reason === 'exit-before-webhook') { |
| 503 | message = `Session process exited before webhook for PID ${pid}`; |
| 504 | } else if (reason === 'process-error-before-webhook') { |
| 505 | message = `Session process error before webhook for PID ${pid}`; |
| 506 | } else { |
| 507 | message = `Session webhook timeout for PID ${pid}`; |
| 508 | } |
| 509 | |
| 510 | if (observedExitCode !== null || observedExitSignal) { |
| 511 | if (observedExitCode !== null) { |
| 512 | message += ` (exit code ${observedExitCode})`; |
| 513 | } else { |
| 514 | message += ` (signal ${observedExitSignal})`; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | const trimmedTail = stderrTail.trim(); |
| 519 | if (trimmedTail) { |
| 520 | const compactTail = trimmedTail.replace(/\s+/g, ' '); |
| 521 | const tailForMessage = compactTail.length > 800 ? compactTail.slice(-800) : compactTail; |
| 522 | message += `. stderr: ${tailForMessage}`; |
| 523 | } |
| 524 | |
| 525 | return message; |
| 526 | }; |
| 527 | |
| 528 | const trackedSession: TrackedSession = { |
| 529 | startedBy: 'runner', |