affaan-m/ECC · error · Error

Work item not found

Error message

Work item not found: ${id}

What it means

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.

Solutions

  1. Print available ids with store.listWorkItems({ limit: 100 }) and confirm the id matches exactly.
  2. Trim the id — stray whitespace or quotes from copy-paste is the most common cause.
  3. Re-fetch the item in case it was completed/removed by another agent and pick a current unassigned item instead.
  4. Omit the id to let selectClaimTarget auto-select the highest-priority unassigned open item.

Example fix

// before
claimWorkItem(store, { id: ' item-42 ' });
// after
const id = ' item-42 '.trim();
const exists = store.getWorkItemById(id);
if (!exists) throw new Error(`Work item not found: ${id}`);
claimWorkItem(store, { id });
Defensive patterns

Strategy: validation

Validate before calling

const { items } = store.listWorkItems({ limit: 100 });
const known = new Set(items.map(i => i.id));
if (!known.has(id)) throw new Error(`Unknown id ${id}; available: ${[...known].join(', ')}`);

Type guard

function itemExists(store, id) { return !!store.getWorkItemById(id); }

Try / catch

try { const item = claimWorkItem(store, { id, owner }); } catch (e) {
  if (e.message.startsWith('Work item not found')) { /* refresh list, pick another item */ }
  else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/7196281a4783c3cb. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/control-pane/work-item-mutations.js:43

    String(status || '')
      .trim()
      .toLowerCase()
  );
}

function priorityRank(priority) {
  return PRIORITY_RANK[String(priority || '').toLowerCase()] ?? 2;
}

/**
 * Resolve which work item a claim targets: an explicit id, otherwise the
 * highest-priority unassigned open item (the JIT pickup queue).
 */
function selectClaimTarget(store, { id } = {}) {
  if (id) {
    const item = store.getWorkItemById(id);
    if (!item) {
      throw new Error(`Work item not found: ${id}`);
    }
    return item;
  }
  const { items } = store.listWorkItems({ limit: 100 });
  return items.filter(item => !item.owner && isOpenStatus(item.status)).sort((a, b) => priorityRank(a.priority) - priorityRank(b.priority))[0] || null;
}

/**
 * Claim an unassigned work item for an agent or human. Sets the owner (and
 * optional assigneeKind) and moves the card to running unless an explicit
 * status is supplied. Returns { claimed, item } or { claimed: false, reason }.
 */
function claimWorkItem(store, { id, owner, assigneeKind, sessionId, status } = {}) {
  if (!owner) {
    throw new Error('claim requires an owner.');
  }
  const kind = assigneeKind ? String(assigneeKind).toLowerCase() : null;
  if (kind && !VALID_ASSIGNEE_KINDS.has(kind)) {

View on GitHub (pinned to 8321021c54)