Skip to content

ACP: session/resume fails with "Client must Subscribe with a working_dir before sending stateful requests" (code=-32603) #779

Closed

Description

@maxivillus

Summary

jcode acp advertises loadSession: true and sessionCapabilities.resume in its
initialize response, but session/resume always fails when it is the first
stateful request on a connection:

Client must Subscribe with a working_dir before sending stateful requests (code=-32603)

Impact

Any ACP client that resumes a session (a second task in the same conversation
thread, "continue", IDE reconnect, etc.) cannot work. The first task on a fresh
session/new succeeds; the next one that tries session/resume fails.

We hit this from a client that keeps one conversation per issue and resumes the
session for every follow-up task: the first task passes, every subsequent task in
the thread fails.

Root cause

The jcode daemon requires the first request on a connection to be
Subscribe { working_dir: <absolute path> }; any stateful request before that is
rejected. See
crates/jcode-app-core/src/server/client_lifecycle.rs:

fn initial_subscribe_working_dir(request: &Request) -> Result<String, String> {
    match request {
        Request::Subscribe { working_dir, .. } => {
            required_subscribe_working_dir(working_dir.as_deref()).map(str::to_string)
        }
        _ => Err(
            "Client must Subscribe with a working_dir before sending stateful requests".to_string(),
        ),
    }
}

In src/cli/acp.rs, create_new_session correctly subscribes first:

session
    .send(&Request::Subscribe {
        id: subscribe_id,
        working_dir: Some(cwd.display().to_string()),
        selfdev: None,
        target_session_id: None,
        client_instance_id: Some("acp".to_string()),
        client_has_local_history: false,
        allow_session_takeover: false,
        terminal_env: crate::terminal_launch::snapshot_client_terminal_env(),
    })
    .await?;

but attach_existing_session (used by session/resume and session/load) sends a
bare Request::ResumeSession as the opening request:

let resume_id = 1;
session
    .send(&Request::ResumeSession {
        id: resume_id,
        session_id: target_session_id.clone(),
        client_instance_id: Some("acp".to_string()),
        client_has_local_history: false,
        allow_session_takeover: false,
    })
    .await?;

That is the first thing the server sees on this connection, so it returns the
-32603 error above.

Suggested fix

Subscribe with target_session_id before (or instead of) the bare
ResumeSession. The server already handles resume inside Subscribe when
target_session_id is set: client_lifecycle.rs calls handle_resume_session
and then handle_subscribe, emitting History + Done. This is the same shape
create_new_session uses, so attach_existing_session should do:

session
    .send(&Request::Subscribe {
        id: resume_id,
        working_dir: Some(cwd.display().to_string()),
        selfdev: None,
        target_session_id: Some(target_session_id.clone()),
        client_instance_id: Some("acp".to_string()),
        client_has_local_history: false,
        allow_session_takeover: false,
        terminal_env: crate::terminal_launch::snapshot_client_terminal_env(),
    })
    .await?;

The _cwd parameter of attach_existing_session should also be used (rename to
cwd) instead of being ignored, since the working directory is now required.

Steps to reproduce

  1. jcode acp --provider <provider> --model <model> --tool-profile full
  2. Send over stdin:
    {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientInfo":{"name":"t","version":"1"},"clientCapabilities":{}}}
    {"jsonrpc":"2.0","id":2,"method":"session/new","params":{"cwd":"/tmp"}}
  3. Capture the returned sessionId, run a session/prompt, then send:
    {"jsonrpc":"2.0","id":3,"method":"session/resume","params":{"sessionId":"<captured>","cwd":"/tmp"}}
  4. Observe:
    {"id":3,"jsonrpc":"2.0","error":{"code":-32603,"message":"Client must Subscribe with a working_dir before sending stateful requests"}}

Environment

  • jcode v0.67.1 (also present on master src/cli/acp.rs)
  • Linux x86_64
  • ACP protocolVersion 1

Activity

  1. maxivillus commented on Aug 4, 2026

    @maxivillus
    Author

    Related: session/set_model is also unimplemented

    The ACP handler in src/cli/acp.rs only implements initialize, session/new,
    session/load, session/resume, session/prompt, session/cancel,
    session/close, and _-prefixed extensions. A client that calls
    session/set_model (e.g. to switch models per task, as Multica does from the
    agent card) gets Method not found. The daemon protocol already supports this
    via Request::SetModel { id, model } (with ServerEvent::ModelChanged), so the
    ACP layer could forward it directly.

    While here: accepting a reasoning-effort override (env var such as
    JCODE_REASONING_EFFORT mapped to Request::SetReasoningEffort, which the
    daemon already supports) would let ACP clients control DeepSeek/OpenAI thinking
    mode. Happy to open these as separate issues or extend this PR.

  2. added
    bug
    priority: high
    triage: reproducible
    autonomous: clear
    on Aug 4, 2026
  3. 1jehuang commented on Aug 4, 2026

    @1jehuang
    Owner

    The root cause is confirmed: ACP opened a fresh daemon connection with ResumeSession, but the daemon requires Subscribe with an absolute working directory as the first stateful request. PR #781 changes the attach path to subscribe with the request cwd and target session ID. The targeted ACP test build passes.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  4. added a commit that references this issue on Aug 4, 2026
    8d46f64
  5. added 5 commits that reference this issue on Aug 30, 2026
    f7262b5
    41abbe3
    70b5fb2
    497ce62
    a64c9b4
  6. added a commit that references this issue on Sep 18, 2026
    bbee183
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

    autonomous: clearbugpriority: hightriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions