zai-org / zai-org/feedback

[Bug] Background subagent completion notifications dropped with "database is not open" — parent turn never re-invoked (3.10.2 macOS)

Open
#447 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · Pre-submission checklist
  • I searched existing issues and confirmed this isn't a duplicate. (Closest: #397 — same symptom class "no turn starts after background completion", but different root cause: remote compact vs local subagent DB admission failure.)
  • I've read CONTRIBUTING.md.
问题类别 · Category

后台任务 / 子代理 · Background tasks / subagents

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

影响功能 · Major (work is completed but the orchestrating session is never notified)

复现频率 · Reproducibility

偶发,但一次会话内三个并行后台 agent 全部命中(3/3)

问题描述 · Description

When background subagents (spawned via the Agent tool with run_in_background: true) complete, the completion notification is generated and enqueued, but admitting it into the session ledger fails with "database is not open". The background turn that should re-invoke the parent session is then cancelled, and the task registry drops the agent handles entirely — TaskOutput returns No task found with ID, SendMessage returns No active local_agent task found. The user must manually prompt the session to continue.

Log events from ~/.zcode/cli/log/zcode-2026-08-31.jsonl (all within one session, timestamps 15:33–15:46 local):

runtime.background_task_notifications.sealed  (reason: subagent_terminal)
background_task.notification.runtime_enqueued (queueSize: 1)
session_input.admit_failed  "Failed to admit background notification to ledger" — errorMessage: "database is not open"
background_task.notification.batch_failed     — errorMessage: "database is not open"
subagent.background.failed                    — errorMessage: "database is not open"
bootstrap.zcode_protocol "v4 background turn failed" — error: "Turn was cancelled."

5 occurrences of "database is not open" in total. The session DB (~/.zcode/cli/db/db.sqlite + WAL) is present and writable before/after the failure window, which suggests the ledger connection handle was closed or not yet (re)opened when the notification arrived — a race between subagent terminal notification and session DB lifecycle. For reference, the OpenCode lineage fixed a similar signature ("database is not open in ephemeral CLI flows", openclaw #20556/#7464).

复现步骤 · Steps to reproduce
  1. ZCode 3.10.2 desktop app on macOS 27.0 arm64, local project session.
  2. Spawn 3 subagents concurrently with the Agent tool, run_in_background: true (each doing multi-minute multi-file work).
  3. End the turn while they run (wait for automatic completion notifications).
  4. All three complete (their edits land in the working tree), but no notification turn starts; task registry has no record of the agents.
期望行为 · Expected behavior

The completion notification is durably admitted to the session ledger (retry/reopen the DB handle if closed) and the parent turn is re-invoked, or at minimum the task handles remain queryable via TaskOutput.

环境信息 · Environment
  • ZCode desktop 3.10.2 (latest at time of writing; changelog has no entry covering this)
  • macOS 27.0.0 arm64
  • Local (non-remote) session, default SQLite session storage
临时规避 · Workaround

Dispatch parallel subagents as multiple synchronous Agent calls in one message (they run concurrently and return in-turn), avoiding the background notification path entirely.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the events in ~/.zcode/cli/log/zcode-2026-08-31.jsonl, especially session_input.admit_failed and background_task.notification.batch_failed, then trace the session database lifecycle around subagent completion. Done means completion notifications are admitted, the parent turn is re-invoked, and task handles remain queryable when admission encounters a closed database.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.