Skip to content

A locally built binary can never reach the shared server: no caller for promote_version_to_shared_server #917

Closed

Description

@YalmutairiAisc

Summary

A locally built binary can reach the client but never the daemon, and nothing in the tree can move it there.

The daemon resolves its reload and spawn target from the shared-server channel:

  • spawn_server (src/cli/dispatch.rs:1296) -> build::shared_server_update_candidate(...)
  • reload_exec_target (crates/jcode-app-core/src/server/util.rs:102) -> newest_reload_candidate -> same

shared_server_update_candidate (crates/jcode-build-support/src/paths.rs:541) tries shared-server, then stable, then current_exe(). It never consults current.

But publish_local_current_build_for_source (crates/jcode-build-support/src/lib.rs:679), which is what self-dev --build calls, only moves current and the launcher:

let current_link = update_current_symlink(&source.version_label)?;
let launcher_link = update_launcher_symlink_to_current()?;

And the two functions that could advance the daemon's channel both decline in this case:

  • advance_shared_server_if_tracking_stable is only called from the update path.
  • repair_stale_shared_server_channel drags shared-server to stable, and returns AlreadyCurrent when the existing marker is not a release marker.

So after self-dev --build the client runs the new binary and the daemon keeps the old one indefinitely.

What that looks like

On this machine the client was on v0.75.8-dev while the server had been serving v0.65.0 since Aug 4, ten releases apart, over the same socket. Both of these are correct-but-useless:

$ jcode server reload --json
{"reloaded": false, "already_current": true,
 "detail": "jcode server is already running the newest binary; no reload needed."}

$ jcode server reload --force      # re-execs the SAME old binary
$ jcode selfdev status
Running: jcode v0.65.0 (d847d62e4)
Current: ee3b3f4a5
Shared server: 0.65.0

reload is truthful: relative to its own candidate (the stale channel) the daemon is current. --force bypasses server_has_newer_binary but still resolves the same candidate, so it cannot help either.

There is already an API for this, with no caller

/// Promote an already installed immutable version onto the shared server channel.
pub fn promote_version_to_shared_server(version: &str) -> Result<Option<String>> {

crates/jcode-build-support/src/lib.rs:726, re-exported through jcode-app-core/src/build.rs:14. grep -rn 'promote_version_to_shared_server(' matches only the definition and the re-export.

Suggested fix

Wire it to a command. I have this working locally as jcode server promote [VERSION] [--json], defaulting to whatever current points at:

$ jcode server promote --json
{
  "version": "ee3b3f4a5",
  "previous": "0.65.0",
  "binary": ".../builds/versions/ee3b3f4a5/jcode.exe",
  "promoted": true,
  "detail": "shared-server channel 0.65.0 -> ee3b3f4a5. Run `jcode server reload` to apply it ..."
}

$ jcode server reload --force
$ jcode selfdev status
Running: jcode v0.75.8-dev (ee3b3f4a5)

Kept as a separate step from reload rather than folded into it, since the pin exists precisely so an update never silently wipes out a self-dev build; promoting is the decision that pin protects. It reports previous so the move is reversible, refuses a version that is not installed (a dangling channel symlink would send the next server spawn down a silent fallback), and is idempotent.

An alternative worth considering: have self-dev --build offer to promote, or teach server reload to report why it considers itself current (naming the channel and version it resolved), so the state is at least discoverable. The current message actively misleads.

Environment

Windows 11 x86_64, jcode built from source at v0.75.5 + local commits. Same machine as #912 and #914; this is the third link in the same chain: the updater would not update (#912), self-dev could not build (#914), and even after building, the daemon could not be moved (this one).

Activity

  1. YalmutairiAisc commented on Aug 12, 2026

    @YalmutairiAisc
    Author

    Patch against master (rebased onto 994b8d3, v0.75.5) - jcode server promote. Applies clean with git am:

    dea37bb67 - jcode server promote
    From dea37bb67c5ed2d977b7d2b5446edc726dfe8445 Mon Sep 17 00:00:00 2001
    From: YalmutairiAisc <[email protected]>
    Date: Thu, 13 Aug 2026 00:08:48 +0300
    Subject: [PATCH] feat(server): promote an installed build to the shared-server
     channel
    
    The daemon resolves its reload and spawn target from the `shared-server`
    channel, never from `current`. `self-dev --build` publishes to `current`
    and the launcher only, and the update path advances `shared-server`
    solely while it is still tracking `stable`. So a locally built binary
    upgraded the client and left the long-lived daemon exactly where it was,
    with no supported way to close the gap.
    
    That is not hypothetical. On this machine the client ran v0.75.8-dev
    while the server had been serving v0.65.0 since Aug 4: ten releases and
    nine days apart, talking to each other over the same socket.
    `server reload` kept answering "already running the newest binary",
    which was true from the daemon's point of view and useless, because its
    candidate was the stale channel. `--force` re-exec'd the same old binary
    for the same reason.
    
    `promote_version_to_shared_server` already existed and was exported, and
    nothing in the tree called it. This wires it to a command:
    
        $ jcode server promote --json
        {
          "version": "ee3b3f4a5",
          "previous": "0.65.0",
          "promoted": true,
          "detail": "shared-server channel 0.65.0 -> ee3b3f4a5. Run
                     `jcode server reload` to apply it ..."
        }
        $ jcode server reload --force
        $ jcode selfdev status
        Running: jcode v0.75.8-dev (ee3b3f4a5)      # was v0.65.0
    
    Deliberately a separate step from `reload`, not folded into it: the
    pin exists so an update never silently wipes out a self-dev build, and
    promoting is exactly the decision that pin is protecting. The command
    reports `previous` so the move can be undone, refuses a version that is
    not installed (a dangling channel symlink would send the next server
    spawn down a silent fallback), and is idempotent: promoting the version
    already in the channel reports promoted=false and changes nothing.
    
    Verified: the not-installed guard exits non-zero with the path it
    looked for; a second promote is a no-op; and after promote + reload the
    running server reports the new version, which is the only check that
    actually matters here.
    ---
     src/cli/args.rs     | 20 +++++++++++
     src/cli/commands.rs | 84 +++++++++++++++++++++++++++++++++++++++++++++
     src/cli/dispatch.rs |  3 ++
     3 files changed, 107 insertions(+)
    
    diff --git a/src/cli/args.rs b/src/cli/args.rs
    index c639d48f3..f23613067 100644
    --- a/src/cli/args.rs
    +++ b/src/cli/args.rs
    @@ -633,6 +633,26 @@ pub(crate) enum ServerCommand {
             #[arg(long)]
             json: bool,
         },
    +
    +    /// Point the `shared-server` channel at an installed build so the daemon
    +    /// can reload into it.
    +    ///
    +    /// `self-dev --build` publishes to `current` and the launcher only, and the
    +    /// update path advances `shared-server` solely while it is still tracking
    +    /// `stable`. A locally built binary therefore upgrades the client while the
    +    /// long-lived daemon stays on its old release, and `server reload` answers
    +    /// "already running the newest binary" because it resolves its target from
    +    /// this channel, not from `current`. Promoting is the deliberate step that
    +    /// closes that gap; pair it with `server reload` to apply it.
    +    Promote {
    +        /// Installed version to promote, named as under `builds/versions/`.
    +        /// Defaults to whatever `current` points at.
    +        version: Option<String>,
    +
    +        /// Emit JSON instead of human-readable text
    +        #[arg(long)]
    +        json: bool,
    +    },
     }
     
     #[derive(Subcommand, Debug)]
    diff --git a/src/cli/commands.rs b/src/cli/commands.rs
    index 82fb3784a..7d56e3fcf 100644
    --- a/src/cli/commands.rs
    +++ b/src/cli/commands.rs
    @@ -2215,6 +2215,90 @@ pub async fn run_server_reload_command(force: bool, emit_json: bool) -> Result<(
     /// 2. Wait for the listener to go away (bounded), escalating to SIGKILL only if
     ///    the process refuses to exit.
     /// 3. Reap any leftover stale socket so a later launch binds cleanly.
    +/// Point the `shared-server` channel at an installed build.
    +///
    +/// The daemon resolves its reload/spawn target from this channel, never from
    +/// `current`, so a locally built binary published by `self-dev --build`
    +/// upgrades the client and leaves the daemon where it was. Without this the
    +/// only ways to close that gap were hand-editing the channel or waiting for a
    +/// release install, and `server reload` kept answering "already running the
    +/// newest binary" from the daemon's point of view, which is true and useless.
    +///
    +/// Refuses to promote a version that is not installed, and reports the previous
    +/// value so the move can be undone.
    +pub async fn run_server_promote_command(version: Option<String>, emit_json: bool) -> Result<()> {
    +    #[derive(Serialize)]
    +    struct ServerPromoteReport {
    +        version: String,
    +        previous: Option<String>,
    +        binary: String,
    +        promoted: bool,
    +        detail: String,
    +    }
    +
    +    let emit = |report: ServerPromoteReport| -> Result<()> {
    +        if emit_json {
    +            println!("{}", serde_json::to_string_pretty(&report)?);
    +        } else {
    +            println!("{}", report.detail);
    +        }
    +        Ok(())
    +    };
    +
    +    let version = match version {
    +        Some(version) => version.trim().to_string(),
    +        None => crate::build::read_current_version()?
    +            .map(|value| value.trim().to_string())
    +            .filter(|value| !value.is_empty())
    +            .ok_or_else(|| {
    +                anyhow::anyhow!(
    +                    "No `current` version marker to promote from; pass a version explicitly."
    +                )
    +            })?,
    +    };
    +
    +    // Promote only what is actually installed: the channel symlink would
    +    // otherwise dangle and the next server spawn would fall back silently.
    +    let binary = crate::build::version_binary_path(&version)?;
    +    if !binary.exists() {
    +        anyhow::bail!(
    +            "Version {} is not installed ({} does not exist). Run `jcode self-dev --build` first, \
    +             or pass a version present under builds/versions/.",
    +            version,
    +            binary.display()
    +        );
    +    }
    +
    +    let previous = crate::build::read_shared_server_version()?
    +        .map(|value| value.trim().to_string())
    +        .filter(|value| !value.is_empty());
    +
    +    if previous.as_deref() == Some(version.as_str()) {
    +        return emit(ServerPromoteReport {
    +            version: version.clone(),
    +            previous,
    +            binary: binary.display().to_string(),
    +            promoted: false,
    +            detail: format!("shared-server channel is already at {version}; nothing to do."),
    +        });
    +    }
    +
    +    let previous = crate::build::promote_version_to_shared_server(&version)?;
    +
    +    emit(ServerPromoteReport {
    +        version: version.clone(),
    +        previous: previous.clone(),
    +        binary: binary.display().to_string(),
    +        promoted: true,
    +        detail: format!(
    +            "shared-server channel {} -> {}. Run `jcode server reload` to apply it \
    +             (the running daemon keeps its old binary until then).",
    +            previous.as_deref().unwrap_or("(unset)"),
    +            version
    +        ),
    +    })
    +}
    +
     pub async fn run_server_stop_command(force: bool, emit_json: bool) -> Result<()> {
         use std::time::{Duration, Instant};
     
    diff --git a/src/cli/dispatch.rs b/src/cli/dispatch.rs
    index 0c2d1fd34..51a06efce 100644
    --- a/src/cli/dispatch.rs
    +++ b/src/cli/dispatch.rs
    @@ -218,6 +218,9 @@ pub(crate) async fn run_main(mut args: Args) -> Result<()> {
                 ServerCommand::Stop { force, json } => {
                     commands::run_server_stop_command(force, json).await?;
                 }
    +            ServerCommand::Promote { version, json } => {
    +                commands::run_server_promote_command(version, json).await?;
    +            }
             },
             Some(Command::Run {
                 message,
    -- 
    2.51.0.windows.1
    
    
  2. added
    bug
    priority: high
    triage: reproducible
    autonomous: clear
    on Aug 13, 2026
  3. 1jehuang commented on Aug 13, 2026

    @1jehuang
    Owner

    I added jcode server promote [VERSION] [--json], defaulting to current, with installed-version validation, previous-version reporting, and idempotent behavior. Fix: #918.

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

  4. added
    triage: fixed-pending-release
    on Aug 13, 2026
  5. added a commit that references this issue on Aug 13, 2026
    3f9653a
  6. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  7. added a commit that references this issue on Aug 28, 2026
    877e57f
  8. added 5 commits that reference this issue on Aug 30, 2026
    61a00b2
    b579d58
    1cf5f44
    e9143e8
    b190f35
  9. added a commit that references this issue on Sep 18, 2026
    dfca915
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: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions