{"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/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/control-pane/work-item-mutations.js#L25-L61","documentation":"selectClaimTarget resolves which work item a claim applies to. When an explicit id is supplied but store.getWorkItemById(id) returns nothing, it throws 'Work item not found: <id>'. It refuses to silently substitute the auto-pick queue in that case.","triggerScenarios":"claimWorkItem(store, { id: 'xyz' }) where 'xyz' is not a stored work item id — typo'd id, item deleted, or store from a different project/session.","commonSituations":"CLI claim with a copied id that has whitespace or wrong case; control pane posting a stale id after another agent completed and pruned the item; pointing at a store file that doesn't contain the item.","solutions":["Print available ids with store.listWorkItems({ limit: 100 }) and confirm the id matches exactly.","Trim the id — stray whitespace or quotes from copy-paste is the most common cause.","Re-fetch the item in case it was completed/removed by another agent and pick a current unassigned item instead.","Omit the id to let selectClaimTarget auto-select the highest-priority unassigned open item."],"exampleFix":"// before\nclaimWorkItem(store, { id: ' item-42 ' });\n// after\nconst id = ' item-42 '.trim();\nconst exists = store.getWorkItemById(id);\nif (!exists) throw new Error(`Work item not found: ${id}`);\nclaimWorkItem(store, { id });","handlingStrategy":"validation","validationCode":"const { items } = store.listWorkItems({ limit: 100 });\nconst known = new Set(items.map(i => i.id));\nif (!known.has(id)) throw new Error(`Unknown id ${id}; available: ${[...known].join(', ')}`);","typeGuard":"function itemExists(store, id) { return !!store.getWorkItemById(id); }","tryCatchPattern":"try { const item = claimWorkItem(store, { id, owner }); } catch (e) {\n  if (e.message.startsWith('Work item not found')) { /* refresh list, pick another item */ }\n  else throw e;\n}","preventionTips":["Fetch fresh ids via listWorkItems before claiming; never hardcode.","Trim and normalize ids copied from logs/UI.","Omit id to use the auto-pick highest-priority queue.","Refresh control-pane state after other agents complete items."],"tags":["work-items","lookup","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}