{"record":{"id":"7b7fd7f7aa6a8541","repo":"github/copilot-sdk","slug":"failed-to-flush-final-factory-progress-after-the-f","errorCode":null,"errorMessage":"Failed to flush final factory progress after the factory body settled","messagePattern":"Failed to flush final factory progress after the factory body settled","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"nodejs/src/session.ts","lineNumber":296,"sourceCode":"        }\n    }\n\n    async close(): Promise<void> {\n        this.closed = true;\n        this.clearFlushTimer();\n        const lines = this.pending.splice(0);\n        await this.flushTail;\n        if (this.flushFailed) {\n            console.warn(\n                \"Ignoring a background factory progress flush failure after the factory body settled\",\n                this.flushError\n            );\n        }\n        if (lines.length > 0) {\n            try {\n                await this.send(lines);\n            } catch (error) {\n                console.warn(\n                    \"Failed to flush final factory progress after the factory body settled\",\n                    error\n                );\n            }\n        }\n    }\n\n    private scheduleFlush(): void {\n        if (this.flushTimer !== undefined) {\n            return;\n        }\n        this.flushTimer = setTimeout(() => {\n            this.flushTimer = undefined;\n            void this.flush().catch(() => {});\n        }, FACTORY_LOG_FLUSH_DELAY_MS);\n        this.flushTimer.unref?.();\n    }\n","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/session.ts#L278-L314","documentation":"CopilotSession buffers periodic factory progress lines and flushes any remaining ones once the factory body settles during close(). This warning is logged when the final send() of those buffered lines rejects. The session still closes; only the last progress update is lost.","triggerScenarios":"Calling close() on a session whose factory body emitted progress lines, while the transport/underlying connection has already been terminated or is failing, so this.send(lines) rejects during the final flush.","commonSituations":"Network drop or server shutdown right as close() is called; calling close() twice so the stream is already closed; killing the parent process/socket before close completes.","solutions":["Verify the underlying connection/transport is still alive before calling close(); retry close() after reconnecting if the progress matters.","Check logs for an earlier transport error - the flush failure is usually a symptom, not the root cause.","If the loss of final progress is acceptable, treat this warning as informational and proceed.","Ensure you do not call send() or close() concurrently from multiple code paths."],"exampleFix":"// before\nawait session.close();\n// after\ntry {\n  await session.close();\n} catch (err) {\n  console.error('close failed', err);\n}","handlingStrategy":"try-catch","validationCode":"if (!session.isConnected?.()) {\n  console.warn('transport down; final progress flush will likely fail');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await session.close();\n} catch (error) {\n  console.error('Session close failed; final progress may be lost', error);\n  // decide whether to reconnect and re-flush or abandon\n}","preventionTips":["Check transport health before close()","Avoid concurrent close()/send() calls","Treat this warning as lossy-close notification and log it persistently"],"tags":["warning","network","flush","session-close"],"backgroundTag":"broken-pipe","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}