{"record":{"id":"7196281a4783c3cb","repo":"affaan-m/ECC","slug":"work-item-not-found-id","errorCode":null,"errorMessage":"Work item not found: ${id}","messagePattern":"Work item not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/control-pane/work-item-mutations.js","lineNumber":43,"sourceCode":"    String(status || '')\n      .trim()\n      .toLowerCase()\n  );\n}\n\nfunction priorityRank(priority) {\n  return PRIORITY_RANK[String(priority || '').toLowerCase()] ?? 2;\n}\n\n/**\n * Resolve which work item a claim targets: an explicit id, otherwise the\n * highest-priority unassigned open item (the JIT pickup queue).\n */\nfunction selectClaimTarget(store, { id } = {}) {\n  if (id) {\n    const item = store.getWorkItemById(id);\n    if (!item) {\n      throw new Error(`Work item not found: ${id}`);\n    }\n    return item;\n  }\n  const { items } = store.listWorkItems({ limit: 100 });\n  return items.filter(item => !item.owner && isOpenStatus(item.status)).sort((a, b) => priorityRank(a.priority) - priorityRank(b.priority))[0] || null;\n}\n\n/**\n * Claim an unassigned work item for an agent or human. Sets the owner (and\n * optional assigneeKind) and moves the card to running unless an explicit\n * status is supplied. Returns { claimed, item } or { claimed: false, reason }.\n */\nfunction claimWorkItem(store, { id, owner, assigneeKind, sessionId, status } = {}) {\n  if (!owner) {\n    throw new Error('claim requires an owner.');\n  }\n  const kind = assigneeKind ? String(assigneeKind).toLowerCase() : null;\n  if (kind && !VALID_ASSIGNEE_KINDS.has(kind)) {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/control-pane/work-item-mutations.js#L25-L61","documentation":"Thrown by selectClaimTarget (work-item-mutations.js) when claimWorkItem is called with an explicit id that does not resolve through store.getWorkItemById. The JIT board cannot claim a card it cannot find; unlike the no-id path (which returns { claimed:false, reason }), an explicit-but-missing id is treated as a caller bug and throws.","triggerScenarios":"Calling claimWorkItem({ id, owner }) where id was deleted, never existed, belongs to a different store/workspace, or is stale from a cached list; passing an id with wrong casing or whitespace; race where another worker deleted the item between list and claim.","commonSituations":"A stale UI/CLI list references an id that was since closed; copy-paste of an id from one workspace into another; trailing whitespace/newline in an id read from stdin or a file; concurrent agent deleted the item.","solutions":["Refresh the work-item list (store.listWorkItems) and retry claim with a current id.","Strip and validate the id before calling (id && typeof id === 'string' && !id.includes(' ')).","To pick up the next available item instead, omit id entirely and let selectClaimTarget use the priority queue.","Wrap claim in try/catch and treat this error as a recoverable 'retry after refresh' rather than fatal."],"exampleFix":"// before\nclaimWorkItem(store, { id: rawId, owner });\n\n// after — verify the id exists first, else fall back to JIT pickup\nconst target = rawId ? store.getWorkItemById(rawId) : null;\nif (rawId && !target) {\n  console.warn(`id ${rawId} gone; falling back to JIT queue`);\n}\nclaimWorkItem(store, { id: target ? target.id : undefined, owner });","handlingStrategy":"validation","validationCode":"if (id && !store.getWorkItemById(id)) {\n  throw new Error(`Cannot claim: work item ${id} does not exist (refresh and retry)`);\n}","typeGuard":"function itemExists(store, id) {\n  return Boolean(id && store.getWorkItemById(id));\n}","tryCatchPattern":"try {\n  claimWorkItem(store, { id, owner });\n} catch (e) {\n  if (/Work item not found/.test(e.message)) { await load(); return; }\n  throw e;\n}","preventionTips":["Refresh the work-item list before claiming by id.","For JIT pickup, omit id and let the priority queue select.","Strip whitespace from ids read from external sources."],"tags":["work-items","claim","validation","state"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}