{"record":{"id":"518d698a3138eb85","repo":"slopus/happy","slug":"daemon-state-version-mismatch","errorCode":null,"errorMessage":"Daemon state version mismatch","messagePattern":"Daemon state version mismatch","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/happy-cli/src/api/apiMachine.ts","lineNumber":422,"sourceCode":"        await backoff(async () => {\n            const updated = handler(this.machine.daemonState);\n\n            const answer = await this.socket.emitWithAck('machine-update-state', {\n                machineId: this.machine.id,\n                daemonState: encodeBase64(encrypt(this.machine.encryptionKey, this.machine.encryptionVariant, updated)),\n                expectedVersion: this.machine.daemonStateVersion\n            });\n\n            if (answer.result === 'success') {\n                this.machine.daemonState = decrypt(this.machine.encryptionKey, this.machine.encryptionVariant, decodeBase64(answer.daemonState));\n                this.machine.daemonStateVersion = answer.version;\n                logger.debug('[API MACHINE] Daemon state updated successfully');\n            } else if (answer.result === 'version-mismatch') {\n                if (answer.version > this.machine.daemonStateVersion) {\n                    this.machine.daemonStateVersion = answer.version;\n                    this.machine.daemonState = decrypt(this.machine.encryptionKey, this.machine.encryptionVariant, decodeBase64(answer.daemonState));\n                }\n                throw new Error('Daemon state version mismatch'); // Triggers retry\n            }\n        });\n    }\n\n    connect() {\n        const serverUrl = configuration.serverUrl.replace(/^http/, 'ws');\n        logger.debug(`[API MACHINE] Connecting to ${serverUrl}`);\n\n        this.socket = io(serverUrl, {\n            transports: ['websocket'],\n            auth: {\n                token: this.token,\n                clientType: 'machine-scoped' as const,\n                machineId: this.machine.id,\n                happyClient: `cli-daemon/${configuration.currentCliVersion}`\n            },\n            path: '/v1/updates',\n            reconnection: false,","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/api/apiMachine.ts#L404-L440","documentation":"Thrown by updateDaemonState when the server reports 'version-mismatch' for daemon runtime state. As with metadata, the client first adopts the server's newer daemonStateVersion/daemonState, then throws to trigger a retry with the refreshed version. It is an expected conflict signal, not a fatal fault.","triggerScenarios":"Concurrent daemon-state updates from two daemon processes or a stale update issued by connect()'s update loop after another writer advanced the version.","commonSituations":"Duplicate daemon instances; daemon reconnecting after another instance already bumped daemonStateVersion; leftover state updates in flight across restarts.","solutions":["Allow the surrounding retry in connect() to re-send with the adopted version","Stop extra daemon instances so only one writer exists","If recurring, re-sync daemon state from the server before pushing updates"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await updateDaemonState(state);\n} catch (e) {\n  if (e.message === 'Daemon state version mismatch') {\n    // server version already adopted locally; retry converges\n    await updateDaemonState(state);\n  } else throw e;\n}","preventionTips":["Prevent duplicate daemon processes (pidfile/lock)","Let connect()'s retry loop handle the conflict","Re-sync daemon state after long disconnects before pushing"],"tags":["version-conflict","optimistic-concurrency","daemon-state","retry"],"backgroundTag":"version-mismatch","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}