Manual REPL restart from the TUI or REPL #16

Closed
opened 2026-04-01 08:03:25 -07:00 by haakon-e · 2 comments
haakon-e commented 2026-04-01 08:03:25 -07:00 (Migrated from github.com)

Is there a way to restart a REPL session while preserving its session ID — either from the TUI or from the Julia REPL itself?

The use cases where this would help:

  • Restarting without going through the agent saves tokens when that's the only thing I want to do
  • Exiting and reopening a REPL works, but generates a new session ID, which can confuse an ongoing agent session

I notice the session overview already has a Shutdown button — a Restart button alongside it would address this nicely.


A public Gate.restart() function would also be useful for triggering this directly from the Julia REPL:

"""
    restart()

Restart the Julia session, preserving the Kaimon session ID so the TUI
reconnects automatically. Equivalent to what the agent's `manage_repl` tool
does, but callable directly from your REPL.

Uses `execvp` to replace the current process image — same PID, fresh Julia
state. Your startup.jl runs again and `Gate.serve()` reconnects with the
same session key.
"""
function restart()
    _RUNNING[] || error("Gate is not running")
    _ALLOW_RESTART[] || error("Restart is disabled for this session (allow_restart=false)")
    sid  = _SESSION_ID[]
    name = basename(dirname(something(Base.active_project(), "julia")))
    proj = dirname(something(Base.active_project(), "."))
    _RUNNING[] = false
    _cleanup()
    _exec_restart(name, sid, proj)
end

The key difference from the MCP path is that the 0.3s sleep (which exists to let the ZMQ :ok reply flush before execvp tears down the sockets) is not needed here, so cleanup can happen immediately.


In the meantime, the following can be pasted directly into the Julia REPL:

let sid = Kaimon.Gate._SESSION_ID[]
    name = basename(dirname(Base.active_project()))
    proj = dirname(Base.active_project())
    Kaimon.Gate._exec_restart(name, sid, proj)
end

This calls _exec_restart directly and preserves the session ID so the TUI reconnects automatically, but relies on a private internal function.

Happy to discuss further, thanks!


Current version for testing: v1.1 branch, commit: ac23906 Use full session ID for TCP sessions in short_key (2 days ago)

Is there a way to restart a REPL session while preserving its session ID — either from the TUI or from the Julia REPL itself? The use cases where this would help: - Restarting without going through the agent saves tokens when that's the only thing I want to do - Exiting and reopening a REPL works, but generates a new session ID, which can confuse an ongoing agent session I notice the session overview already has a **Shutdown** button — a **Restart** button alongside it would address this nicely. --- A public `Gate.restart()` function would also be useful for triggering this directly from the Julia REPL: ```julia """ restart() Restart the Julia session, preserving the Kaimon session ID so the TUI reconnects automatically. Equivalent to what the agent's `manage_repl` tool does, but callable directly from your REPL. Uses `execvp` to replace the current process image — same PID, fresh Julia state. Your startup.jl runs again and `Gate.serve()` reconnects with the same session key. """ function restart() _RUNNING[] || error("Gate is not running") _ALLOW_RESTART[] || error("Restart is disabled for this session (allow_restart=false)") sid = _SESSION_ID[] name = basename(dirname(something(Base.active_project(), "julia"))) proj = dirname(something(Base.active_project(), ".")) _RUNNING[] = false _cleanup() _exec_restart(name, sid, proj) end ``` The key difference from the MCP path is that the 0.3s sleep (which exists to let the ZMQ `:ok` reply flush before `execvp` tears down the sockets) is not needed here, so cleanup can happen immediately. ---- In the meantime, the following can be pasted directly into the Julia REPL: ```julia let sid = Kaimon.Gate._SESSION_ID[] name = basename(dirname(Base.active_project())) proj = dirname(Base.active_project()) Kaimon.Gate._exec_restart(name, sid, proj) end ``` This calls `_exec_restart` directly and preserves the session ID so the TUI reconnects automatically, but relies on a private internal function. Happy to discuss further, thanks! --- Current version for testing: v1.1 branch, commit: `ac23906 Use full session ID for TCP sessions in short_key (2 days ago)`
kahliburke commented 2026-04-02 13:52:59 -07:00 (Migrated from github.com)

@haakon-e Likely yes do you want to put that in as a PR, or just use it as a starting point?

Also 1.1 really will come eventually I just have been busy.

@haakon-e Likely yes do you want to put that in as a PR, or just use it as a starting point? Also 1.1 really will come eventually I just have been busy.
kahliburke commented 2026-04-03 12:17:34 -07:00 (Migrated from github.com)

@haakon-e Thanks for the PR I will review it and get it in shortly!

@haakon-e Thanks for the PR I will review it and get it in shortly!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kahliburke/Kaimon.jl#16
No description provided.