{"record":{"id":"5d5bdf95e84a36f5","repo":"windmill-labs/windmill","slug":"database-write-failed-e","errorCode":null,"errorMessage":"Database write failed: {e:?}","messagePattern":"Database write failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-worker/src/memory_oss.rs","lineNumber":40,"sourceCode":"}\n\n/// Write AI agent memory to storage\n/// In OSS: always writes to database\n#[cfg(not(all(feature = \"private\", feature = \"enterprise\")))]\npub async fn write_to_memory(\n    db: &DB,\n    workspace_id: &str,\n    conversation_id: Uuid,\n    step_id: &str,\n    messages: &[OpenAIMessage],\n) -> anyhow::Result<()> {\n    if messages.is_empty() {\n        return Ok(());\n    }\n\n    memory_common::write_to_db(db, workspace_id, conversation_id, step_id, messages)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Database write failed: {e:?}\"))\n}\n\n/// Delete all memory for a conversation from storage\n/// In OSS: always deletes from database\n#[cfg(not(all(feature = \"private\", feature = \"enterprise\")))]\npub async fn delete_conversation_memory(\n    db: &DB,\n    workspace_id: &str,\n    conversation_id: Uuid,\n) -> anyhow::Result<()> {\n    memory_common::delete_conversation_from_db(db, workspace_id, conversation_id)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Database delete failed: {e:?}\"))\n}\n","sourceCodeStart":22,"sourceCodeEnd":55,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-worker/src/memory_oss.rs#L22-L55","documentation":"OSS agent memory writer: `write_to_memory` wraps failures of `memory_common::write_to_db`, which persists the agent's messages for a conversation step. Only invoked when `messages` is non-empty; a failure means the conversation history for this step was not saved and later steps will resume without it.","triggerScenarios":"`run_agent` finishing a step calls `write_to_memory(db, workspace_id, conversation_id, step_id, messages)`; the DB insert fails — connection loss, write permission denied, table missing after an upgrade, row size limits exceeded by very large message payloads.","commonSituations":"Postgres connection pool exhausted under heavy agent concurrency; database in read-only mode (disk full); messages JSON exceeding column/row limits; OSS instance not migrated to the version that introduced memory tables.","solutions":["Inspect the `{e:?}` chain for the root cause (connection, permission, or size).","Check Postgres health: connectivity, disk space, connection pool saturation.","Ensure migrations have run so memory tables exist.","Re-run the agent step — the write happens after execution, so re-running regenerates and re-saves the messages."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// check writable DB + table presence before long agent runs\npsql \"$DATABASE_URL\" -c \"insert into agent_memory default values; rollback;\" >/dev/null || echo 'DB not writable'","typeGuard":null,"tryCatchPattern":"// retry the post-step write once; it happens after execution so it's safe to redo\nif let Err(e) = write_to_memory(&db, w_id, conv_id, &step_id, &msgs).await {\n    log::warn!(\"memory write failed: {e:?}; retrying once\");\n    write_to_memory(&db, w_id, conv_id, &step_id, &msgs).await?;\n}","preventionTips":["Monitor Postgres disk space and connection-pool saturation","Keep agent message payloads reasonably small (truncate huge tool outputs)","Run migrations on upgrade so memory tables exist"],"tags":["database","agent","memory","write"],"backgroundTag":"database-write-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}