{"record":{"id":"74a9f5daff00ac88","repo":"can1357/oh-my-pi","slug":"acp-session-cannot-be-forked-before-it-is-persiste","errorCode":null,"errorMessage":"ACP session cannot be forked before it is persisted: ${sessionId}","messagePattern":"ACP session cannot be forked before it is persisted: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/acp/acp-agent.ts","lineNumber":1401,"sourceCode":"\n\t#assertMatchingCwd(session: AgentSession, cwd: string): void {\n\t\tconst expected = path.resolve(cwd);\n\t\tconst actual = path.resolve(session.sessionManager.getCwd());\n\t\tif (actual !== expected) {\n\t\t\tthrow new Error(`ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}`);\n\t\t}\n\t}\n\n\tasync #resolveForkSourceSessionPath(sessionId: string): Promise<string> {\n\t\tconst loaded = this.#sessions.get(sessionId);\n\t\tif (loaded) {\n\t\t\tif (isPromptTurnInFlight(loaded.promptTurn)) {\n\t\t\t\tthrow new Error(`ACP session fork is unavailable while a prompt is in progress: ${sessionId}`);\n\t\t\t}\n\t\t\tawait loaded.session.sessionManager.flush();\n\t\t\tconst sessionPath = loaded.session.sessionManager.getSessionFile();\n\t\t\tif (!sessionPath) {\n\t\t\t\tthrow new Error(`ACP session cannot be forked before it is persisted: ${sessionId}`);\n\t\t\t}\n\t\t\treturn sessionPath;\n\t\t}\n\n\t\tconst storedSession = await this.#findStoredSessionById(sessionId);\n\t\tif (!storedSession) {\n\t\t\tthrow new Error(`ACP session not found: ${sessionId}`);\n\t\t}\n\t\treturn storedSession.path;\n\t}\n\n\tasync #handlePromptEvent(record: ManagedSessionRecord, event: AgentSessionEvent): Promise<void> {\n\t\tconst promptTurn = record.promptTurn;\n\t\tif (!promptTurn || promptTurn.settled || promptTurn.cancelRequested) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (event.type === \"tool_execution_start\" || event.type === \"tool_execution_update\") {","sourceCodeStart":1383,"sourceCodeEnd":1419,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/acp/acp-agent.ts#L1383-L1419","documentation":"Thrown by #resolveForkSourceSessionPath when the loaded session has no session file: after flushing, sessionManager.getSessionFile() still returns nothing, meaning the session was never persisted and there is nothing on disk to fork from. Fork requires a source file to copy.","triggerScenarios":"Forking a session created with persistence disabled, or a brand-new session whose first write to disk failed/hasn't happened, so no session file exists.","commonSituations":"Sessions running with ephemeral/no-persist configuration; disk-full or permissions issues preventing the session file from being written; forking immediately after session creation before any persisted turn.","solutions":["Ensure the session is configured with persistence enabled so a session file is created.","Send at least one turn (or trigger a flush/save) before forking.","Check disk space/permissions in the sessions storage directory if flush is failing to materialize the file."],"exampleFix":"// before\nconst session = await createSession({ cwd, persist: false });\nawait forkSession({ sessionId: session.sessionId });\n// after\nconst session = await createSession({ cwd, persist: true });\nawait session.prompt(\"init\"); // ensure state is persisted\nawait forkSession({ sessionId: session.sessionId });","handlingStrategy":"validation","validationCode":"// fork requires a persisted session file\nconst file = session.sessionManager.getSessionFile();\nif (!file) throw new Error(\"session not persisted yet; run a turn or enable persistence before forking\");","typeGuard":null,"tryCatchPattern":"try {\n  await agent.fork({ sessionId });\n} catch (err) {\n  if (err.message.includes(\"before it is persisted\")) {\n    // enable persistence or send a turn first, then retry\n  }\n  throw err;\n}","preventionTips":["Run sessions with persistence enabled when fork support is required.","Ensure at least one turn is saved before forking a fresh session.","Monitor disk/permission health of the sessions storage directory."],"tags":["acp","session-fork","persistence"],"backgroundTag":"session-not-persisted","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}