openclaw - ✅(Solved) Fix Unhandled promise rejection: NOT NULL constraint on task_runs.requester_session_key crashes gateway [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58827Fetched 2026-04-08 02:32:14
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Participants
Assignees
Timeline (top)
assigned ×1cross-referenced ×1

Error Message

[openclaw] Unhandled promise rejection: Error: NOT NULL constraint failed: task_runs.requester_session_key
    at upsertTaskWithDeliveryStateToSqlite (pi-embedded-BE6Oo-8e.js:14879:24)
    at withWriteTransaction (pi-embedded-BE6Oo-8e.js:14849:3)
    at persistTaskUpsert (pi-embedded-BE6Oo-8e.js:14968:9)
    at updateTask (pi-embedded-BE6Oo-8e.js:15269:2)
    at updateTaskStateByRunId (pi-embedded-BE6Oo-8e.js:15657:16)
    at markTaskTerminalByRunId (pi-embedded-BE6Oo-8e.js:15698:9)
    at completeTaskRunByRunId (pi-embedded-BE6Oo-8e.js:15875:9)
    at completeSubagentRun (pi-embedded-BE6Oo-8e.js:16223:47)

Root Cause

  • #58786 (subagent announce timeout destabilizes gateway — may share root cause with corrupt task state)

Fix Action

Workaround

Deleting the corrupted database allows fresh starts:

mv ~/.openclaw/tasks/runs.sqlite ~/.openclaw/tasks/runs.sqlite.bak

PR fix notes

PR #58869: fix(subagents): harden task-registry lifecycle writes

Description (problem / solution / changelog)

Addresses #58827

Summary

  • make subagent lifecycle task-registry writes explicitly best-effort instead of letting registry errors reject the completion path
  • harden both terminal task updates and delivery-status updates in the subagent lifecycle controller
  • add focused regressions proving subagent completion and cleanup still finish when task-registry writes throw

Verification

  • pnpm test -- src/agents/subagent-registry-lifecycle.test.ts
  • pnpm test -- src/agents/subagent-registry.test.ts
  • pnpm check
  • pnpm build

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/subagent-registry-lifecycle.test.ts (added, +167/-0)
  • src/agents/subagent-registry-lifecycle.ts (modified, +95/-26)

Code Example

[openclaw] Unhandled promise rejection: Error: NOT NULL constraint failed: task_runs.requester_session_key
    at upsertTaskWithDeliveryStateToSqlite (pi-embedded-BE6Oo-8e.js:14879:24)
    at withWriteTransaction (pi-embedded-BE6Oo-8e.js:14849:3)
    at persistTaskUpsert (pi-embedded-BE6Oo-8e.js:14968:9)
    at updateTask (pi-embedded-BE6Oo-8e.js:15269:2)
    at updateTaskStateByRunId (pi-embedded-BE6Oo-8e.js:15657:16)
    at markTaskTerminalByRunId (pi-embedded-BE6Oo-8e.js:15698:9)
    at completeTaskRunByRunId (pi-embedded-BE6Oo-8e.js:15875:9)
    at completeSubagentRun (pi-embedded-BE6Oo-8e.js:16223:47)

---

mv ~/.openclaw/tasks/runs.sqlite ~/.openclaw/tasks/runs.sqlite.bak
RAW_BUFFERClick to expand / collapse

Problem

Gateway crashes with an unhandled promise rejection when completing a subagent run, due to a NOT NULL constraint violation on task_runs.requester_session_key.

Error

[openclaw] Unhandled promise rejection: Error: NOT NULL constraint failed: task_runs.requester_session_key
    at upsertTaskWithDeliveryStateToSqlite (pi-embedded-BE6Oo-8e.js:14879:24)
    at withWriteTransaction (pi-embedded-BE6Oo-8e.js:14849:3)
    at persistTaskUpsert (pi-embedded-BE6Oo-8e.js:14968:9)
    at updateTask (pi-embedded-BE6Oo-8e.js:15269:2)
    at updateTaskStateByRunId (pi-embedded-BE6Oo-8e.js:15657:16)
    at markTaskTerminalByRunId (pi-embedded-BE6Oo-8e.js:15698:9)
    at completeTaskRunByRunId (pi-embedded-BE6Oo-8e.js:15875:9)
    at completeSubagentRun (pi-embedded-BE6Oo-8e.js:16223:47)

Timeline

  1. 15:11 — Heartbeat triggers, spawns subagent. Also logs: Failed to create background task for subagent run with ERR_SQLITE_ERROR / errcode: 1299 (constraint failed)
  2. 15:19 — Subagent completes, completeSubagentRun calls upsertTaskWithDeliveryState with null requester_session_key → unhandled promise rejection
  3. 15:25 — Gateway process crashes and restarts (new PID observed)

Probable cause

The subagent task row was not properly created at spawn time (step 1 already failed with constraint error). When the subagent later completed and tried to upsert the delivery state, the missing row caused a NOT NULL violation that was not caught, leading to an unhandled rejection that killed the process.

Workaround

Deleting the corrupted database allows fresh starts:

mv ~/.openclaw/tasks/runs.sqlite ~/.openclaw/tasks/runs.sqlite.bak

Impact

  • Gateway crashes → all channels disconnect
  • Running subagents lose their delivery target
  • Requires manual restart

Expected behavior

  1. completeSubagentRun should handle missing/corrupt task rows gracefully (try/catch)
  2. If task creation fails at spawn time, the error should not silently propagate to completion time
  3. SQLite constraint violations should never cause unhandled promise rejections

Environment

  • OpenClaw: 2026.4.1
  • OS: Linux 6.8.0-106-generic (x64)
  • Node: v22.22.1

Related

  • #58786 (subagent announce timeout destabilizes gateway — may share root cause with corrupt task state)

extent analysis

TL;DR

  • The most likely fix is to handle missing or corrupt task rows in the completeSubagentRun function to prevent unhandled promise rejections.

Guidance

  • Verify that the upsertTaskWithDeliveryState function is properly handling NULL values for requester_session_key to prevent NOT NULL constraint violations.
  • Implement a try/catch block in the completeSubagentRun function to catch and handle any errors that occur when upserting the delivery state, including NOT NULL constraint violations.
  • Investigate why the subagent task row was not properly created at spawn time and address the root cause of the ERR_SQLITE_ERROR with `errcode:

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  1. completeSubagentRun should handle missing/corrupt task rows gracefully (try/catch)
  2. If task creation fails at spawn time, the error should not silently propagate to completion time
  3. SQLite constraint violations should never cause unhandled promise rejections

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING