Bug Report
Platform
- Pi coding agent (Windows)
- context-mode v1.0.129
Problem
When spawning subagents via Pi's subagent() tool (parallel mode), each child agent tries to load the context-mode extension. The extension's db-lock.js (acquireDbLock) detects the parent process's PID lockfile and throws DatabaseLockedError:
Failed to load extension "context-mode/build/adapters/pi/extension.js":
Another context-mode server is already running (PID: 4524). Stop it before starting a new instance.
This makes all subagents fail immediately — they cannot even start.
Root Cause
db-lock.js enforces single-writer via a PID-based lockfile (<dbPath>.lock). This is correct for standalone instances but breaks when:
- Parent agent starts context-mode (holds the lock)
- Parent spawns child subagents that inherit the same extension config
- Each child tries to acquire the same lock →
DatabaseLockedError
Current Workaround
Create a custom agent with extensions: "" (empty) to skip context-mode entirely:
subagent({ action: "create", config: { name: "ida-decompiler", extensions: "", ... } })
This works but means child agents lose all context-mode benefits (ctx_execute, ctx_search, etc.)
Proposed Fix Options
- Read-only mode for child processes: Detect that the lock is held by the parent process and open SQLite in read-only mode instead of throwing
- Per-process temp DB: Child agents already use tmpdir-based DBs (which
isUnderTmpdir skips) — but the shared project DB path triggers the lock
- Graceful skip: If extension loads in a subagent context (detect via env var or Pi API), skip DB initialization entirely rather than crashing
- Share the lock: Allow child processes to share the parent's DB connection via IPC instead of opening their own
Reproduction
- Start Pi with context-mode extension enabled
- Run
subagent({ tasks: [{ agent: "delegate", task: "hello" }, { agent: "delegate", task: "world" }], concurrency: 2 })
- Both subagents fail with
DatabaseLockedError
Related: #233 (ctx_commands injection in subagent sessions)
Bug Report
Platform
Problem
When spawning subagents via Pi's
subagent()tool (parallel mode), each child agent tries to load the context-mode extension. The extension'sdb-lock.js(acquireDbLock) detects the parent process's PID lockfile and throwsDatabaseLockedError:This makes all subagents fail immediately — they cannot even start.
Root Cause
db-lock.jsenforces single-writer via a PID-based lockfile (<dbPath>.lock). This is correct for standalone instances but breaks when:DatabaseLockedErrorCurrent Workaround
Create a custom agent with
extensions: ""(empty) to skip context-mode entirely:This works but means child agents lose all context-mode benefits (ctx_execute, ctx_search, etc.)
Proposed Fix Options
isUnderTmpdirskips) — but the shared project DB path triggers the lockReproduction
subagent({ tasks: [{ agent: "delegate", task: "hello" }, { agent: "delegate", task: "world" }], concurrency: 2 })DatabaseLockedErrorRelated: #233 (ctx_commands injection in subagent sessions)