Skip to content

Make a successful launch distinguishable when fast work exits before handle refresh #221

Backlog

Description

@tony

Summary

A command started by session creation, window creation or pane splitting can produce its side effect before the Java handle refresh throws TargetGoneException. The split documentation describes this for fast commands. The same behavior occurred with sessions and windows.

Motivation

A caller can determine whether creation was refused or completed and subsequently disappeared, without treating a missing fresh handle as a safe retry.

  • Developer experience — Callers have no creation receipt in the exception returned by the existing handle API.
  • Immediate benefit — Blind retry can publish or enqueue the same work twice.
  • Longer-term benefit — Distinguishing execution from handle hydration supports reliable orchestration.
  • End-user experience — Short-lived jobs may run twice when their tool reports a launch problem.

Evidence

With retention off, short commands sometimes disappeared before Java could refresh the handle. Retrying after the exception appended a second receipt. If the first call returns an ID, repeat in fresh directories to exercise the race.

Steps, versions and observations

Run these steps from a checkout of ddcf8d2ff8761c5ea81291c0882007f786be778d unless a step explicitly identifies a released artifact. The release-tag links below identify code or a baseline at v0.1.2 (e8a39689). The observed behavior is attributed to the tested revision or artifact.

Audited revision ddcf8d2ff8761c5ea81291c0882007f786be778d. Linux ARM64 with pinned core ddcf8d2 and JDK 25, 26, 27. The matched tmux builds were 3.3a, 3.4, 3.5, 3.5a, 3.6, 3.6a, 3.6b, 3.7, 3.7a, 3.7b, 3.7c, 3.8 and next-3.9 (ce276a1d).

  1. From a fresh public checkout with JDK 25 or newer and a supported tmux on PATH, build the pinned Java core. Use the affected native release when the scope calls for one.
git clone https://github.com/libtmux/libtmux-java.git
cd libtmux-java
git checkout ddcf8d2ff8761c5ea81291c0882007f786be778d
./gradlew :libtmux:jar
CORE=$(find "$PWD/libtmux/build/libs" -name 'libtmux-*.jar' ! -name '*-sources.jar' ! -name '*-javadoc.jar' | head -1)
mkdir -p /tmp/libtmux-java-test
LAB=$(mktemp -d /tmp/libtmux-java-test/q.XXXXXX)
  1. Run the following source file in the same shell. The daemon and the sample all use the private directory created above.
cat > "$LAB/Repro.java" <<'JAVA'
import io.github.libtmux.*;
import java.nio.file.*;
import java.time.Duration;
import java.util.*;
class Repro {
  static String peer(Server s,String... args) throws Exception {
    var argv=new ArrayList<>(s.config().endpointCommand()); argv.addAll(List.of(args));
    var p=new ProcessBuilder(argv).redirectErrorStream(true).start();
    var out=new String(p.getInputStream().readAllBytes()).strip();
    if(p.waitFor()!=0) throw new IllegalStateException(out);
    return out;
  }
  static void waitFile(Path path) throws Exception {
    long end=System.nanoTime()+Duration.ofSeconds(12).toNanos();
    while(!Files.exists(path) && System.nanoTime()<end) Thread.sleep(20);
    if(!Files.exists(path)) throw new IllegalStateException("missing "+path.getFileName());
  }
  public static void main(String[] args) throws Exception {
    Path d=Path.of(args[0]);
    try(var s=Server.start(ServerLaunch.builder().root(d).build())) {
      var parent=s.newSession("anchor");
      Path ledger=d.resolve("actions");
      String[] job={"sh","-c","echo action >> $1","job",ledger.toString()};
      for(int i=0;i<2;i++) {
        try {System.out.println("returned "+parent.newWindow(w->w.detached().running(job)).id());break;}
        catch(io.github.libtmux.exception.TargetGoneException e) {System.out.println(e.getClass().getSimpleName());}
      }
      waitFile(ledger);System.out.println("receipts="+Files.readAllLines(ledger).size());
      System.out.println("native ID="+peer(s,"new-window","-d","-P","-F","#{window_id}","-t",parent.id().value(),"--","true"));
    }
  }
}
JAVA
java --class-path "$CORE" "$LAB/Repro.java" "$LAB"

115/117 fast Java creations threw after recording the effect (session 39/39, window 38/39, split 38/39). Retrying only those ambiguous results duplicated the receipt. With retention on, 117/117 Java calls returned. Native create returned 234/234 IDs across both settings.

Proposal

Options to evaluate.

  • Consider exposing the ID tmux already returned when subsequent hydration fails.
  • Document the same retry semantics on all creation methods and demonstrate application-owned idempotency.

References

Native creation-ID experiment

The typed creation-ID draft uses the ID returned by the tmux command. The caller can keep it even after the launched job disappears. A consumer exercised session creation, window creation, and splits through both a pane and a window on tmux 3.3a, 3.4, and 3.8. All four handle lookups were empty once the workers had exited. On window reuse without native output the new method returned an empty optional and the existing handle-returning method still found the original window.

The test fails when a lookup is deliberately reintroduced after successful creation. An earlier experiment putting the ID in a disappearance exception broke an existing exception-message test and still lost the ID on a subsequent transport failure. The worker's own completion receipt remains necessary before deciding to publish or retry a job.

Activity

  1. added
    enhancement
    java
    p0
    area:core
    on Dec 1, 2026
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

    area:coreenhancementjavap0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions