Skip to content

[Bug]: ACP replay-idle shortcut sends session/prompt before session/load responds, so the first prompt after a cold reconnect fails with Resource not found #37106

Closed

Description

@JingLi1998

Before submitting

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

Area

apps/server

Summary

When T3 starts a fresh ACP runtime for an existing session, the first prompt fails with -32002 Resource not found whenever the agent takes more than about 2 seconds after its last session/update to finish session/load.

The cause is the replay-idle shortcut in packages/provider-acp/src/server/AcpSessionRuntime.ts (defaultSessionLoadReplayIdleGap on line 82, runLoadSessionWithReplayIdle from line 1970). runLoadSessionWithReplayIdle races the session/load request against waitForSessionLoadReplayIdle. When the idle timer wins, T3 creates a result itself ({ _meta: { t3SessionLoadReady: "replay_idle" } }) and sends session/prompt before the agent has replied to session/load. The agent hasn't registered the session yet, so it rejects the prompt.

This is related to #21739 but is a different failure. #21739, #23586 and #36358 cover adopting the late session/load response's config. Even with those fixes, the prompt still reaches the agent before the agent says the session is ready.

Steps to reproduce

Use a stdio ACP test agent that supports session/load:

  1. When it receives session/load, send one session/update straight away. Any update works; available_commands_update or one replayed message is enough.
  2. Wait about 4 s, standing in for runtime, plugin or MCP warmup. Then register the session and reply to session/load.
  3. Have session/prompt return -32002 Resource not found for any session that isn't registered yet.
  4. In T3, open an existing thread for this agent in a fresh provider runtime. For example, settle and unsettle it, or wait for the idle unload. Then send a message.

Result: about 2 s after the update in step 1, T3 logs session/load as succeeded with a one-field result. About 40 ms later it sends session/prompt, which fails with Resource not found. The agent's real session/load reply arrives a couple of seconds later and is ignored.

Expected behavior

T3 should not send session/prompt for a loaded session until the agent has replied to session/load.

The ACP spec (Loading Sessions) says:

When all the conversation entries have been streamed to the Client, the Agent MUST respond to the original session/load request. … The Client can then continue sending prompts as if the session was never interrupted.

The spec's sequence diagram also places "Ready for prompts" after the session/load response. A replay-idle gap doesn't show that the agent is ready. Agents can do non-replay work after their last update, such as warming the runtime, and they may also send non-replay updates like available_commands_update during the load.

Actual behavior

waitForSessionLoadReplayIdle arms on the first update it receives, replay or not. It succeeds after defaultSessionLoadReplayIdleGap (2 s) with no further updates. Effect.raceFirst then interrupts the real session/load waiter, and T3 moves straight on to session/prompt.

Suggested fix

Either of these would work. Option 1 is closest to the spec.

  1. Wait for the real reply before prompting. Drop the replay-idle race, or use it only for agents that don't advertise loadSession. Keep defaultSessionLoadTimeout (90 s) as the fallback.
  2. Keep replay idle for display only. Let the idle gap mark the thread as usable in the UI, so history appears quickly. Hold any session/prompt, and other session-scoped requests such as session/set_config_option and session/cancel, until the real session/load reply arrives or the load times out. When the reply arrives, adopt its config as fix(acp): a late session/load response no longer leaves the session without model controls #23586 does.

Only ignoring available_commands_update in the activity check would not be enough. Replayed history also arms the timer, and any warmup longer than 2 s after the last replayed chunk would still trip it.

Impact

Major degradation or frequent failure.

For agents with a few seconds of warmup on load, every cold reconnect fails its first message. We saw 5 out of 5 with our agent. Settling and unsettling a thread, or the 30-minute idle unload (scheduleThreadUnload / releaseIfStillIdle), is enough to trigger it.

Version or commit

T3 Code (Beta) 0.1.9 desktop app

Environment

macOS 15.7.9. ACP stdio agent registered through the ACP registry provider. Its session/load takes about 4.6–6.2 s.

Logs or stack traces

# T3 provider event log (one thread, times in UTC)
05:53:14.225  session/load    started
05:53:16.273  session/load    succeeded   result: { fieldCount: 1 }   # synthetic { _meta: { t3SessionLoadReady: "replay_idle" } }
05:53:16.315  session/prompt  started
05:53:16.318  session/prompt  failed      AcpRequestError -32002 "Resource not found: <sessionId>"

# Agent log, same process
05:53:14.226  Loading session
05:53:18.848  ACP startup timing operation=loadSession state=success elapsedMs=4618   # real session/load reply

Workaround

On the agent side: queue session-scoped requests that arrive while a session/load is still running, and process them once the load finishes. We're adding this to our agent, but every ACP agent with a slow load would need the same workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions