{"record":{"id":"a1ca53068d5482db","repo":"davila7/claude-code-templates","slug":"error-calculating-state-for-conversation-convers","errorCode":null,"errorMessage":"Error calculating state for conversation ${conversation.id}:","messagePattern":"Error calculating state for conversation (.+?):","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-tool/src/chats-mobile.js","lineNumber":165,"sourceCode":"      try {\n        // Calculate states for ALL conversations using StateCalculator\n        const activeStates = {};\n        \n        for (const conversation of this.data.conversations) {\n          try {\n            // Get parsed messages for state calculation\n            const parsedMessages = await this.conversationAnalyzer.getParsedConversation(conversation.filePath);\n            \n            // Use StateCalculator to determine current state\n            const state = this.stateCalculator.determineConversationState(\n              parsedMessages, \n              conversation.lastModified,\n              null // No running process detection for now\n            );\n            \n            activeStates[conversation.id] = state;\n          } catch (error) {\n            console.warn(`Error calculating state for conversation ${conversation.id}:`, error.message);\n            activeStates[conversation.id] = 'Inactive';\n          }\n        }\n        \n        res.json({\n          activeStates,\n          timestamp: new Date().toISOString(),\n          totalConversations: this.data.conversations.length\n        });\n      } catch (error) {\n        console.error('Error calculating conversation states:', error);\n        res.status(500).json({ error: 'Internal server error' });\n      }\n    });\n\n    // API to get unique working directories from conversations\n    this.app.get('/api/directories', (req, res) => {\n      try {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/chats-mobile.js#L147-L183","documentation":"An HTTP route handler in chats-mobile.js computes a per-conversation active state and caught an error for one conversation, defaulting it to 'Inactive'. Caused by a per-item helper (getState-like function taking lastModified/process info) throwing.","triggerScenarios":"GET on the mobile chats active-states endpoint where computing state for one conversation throws — e.g. invalid lastModified (NaN/undefined date) passed into date math.","commonSituations":"A conversation file with missing/zero mtime; mixed data where lastModified is undefined; schema drift after CLI update.","solutions":["Ignore — that conversation shows as Inactive; others are correct","Check the conversation file named by its id for missing/odd mtime","Update the CLI where mtime handling was hardened","If persistent for all conversations, inspect the server console for the underlying message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Sanitize inputs to the state computation\nconst lm = Number.isFinite(conversation.lastModified) ? conversation.lastModified : 0;\nconst state = computeState(lm, null);","typeGuard":"function hasValidTimestamp(c) {\n  return !!c && Number.isFinite(c.lastModified) && c.lastModified > 0;\n}","tryCatchPattern":"try { activeStates[id] = computeState(c.lastModified, null); }\ncatch (error) {\n  console.warn(`Error calculating state for ${c.id}:`, error.message);\n  activeStates[id] = 'Inactive'; // safe default per conversation\n}","preventionTips":["Default missing timestamps to 0/epoch before date math","Never let one bad conversation fail the whole active-states response","Log conversation ids so bad files are traceable"],"tags":["chats-mobile","http-route","state","fallback"],"backgroundTag":"per-item-handler-error","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}