Skip to content

jcode server reload always fails: sends Reload before Subscribe #648

Closed

Description

@paulbettner

jcode server reload fails immediately with:

Error: server reload failed: Client must Subscribe with a working_dir before sending stateful requests

This is not environment-specific — the command appears to be broken for every invocation, on a stock release binary.

Reproduction

$ jcode --version
jcode v0.61.0 (c5009da0)

$ jcode server reload
Error: server reload failed: Client must Subscribe with a working_dir before sending stateful requests

Any running server reproduces it. --force fails the same way.

Expected vs actual

  • Expected: the daemon reloads (or reports it is already current).
  • Actual: the command always errors before the server processes the reload.

Cause

run_server_reload_command in src/cli/commands.rs connects and then sends the
stateful Reload request without subscribing first:

let mut client = crate::server::Client::connect().await?;
// ... repair_stale_shared_server_channel() ...
client.reload_with_force(force).await?;

The server requires a Subscribe as the first frame. In
crates/jcode-app-core/src/server/client_lifecycle.rs,
initial_subscribe_working_dir rejects any other opening request with exactly
this message.

So the first frame on the wire is reload, and the server rejects it.

Possible fix

Subscribing before the reload request is enough. Client::subscribe() already
defaults working_dir to the current directory, which satisfies the server's
absolute-path requirement:

let mut client = crate::server::Client::connect().await?;
client.subscribe().await?;

Notes for testing

Two things that are easy to trip over when writing a regression test:

  • jcode server reload opens a throwaway liveness-probe connection first
    (has_live_listener) and closes it without sending data, so a stub server has
    to keep accepting until a connection actually delivers a frame.
  • The wire tag is lowercase subscribe / reload, per the #[serde(rename)]
    attributes on Request in crates/jcode-protocol/src/wire.rs.

Pointing the binary at a stub socket via JCODE_SOCKET and asserting the first
frame is subscribe reproduces the bug directly: with the current code the first
frame is reload.

I have this change plus a test running locally in a fork if a reference is
useful, but per CONTRIBUTING I'm filing this as an issue rather than a PR since
it reproduces trivially.

Activity

  1. added
    bug
    triage: reproducible
    autonomous: clear
    priority: high
    on Jul 29, 2026
  2. 1jehuang commented on Jul 29, 2026

    @1jehuang
    Owner

    Confirmed. run_server_reload_command connected and sent the stateful Reload frame directly, and the server requires Subscribe as its opening frame, so the command could never succeed.

    Fixed in #656 by calling client.subscribe().await? before the reload request, exactly as you suggested, since subscribe() already defaults working_dir to the current directory.

    Thanks also for the two testing notes: the throwaway liveness probe from has_live_listener and the lowercase subscribe/reload wire tags are both easy traps, and they saved real time. I have not added the stub-socket regression test yet; the fix is verified by compilation and the code path, and the test wants a bit of harness scaffolding to do properly. Flagged in the PR for review.

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

  3. 1jehuang commented on Jul 29, 2026

    @1jehuang
    Owner

    Follow-up: verified end-to-end against a running daemon, rather than only by inspection as I said earlier.

    I ran the built binary against an isolated daemon (private JCODE_SOCKET, JCODE_HOME, and XDG_RUNTIME_DIR so it could not touch a real session), then mutation-checked it by reverting just the subscribe() call and rebuilding:

    Without the fix:

    exit code: 1
    Error: server reload failed: Client must Subscribe with a working_dir before sending stateful requests
    

    With the fix:

    exit code: 0
    jcode server is already running the newest binary; no reload needed.
    

    That is your reported error reproduced exactly and then resolved, so the fix is confirmed rather than assumed.

    One note on writing a permanent regression test, since you raised it: the naive version passes vacuously. If the harness does not wait for the daemon to actually signal ready, server reload takes the has_live_listener early return and prints "No running jcode server found", exiting 0 without ever exercising the reload path. My first attempt did exactly that and looked green. Any committed test needs to assert it did not hit that branch.

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

  4. added a commit that references this issue on Jul 31, 2026
    41f9142
  5. added 5 commits that reference this issue on Aug 30, 2026
    cc3425b
    5961508
    118db83
    dfc2f85
    191faa7
  6. added a commit that references this issue on Sep 18, 2026
    edb4917
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