{"record":{"id":"3aaec00514094bf9","repo":"nanocoai/nanoclaw","slug":"session-not-found-sessionid","errorCode":null,"errorMessage":"session not found: ${sessionId}","messagePattern":"session not found: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli/resources/tasks.ts","lineNumber":77,"sourceCode":"}\n\nfunction statusFilter(args: Record<string, unknown>): TaskStatus | undefined {\n  const status = str(args.status);\n  if (!status) return undefined;\n  if (status !== 'pending' && status !== 'paused') {\n    throw new Error('--status must be pending or paused');\n  }\n  return status;\n}\n\nfunction groupArg(args: Record<string, unknown>, ctx: CallerContext): string | undefined {\n  if (ctx.caller === 'agent') return ctx.agentGroupId;\n  return str(args.group) ?? str(args.agent_group_id);\n}\n\nasync function ownSession(sessionId: string, ctx: CallerContext): Promise<ScopedSession> {\n  const session = await getSession(sessionId);\n  if (!session) throw new Error(`session not found: ${sessionId}`);\n  if (ctx.caller === 'agent' && session.agent_group_id !== ctx.agentGroupId) {\n    throw new Error(`session not found: ${sessionId}`);\n  }\n  return { id: session.id, agent_group_id: session.agent_group_id };\n}\n\nasync function selectedSessions(\n  args: Record<string, unknown>,\n  ctx: CallerContext,\n  includeClosed = false,\n): Promise<ScopedSession[]> {\n  const sessionId = str(args.session);\n  if (sessionId) return [await ownSession(sessionId, ctx)];\n\n  const group = groupArg(args, ctx);\n  if (group) {\n    // One session per live task series — the loops below already fan out across them.\n    return (await findTaskSessions(group, includeClosed)).map((s) => ({","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/cli/resources/tasks.ts#L59-L95","documentation":"Thrown by `ownSession` in the tasks resource when `getSession(sessionId)` returns no row — no session with that id exists in the central DB. The id may have been mistyped, deleted, or never created; the tasks CLI refuses to operate on it.","triggerScenarios":"`ncl tasks list --session <bad-id>`, `ncl tasks create --session <bad-id> ...`, or any tasks verb that routes through selectedSessions with a nonexistent session id.","commonSituations":"Copy/paste of a truncated session id; session was cleaned up (sessions are runtime artifacts and can disappear); referencing a session from another install or environment; typo in a scripted id variable.","solutions":["List real sessions with `ncl sessions list` (or `ncl sessions list --json`) and copy the exact id","If scripting, resolve the session id dynamically instead of hardcoding it","Confirm you are pointed at the right install/DB if the session came from another environment"],"exampleFix":"# before\nncl tasks list --session sess_typo123\n# after\nncl sessions list   # copy exact id\nncl tasks list --session sess_ab12cd34","handlingStrategy":"validation","validationCode":"const sessions = await execNclJson(['sessions', 'list']);\nconst ok = sessions.some(s => s.id === sessionId);\nif (!ok) throw new Error(`unknown session ${sessionId}; run ncl sessions list`);\nawait execNcl(['tasks', 'list', '--session', sessionId]);","typeGuard":"const isExistingSessionId = (id: string, known: {id: string}[]) =>\n  known.some(s => s.id === id);","tryCatchPattern":"catch (e) { if (e.message.startsWith('session not found:')) { refresh session cache and retry once } else throw e; }","preventionTips":["Never hardcode session ids in long-lived scripts — resolve them at runtime","Sessions are ephemeral; re-resolve after restarts or rewiring","Validate ids against `ncl sessions list --json` before use"],"tags":["cli","tasks","session","not-found"],"backgroundTag":"record-not-found","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}