t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Thread run stays in 'running' state indefinitely after assistant completes turn if command item remains open

Open HITECHDEM opened this issue 2 weeks ago • 3 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. In an ACP provider thread (e.g. Antigravity or OpenCode), initiate a multi-step turn where an agent triggers a command execution turn item.
  2. The agent outputs its final assistant message and marks its turn completed (PLANNER_RESPONSE with status DONE and tool_calls: []), but the turn item in orchestration_v2_projection_turn_items (type command_execution) was not explicitly resolved/closed by the coordinator.
  3. Observe the thread status in T3 Code UI and query the projection database statev2.sqlite.

Expected behavior

T3 Code's server turn coordinator should reconcile turn items when the assistant finishes its turn. If the assistant emitted its final message and the agent reports DONE, any remaining pending command item should be automatically reconciled/closed, transitioning orchestration_v2_projection_runs to idle/done and releasing the composer.

Actual behavior

The run remains indefinitely in status = 'running' inside orchestration_v2_projection_runs:

  • The desktop/web UI displays an active spinner and disables the composer.
  • Neither an error nor a prompt can be submitted without manually interrupting the thread or sending a thread.stop command over WebSocket.

Querying statev2.sqlite reveals the deadlock:

SELECT r.run_id, r.status, r.thread_id,
       (SELECT MAX(updated_at) FROM orchestration_v2_projection_messages WHERE role = 'assistant' AND thread_id = r.thread_id) AS last_asst_at,
       (SELECT MAX(updated_at) FROM orchestration_v2_projection_turn_items WHERE type = 'command_execution' AND status = 'running' AND thread_id = r.thread_id) AS open_cmd_at
FROM orchestration_v2_projection_runs r
WHERE r.status = 'running';

Here, last_asst_at >= open_cmd_at and the ACP agent's transcript shows PLANNER_RESPONSE status DONE with 0 pending tool calls, but the thread coordinator never resolves the run.

Impact

Blocks work completely

Version or commit

T3 Code 0.1.9 / core 0.169.0

Environment

Windows 11 x64, Desktop app, Provider: Antigravity ACP (agy_acp_server)

Workaround

We had to run an external watchdog daemon that queries statev2.sqlite, detects this post-reply zombie condition (last_asst_at >= open_cmd_at && agent idle > 150s), and dispatches a thread.stop command over the server's WebSocket RPC:

{
  "_tag": "Request",
  "tag": "orchestration.dispatchCommand",
  "payload": {
    "type": "thread.stop",
    "threadId": "<thread_id>",
    "reason": "Post-reply zombie with open command turn item",
    "stopDelegatedTasks": false
  }
}

Suggested Fix: In T3 Code server turn-management / projection loop, add an auto-reconciliation check when assistant emits final text with no further tool calls: auto-complete or mark lingering command execution turn items as resolved, and transition the run to idle.

HITECHDEM avatar Nov 15 '26 22:11 HITECHDEM

Update with further cross-verification from production telemetry:

This deadlock specifically triggers in the server turn projection loop when an ACP turn emits an assistant completion (PLANNER_RESPONSE status DONE, empty tool call set), but the projection database still holds an unresolved command_execution entry in orchestration_v2_projection_turn_items (often originating from async commands or tool-item timing races).

Because orchestration_v2_projection_runs relies on all items in the turn being terminalized, the turn coordinator never transitions the run to idle. The current effective workaround is an external watchdog polling statev2.sqlite that issues an explicit hread.stop via WebSocket RPC when last_asst_at >= open_cmd_at with no further agent activity for > 150s.

A natural fix in the turn coordinator is to auto-reconcile/terminalize orphaned open command items when an assistant emits its terminal message with status DONE.

HITECHDEM avatar Nov 15 '26 23:11 HITECHDEM

@HITECHDEM Does this still happen on T3 Code 0.1.10 or newer with Antigravity's native CLI runtime (1.5.x, installed from Settings → Providers → Antigravity) instead of the legacy agy_acp_server? If it does, please attach the provider log for one stuck turn, so we can see whether the agent's session/prompt request ever returned a stopReason.

juliusmarminge avatar Nov 19 '26 02:11 juliusmarminge

@juliusmarminge Re-tested on T3 Code 0.1.11-nightly (0.1.11-nightly.20261119.4954) with Antigravity CLI 1.5.12 / 1.5.13:

This deadlock condition no longer reproduces. In our projection database (statev2.sqlite), turns that execute commands now resolve all orchestration_v2_projection_turn_items cleanly to 0 open items upon assistant turn completion, and runs properly transition to completed, interrupted, or failed rather than remaining stranded in running.

The issue appears resolved in 0.1.10+ / 0.1.11-nightly. Closing this out. Thank you!

HITECHDEM avatar Nov 20 '26 00:11 HITECHDEM