{"record":{"id":"a286116a90eb1119","repo":"slopus/happy","slug":"resume-session-handler-not-available","errorCode":null,"errorMessage":"Resume session handler not available","messagePattern":"Resume session handler not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/api/apiMachine.ts","lineNumber":348,"sourceCode":"            return { message: 'Daemon stop request acknowledged, starting shutdown sequence...' };\n        });\n    }\n\n    private syncResumeSessionRpcRegistration(): void {\n        const method = 'resume-happy-session';\n\n        if (this.resumeSessionHandler) {\n            if (!this.rpcHandlerManager.hasHandler(method)) {\n                this.rpcHandlerManager.registerHandler(method, async (params: any) => {\n                    const { sessionId, model, permissionMode } = params || {};\n\n                    if (!sessionId || typeof sessionId !== 'string') {\n                        throw new Error('Session ID is required');\n                    }\n\n                    const handler = this.resumeSessionHandler;\n                    if (!handler) {\n                        throw new Error('Resume session handler not available');\n                    }\n\n                    const result = await handler(sessionId, { model, permissionMode });\n                    switch (result.type) {\n                        case 'success':\n                            return { type: 'success', sessionId: result.sessionId };\n                        case 'requestToApproveDirectoryCreation':\n                            return result;\n                        case 'error':\n                            throw new Error(result.errorMessage);\n                    }\n                });\n            }\n            return;\n        }\n\n        if (this.rpcHandlerManager.hasHandler(method)) {\n            this.rpcHandlerManager.unregisterHandler(method);","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/api/apiMachine.ts#L330-L366","documentation":"Thrown by the resume-session RPC handler when this.resumeSessionHandler is unset at the time the RPC arrives, even though a handler was registered. This is a narrow race/lifecycle window: the RPC method is registered but the actual callback has not been attached (or was detached), so the request cannot be fulfilled.","triggerScenarios":"Invoking the resume-session RPC during client startup before connect()/setRPCHandlers has assigned this.resumeSessionHandler; resuming right after teardown/disconnect cleared the handler.","commonSituations":"Race between daemon startup and an immediate resume request from the app; reconnect flow where RPC registration runs before handler wiring; tests calling the RPC before full initialization.","solutions":["Wait for the client connection/initialization to complete before calling resume-session","Retry the RPC after a short delay so the handler is attached","Ensure setRPCHandlers/connect assigns resumeSessionHandler before (or atomically with) registering the RPC method"],"exampleFix":"// before\nawait connect();\nawait rpc.call('session/resume', { sessionId }); // may race\n// after\nawait connect();\nawait waitFor(client.ready); // handler attached\nawait rpc.call('session/resume', { sessionId });","handlingStrategy":"retry","validationCode":"// Only resume once the client reports readiness\nif (!client.ready || !client.resumeSessionHandler) {\n  await client.waitForReady();\n}","typeGuard":"function canResume(c: { resumeSessionHandler?: unknown }): c is { resumeSessionHandler: Function } {\n  return typeof c.resumeSessionHandler === 'function';\n}","tryCatchPattern":"try {\n  await rpc.call(method, { sessionId });\n} catch (e) {\n  if (e.message === 'Resume session handler not available') {\n    await delay(250);\n    return rpc.call(method, { sessionId }); // retry once ready\n  } throw e;\n}","preventionTips":["Gate resume calls on client readiness signals","Wire handlers before registering RPC methods","Add a small startup delay/retry after daemon boot"],"tags":["rpc","lifecycle","race-condition","session-resume"],"backgroundTag":"handler-not-initialized","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}