Skip to content

GjcRuntime has no termination path: worker sessions and nested mcp serve leak on every run (success and failure) #2326

Description

@Q00

Symptom (production, 2026-08-31)

A failed `execute_seed --runtime gjc` run left 19 gjc worker (bun) processes and 18 nested `ouroboros mcp serve --runtime gjc` children alive 17+ minutes after the run ended, each holding DB connections — a major contributor to the pool-exhaustion incident.

Root causes (audited on main @ v0.52.0)

  1. `GjcRuntime._build_runtime_handle` (orchestrator/gjc_runtime.py:120-160) never calls `bind_controls`, so `can_terminate` is False and every existing termination path (per-AC finally in parallel_executor, run-level finallys in runner, cancel/escalation paths) is a silent no-op for gjc. Only codex/opencode bind a terminate callback.
  2. `GjcCoordinatorClient.stop_session` exists (gjc/sdk_client.py:390) but is never called from the agent-runtime path — the finally only disconnects the coordinator client (gjc_runtime.py:376-381). The success path leaks sessions too.
  3. gjc workers inherit the project env and cwd verbatim (sdk_client.py:104, bypassing `build_child_env`), read the project `.mcp.json`, and spawn one nested `ouroboros mcp serve` per AC attempt. claude has `--strict-mcp-config` and codex has `enabled=false`; gjc has no equivalent suppression.
  4. No run-scoped reaper: `execute_parallel` has no outer try/finally sweeping runtimes; `_close_adapter` only calls `aclose` where it exists (not on GjcRuntime).

Fix plan (single PR)

  • Call `stop_session` in the gjc turn finally on terminal states.
  • Bind a terminate callback on the gjc RuntimeHandle so the already-wired termination paths start working.
  • Suppress project MCP config / route env through `build_child_env` for gjc workers to stop nested serve spawns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions