(sessionId: UUID, entry: TranscriptMessage)
| 1382 | } |
| 1383 | |
| 1384 | private async persistToRemote(sessionId: UUID, entry: TranscriptMessage) { |
| 1385 | if (isShuttingDown()) { |
| 1386 | return |
| 1387 | } |
| 1388 | |
| 1389 | // CCR v2 path: write as internal worker event |
| 1390 | if (this.internalEventWriter) { |
| 1391 | try { |
| 1392 | await this.internalEventWriter( |
| 1393 | 'transcript', |
| 1394 | entry as unknown as Record<string, unknown>, |
| 1395 | { |
| 1396 | ...(isCompactBoundaryMessage(entry) && { isCompaction: true }), |
| 1397 | ...(entry.agentId && { agentId: entry.agentId }), |
| 1398 | }, |
| 1399 | ) |
| 1400 | } catch { |
| 1401 | logEvent('ncode_session_persistence_failed', {}) |
| 1402 | logForDebugging('Failed to write transcript as internal event') |
| 1403 | } |
| 1404 | return |
| 1405 | } |
| 1406 | |
| 1407 | // v1 Session Ingress path |
| 1408 | if ( |
| 1409 | !isEnvTruthy(process.env.ENABLE_SESSION_PERSISTENCE) || |
| 1410 | !this.remoteIngressUrl |
| 1411 | ) { |
| 1412 | return |
| 1413 | } |
| 1414 | |
| 1415 | const success = await sessionIngress.appendSessionLog( |
| 1416 | sessionId, |
| 1417 | entry, |
| 1418 | this.remoteIngressUrl, |
| 1419 | ) |
| 1420 | |
| 1421 | if (!success) { |
| 1422 | logEvent('ncode_session_persistence_failed', {}) |
| 1423 | gracefulShutdownSync(1, 'other') |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | setRemoteIngressUrl(url: string): void { |
| 1428 | this.remoteIngressUrl = url |
no test coverage detected