{"record":{"id":"e888e22c37bad9ba","repo":"mastra-ai/mastra","slug":"harness-pending-item-pendingitemid-was-not-fo","errorCode":null,"errorMessage":"Harness pending item \"${pendingItemId}\" was not found on session \"${sessionId}\"","messagePattern":"Harness pending item \"(.+?)\" was not found on session \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/harness/base.ts","lineNumber":75,"sourceCode":"      throw new Error(`Harness session \"${sessionId}\" was not found`);\n    }\n\n    let found = false;\n    const pending = (record.pending ?? []).map(item => {\n      if (item.id !== pendingItemId) return item;\n      found = true;\n      return {\n        ...item,\n        ...updates,\n        id: item.id,\n        sessionId: item.sessionId,\n        createdAt: item.createdAt,\n        updatedAt: new Date(),\n      };\n    });\n\n    if (!found) {\n      throw new Error(`Harness pending item \"${pendingItemId}\" was not found on session \"${sessionId}\"`);\n    }\n\n    return this.updateSession(sessionId, { pending });\n  }\n\n  async removePendingItem(sessionId: string, pendingItemId: string): Promise<SessionRecord> {\n    const record = await this.loadSession(sessionId);\n    if (!record) {\n      throw new Error(`Harness session \"${sessionId}\" was not found`);\n    }\n\n    return this.updateSession(sessionId, {\n      pending: (record.pending ?? []).filter(item => item.id !== pendingItemId),\n    });\n  }\n}\n","sourceCodeStart":57,"sourceCodeEnd":92,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/harness/base.ts#L57-L92","documentation":"`updatePendingItem` maps over the session's pending items looking for one whose id matches `pendingItemId`; if none matched after the full pass, it throws this error. The session existed, but the specific pending item did not.","triggerScenarios":"Calling `updatePendingItem` with a pendingItemId that was never appended, was already removed via `removePendingItem`, or belongs to a different session.","commonSituations":"Updating an item after it was finalized/removed by the harness; mixing item ids across sessions; double-processing where one worker already removed the item it completed; copy-paste of item id from logs of another session.","solutions":["Check that the pending item exists (`loadSession` then inspect `record.pending`) before updating.","Verify `pendingItemId` comes from the same session's `appendPendingItem` result.","Handle the already-removed case gracefully: treat item-not-found as a no-op in idempotent workflows.","Log session id plus item id together to catch cross-session id reuse."],"exampleFix":"// before\nawait storage.updatePendingItem(sessionId, itemId, { status: 'done' }); // throws if removed\n// after\nconst rec = await storage.loadSession(sessionId);\nif (rec?.pending?.some(i => i.id === itemId)) {\n  await storage.updatePendingItem(sessionId, itemId, { status: 'done' });\n}","handlingStrategy":"validation","validationCode":"const record = await storage.loadSession(sessionId);\nif (!record?.pending?.some(i => i.id === pendingItemId)) {\n  return; // nothing to update\n}\nawait storage.updatePendingItem(sessionId, pendingItemId, updates);","typeGuard":"function hasPendingItem(r: SessionRecord | null, itemId: string): r is SessionRecord {\n  return r != null && Array.isArray(r.pending) && r.pending.some(i => i.id === itemId);\n}","tryCatchPattern":"try {\n  await storage.updatePendingItem(sessionId, itemId, updates);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('pending item') && e.message.includes('was not found')) {\n    return; // already removed — treat as no-op in idempotent flows\n  }\n  throw e;\n}","preventionTips":["Only update item ids that came from appendPendingItem on the same session.","Treat item-not-found as a no-op in retry/idempotent paths.","Don't remove pending items before final updates complete.","Correlate itemId with sessionId in logs to catch cross-session reuse."],"tags":["storage","harness","pending-item-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}