{"record":{"id":"522e88d6766128b7","repo":"coleam00/Archon","slug":"failed-to-clear-workflow-wait-err-message","errorCode":null,"errorMessage":"Failed to clear workflow wait: ${err.message}","messagePattern":"Failed to clear workflow wait: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":1523,"sourceCode":"        data: completion.result,\n      });\n      await insertWorkflowEvent(query, {\n        workflow_run_id: id,\n        event_type: 'node_completed',\n        step_name: completion.stepName,\n        data: {\n          type: 'wait',\n          duration_ms: completion.result.waited_ms,\n          node_output: JSON.stringify(completion.result),\n          structured_output: completion.result,\n        },\n      });\n      return { cleared: true };\n    });\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err, workflowRunId: id }, 'db.workflow_wait_clear_failed');\n    throw new Error(`Failed to clear workflow wait: ${err.message}`);\n  }\n}\n\n/** Return a bounded set of time/deadline waits eligible for a resume claim. */\nexport async function listDueWorkflowContinuations(\n  now: Date,\n  limit: number\n): Promise<WorkflowRun[]> {\n  const resumeAt =\n    getDatabaseType() === 'postgresql'\n      ? \"metadata->'wait'->>'resumeAt'\"\n      : \"json_extract(metadata, '$.wait.resumeAt')\";\n  const signaledAt =\n    getDatabaseType() === 'postgresql'\n      ? \"metadata->'wait'->>'signaledAt'\"\n      : \"json_extract(metadata, '$.wait.signaledAt')\";\n  const scheduledResumeAt =\n    getDatabaseType() === 'postgresql'","sourceCodeStart":1505,"sourceCodeEnd":1541,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L1505-L1541","documentation":"Thrown by clearWorkflowWait in packages/core/src/db/workflows.ts when the transactional UPDATE that removes the `metadata.wait` object (and inserts wait_completed/wait_expired events) fails against SQLite or PostgreSQL. It is a contextual rethrow: the original driver error is logged under `db.workflow_wait_clear_failed` and its message is embedded. The function returns `{cleared:false}` (not an error) when the wait row simply does not match, so this throw always means a database-level failure, not a missed match.","triggerScenarios":"Calling clearWorkflowWait(id, waitContext, completion) when the database connection is down, the underlying `remote_agent_workflow_runs` UPDATE or insertWorkflowEvent calls fail (lock timeout, SQL error, JSON-path expression invalid for the configured dialect), or the withTransaction callback rejects.","commonSituations":"Postgres restarted or connection pool exhausted during a workflow resume; schema drift so metadata columns/dialect JSON functions mismatch; a database in read-only mode (disk full, replica); concurrent transaction lock contention on the run row.","solutions":["Check the logged `db.workflow_wait_clear_failed` entry for the underlying driver message and fix that root cause first","Verify database connectivity (server up, pool not exhausted) and retry the resume","Confirm the configured database type (sqlite/postgresql) matches the actual schema so JSON-path expressions are valid","If disk-full/read-only, free space or restore write access before resuming"],"exampleFix":"// before\nclearWorkflowWait(runId, waitCtx, completion); // throws opaque 'Failed to clear workflow wait: ...'\n// after\ntry {\n  const { cleared } = await clearWorkflowWait(runId, waitCtx, completion);\n  if (!cleared) logger.warn({ runId }, 'wait already cleared or status changed');\n} catch (e) {\n  logger.error({ runId, cause: e }, 'clearing wait failed; will retry resume');\n}","handlingStrategy":"try-catch","validationCode":"// before calling\nclassic check: ensure the run exists and is paused with the expected wait\nconst run = await getWorkflowRun(id);\nconst canClear = run?.status === 'running' && run.metadata?.wait?.nodeId === waitContext.nodeId;","typeGuard":"function isEventOrTimeWait(w: unknown): w is WorkflowWaitContext {\n  return typeof w === 'object' && w !== null && 'kind' in w && 'nodeId' in w && 'resumeAt' in w;\n}","tryCatchPattern":"try {\n  const { cleared } = await clearWorkflowWait(id, waitContext, completion);\n  if (!cleared) log.info({ id }, 'wait not matched; run state moved on');\n} catch (error) {\n  const cause = (error as Error).message.replace('Failed to clear workflow wait: ', '');\n  log.error({ id, cause }, 'clear workflow wait failed');\n  throw error; // resume pipeline should handle retry\n}","preventionTips":["Keep the database reachable and pool sized for resume traffic","Never edit `metadata.wait` JSON out-of-band; use the library APIs","Pin one database engine per deployment so dialect JSON paths stay valid","Monitor `db.workflow_wait_clear_failed` log events as an SLO signal"],"tags":["database","workflow","transaction"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}