{"record":{"id":"bb08be7e09ec666a","repo":"coleam00/Archon","slug":"failed-to-defer-workflow-continuation-err-messa","errorCode":null,"errorMessage":"Failed to defer workflow continuation: ${err.message}","messagePattern":"Failed to defer workflow continuation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":1617,"sourceCode":"  try {\n    await pool.query(\n      `UPDATE remote_agent_workflow_runs\n       SET metadata = ${dialect.jsonMerge('metadata', 2)}\n       WHERE id = $1 AND ((status = 'paused' AND ${waitResumeAt} = $3 AND ${waitNodeId} = $4)\n         OR (status = 'failed' AND ${scheduledResumeAt} = $3\n           AND ${scheduledTriggeredAt} IS NULL AND ${scheduledAttempt} = $5))`,\n      [\n        id,\n        JSON.stringify({ continuation_retry_at: retryAt }),\n        cursor.resumeAt,\n        cursor.kind === 'wait' ? cursor.nodeId : null,\n        cursor.kind === 'quota' ? cursor.attempt : null,\n      ]\n    );\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err, workflowRunId: id }, 'db.workflow_continuation_defer_failed');\n    throw new Error(`Failed to defer workflow continuation: ${err.message}`);\n  }\n}\n\n/** Atomically record the signal for one exact paused event wait. */\nexport async function signalWorkflowWait(\n  id: string,\n  waitContext: Extract<WorkflowWaitContext, { kind: 'event' }>,\n  payload?: unknown\n): Promise<{ signaled: boolean }> {\n  const parsedWaitContext = workflowWaitContextSchema.parse(waitContext);\n  if (parsedWaitContext.kind !== 'event') {\n    throw new Error('Cannot signal a non-event workflow wait');\n  }\n  const eventExpr =\n    getDatabaseType() === 'postgresql'\n      ? \"metadata->'wait'->>'event'\"\n      : \"json_extract(metadata, '$.wait.event')\";\n  const nodeExpr =","sourceCodeStart":1599,"sourceCodeEnd":1635,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L1599-L1635","documentation":"Thrown by deferWorkflowContinuation when the UPDATE that writes `continuation_retry_at` backoff metadata fails. The update is guarded (only matches a paused wait with exact resumeAt/nodeId or a failed scheduled resume with matching attempt), but this error is reserved for SQL/driver failures, which are logged under `db.workflow_continuation_defer_failed`. A zero-row match is silent, not an error.","triggerScenarios":"Calling deferWorkflowContinuation(id, retryAt, cursor) when the transaction fails, the connection drops, dialect jsonMerge produces invalid SQL, or a lock conflict on the run row times out.","commonSituations":"DB contention while many continuations back off concurrently; dialect mismatch (e.g. jsonMerge variant unsupported by the actual engine); transient network failure mid-backoff write.","solutions":["Inspect the `db.workflow_continuation_defer_failed` log for the real driver error","Retry the defer — it is idempotent metadata written only on an exact state match","Verify the dialect's jsonMerge implementation against the running database engine","Check for row-lock contention and serialize continuation processing if needed"],"exampleFix":"// before\nawait deferWorkflowContinuation(id, retryAt, cursor); // throws on transient failure\n// after\ntry {\n  await deferWorkflowContinuation(id, retryAt, cursor);\n} catch (e) {\n  logger.warn({ runId: id, err: e }, 'defer failed; continuation will be retried on next scan');\n}","handlingStrategy":"retry","validationCode":"// pre-check the run still matches the cursor before deferring\nconst run = await getWorkflowRun(id);\nconst matches = run != null && (\n  (run.status === 'paused' && run.metadata?.wait?.resumeAt === cursor.resumeAt) ||\n  (run.status === 'failed' && run.metadata?.scheduled_resume?.resumeAt === cursor.resumeAt)\n);","typeGuard":"function isContinuationCursor(c: unknown): c is WorkflowContinuationCursor {\n  return typeof c === 'object' && c !== null && 'kind' in c && 'resumeAt' in (c as Record<string, unknown>);\n}","tryCatchPattern":"try {\n  await deferWorkflowContinuation(id, retryAt, cursor);\n} catch (error) {\n  log.warn({ id, err: error }, 'defer failed; next scan will pick the continuation up');\n  // safe to swallow: the write is pure backoff metadata\n}","preventionTips":["Treat defer as best-effort backoff; never crash the worker over it","Avoid many concurrent defers on the same run to prevent lock contention","Validate cursor shape (kind, resumeAt, nodeId/attempt) before calling","Keep dialect jsonMerge implementations covered by tests for both engines"],"tags":["database","workflow","retry-backoff"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}