{"record":{"id":"1eb36edba537a25b","repo":"davila7/claude-code-templates","slug":"task-not-found","errorCode":null,"errorMessage":"Task not found","messagePattern":"Task not found","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"cli-tool/src/sandbox-server.js","lineNumber":180,"sourceCode":"    // Execute based on mode\n    if (mode === 'cloud') {\n        executeE2BTask(task);\n    } else {\n        executeLocalTask(task);\n    }\n    \n    res.json({\n        success: true,\n        taskId: taskId,\n        message: 'Task started successfully'\n    });\n});\n\n// API endpoint to get task status\napp.get('/api/task/:taskId', (req, res) => {\n    const task = activeTasks.get(req.params.taskId);\n    if (!task) {\n        return res.status(404).json({\n            success: false,\n            error: 'Task not found'\n        });\n    }\n    \n    res.json({\n        success: true,\n        task: {\n            id: task.id,\n            title: task.title,\n            status: task.status,\n            progress: task.progress,\n            output: task.output.join('\\\\n'),\n            startTime: task.startTime,\n            endTime: task.endTime,\n            sandboxId: task.sandboxId\n        }\n    });","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/sandbox-server.js#L162-L198","documentation":"GET /api/task/:taskId looks up the task in the in-memory activeTasks Map and returns 404 when no task with that ID exists. Task IDs are only held in the server process's memory, so they disappear on restart and are never persisted.","triggerScenarios":"Polling /api/task/<id> with a malformed or wrong ID (e.g. missing the task- prefix generated by /api/execute); polling after the server restarted; polling a task created by a different server instance (multiple sandbox servers on different ports).","commonSituations":"Client resumes polling after a server restart; typos in task ID; load-balanced or redeployed server losing in-memory state; very long-running tasks where the client reconnects later.","solutions":["Re-submit the task via POST /api/execute to get a fresh task ID","Verify the task ID string exactly matches what /api/execute returned (task-<timestamp>-<random>)","Keep the same server process alive while polling, or persist tasks externally if cross-restart status is needed"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const taskRes = await fetch(`${base}/api/task/${encodeURIComponent(taskId)}`);\nif (taskRes.status === 404) {\n  // task lost (server restart?) — resubmit\n  const redo = await fetch(`${base}/api/execute`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt }) });\n  const { taskId: newId } = await redo.json();\n}","typeGuard":null,"tryCatchPattern":"try { const r = await fetch(url); if (r.status === 404) { /* resubmit */ } } catch (e) { /* network error: retry with backoff */ }","preventionTips":["Store the task ID returned by /api/execute exactly and urlencode it","Don't restart the server while tasks are in flight","Treat 404 on polling as a signal to resubmit, not a hard failure"],"tags":["http-404","task-not-found","in-memory-state","polling"],"backgroundTag":"resource-not-found","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}