{"record":{"id":"9ab1c9aee89d9fe9","repo":"affaan-m/ECC","slug":"claim-requires-an-owner","errorCode":null,"errorMessage":"claim requires an owner.","messagePattern":"claim requires an owner\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/control-pane/work-item-mutations.js","lineNumber":58,"sourceCode":"  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)) {\n    throw new Error(\"assigneeKind must be 'agent' or 'human'.\");\n  }\n  const target = selectClaimTarget(store, { id });\n  if (!target) {\n    return { claimed: false, reason: 'no-unassigned-open-items' };\n  }\n  if (!isOpenStatus(target.status)) {\n    throw new Error(`Work item ${target.id} is already done; cannot claim.`);\n  }\n  const metadata = { ...(target.metadata || {}) };\n  if (kind) {\n    metadata.assigneeKind = kind;\n  }\n  const item = store.upsertWorkItem({\n    ...target,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/control-pane/work-item-mutations.js#L40-L76","documentation":"claimWorkItem requires an owner (agent or human name) to record who is taking the item. With no owner supplied it throws 'claim requires an owner.' rather than guessing an identity. This is a precondition guard before any store mutation.","triggerScenarios":"claimWorkItem(store, { id }) or claimWorkItemCli(...) with owner undefined/null/empty string — omitted CLI flag, empty prompt input in the control pane, or a config not passing agent identity.","commonSituations":"Running the claim CLI without --owner; user cancels or submits empty text at the window.prompt in eccClaimItem; automation scripts that never set an agent name env/config.","solutions":["Pass owner explicitly: claimWorkItem(store, { id, owner: 'agent-name' }).","For CLI, supply the owner flag (e.g. --owner agent-name).","In the control pane, enter a non-empty name when prompted; the prompt result must be non-null/non-empty.","Set a default agent identity in your automation config so owner is always populated."],"exampleFix":"// before\nclaimWorkItem(store, { id });\n// after\nclaimWorkItem(store, { id, owner: process.env.AGENT_NAME || 'human-operator' });","handlingStrategy":"validation","validationCode":"if (!owner || typeof owner !== 'string' || !owner.trim()) {\n  throw new Error('Refusing to claim: owner is required.');\n}","typeGuard":"function hasOwner(args) { return typeof args?.owner === 'string' && args.owner.trim().length > 0; }","tryCatchPattern":"try { claimWorkItem(store, { id, owner }); } catch (e) {\n  if (e.message === 'claim requires an owner.') { owner = promptForOwner(); return claimWorkItem(store, { id, owner }); }\n  throw e;\n}","preventionTips":["Default the owner from env/config (AGENT_NAME) at the call site.","Validate owner non-empty before calling, especially when it comes from window.prompt or CLI flags.","Handle prompt cancellation (null) explicitly instead of passing it through.","Standardize agent identity in automation scripts."],"tags":["work-items","validation","missing-argument"],"backgroundTag":"missing-required-argument","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"}