Skip to content

unsloth start: add --persist to keep and reopen agent sessions - #7014

Merged
wasimysaid merged 5 commits into
mainfrom
start-session-resume
Jul 9, 2026
Merged

wasimysaid merged 5 commits into
mainfrom
start-session-resume

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What

unsloth start <agent> launches a coding agent pointed at a served model. An interactive launch puts the agent's home in a throwaway temp dir that is deleted on exit, so nothing persists. Four of the agents relocate their WHOLE home there, which silently makes their conversations non-resumable:

Agent Launch-path session store Resume today
codex, openclaw, hermes, pi whole home relocated to a temp dir wiped on exit broken
opencode, claude session data stays in a fixed user dir works

There was no --resume on unsloth start, and even passing the agent's own resume flag failed for the four temp-dir agents because their session store was already gone.

Change

Add an opt-in --resume/--no-resume flag (default off):

  • It routes the launch to the stable Unsloth agents dir (the same one --no-launch already uses) instead of a temp dir, so the session survives the exit. State lives under the Unsloth-owned agents dir, never the user's own ~/.<agent>.
  • A bare --resume (no passthrough subcommand) also reopens the last conversation via the agent's native selector: codex resume --last, opencode/claude/pi --continue. openclaw/hermes persist only, so their own in-app picker resumes.
  • The default path is unchanged: a plain launch still uses a temp dir and persists nothing, so the current privacy behavior is preserved.

The core is a small addition to _session_config (a persist parameter that reuses the existing stable-dir branch) plus the per-command --resume option and the bare-launch native-resume mapping.

Tests

unsloth_cli/tests/test_start.py gains unit coverage (runs on Linux, no agent installed):

  • _session_config(persist=True) yields the stable dir and does not wipe it; the default yields a temp dir removed on exit.
  • Each temp-dir agent's home env var points under the Unsloth agents dir with --resume, at a temp path without it.
  • A bare --resume appends the native resume token; --resume with an explicit subcommand does not.

CI

Adds a dispatch-only resume job to Local Agent Guides CI that drives the real launch path and asserts the split end to end: codex/pi are WIPED without --resume and PERSISTED with it, opencode/claude are PERSISTED either way. openclaw/hermes share codex's relocation mechanism and are covered by the unit tests.

Usage

unsloth start codex --resume              # reopen your last codex session
unsloth start opencode --resume run ...   # persist the session, drive resume yourself

`unsloth start <agent>` launches a coding agent whose home is a throwaway
temp dir wiped on exit, so codex/openclaw/hermes/pi (which relocate their
whole home there) cannot resume a conversation after you quit. opencode and
claude keep their session data in a fixed user dir, so they already resume.

Add an opt-in --resume/--no-resume flag: it routes the launch to the stable
Unsloth agents dir (the same one --no-launch already uses) so the session
survives the exit, never touching the user's own ~/.<agent>. A bare --resume
also reopens the last conversation via the agent's native flag (codex
`resume --last`, opencode/claude/pi `--continue`). The default is unchanged:
a plain launch still uses a temp dir and persists nothing.

Add a dispatch-only `resume` job to the Local Agent Guides CI that drives the
real launch path and asserts the split: codex/pi are wiped without --resume
and persist with it, while opencode/claude persist either way.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4d2adb0b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +140 to +143
"Keep this agent's session so you can resume it later. Without --resume a "
"launched agent's home is a throwaway temp dir wiped on exit (nothing "
"persists); with it, the session lives under the Unsloth agents dir (never "
"your own ~/.<agent>). A bare `--resume` also reopens the last conversation."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't promise isolated resume storage for all agents

This shared help text is shown for Claude and OpenCode too, but the implementations below still keep their histories in the user's normal stores (~/.claude and ~/.local/share/opencode, per the new comments in claude()/opencode()) and only add the vendors' continue flags. In those contexts a default launch can still persist data, and --resume can reopen the user's normal CLI history rather than an Unsloth-owned session, contrary to the advertised throwaway/Unsloth-dir isolation; users relying on this for transcript isolation could leave or send unrelated session context.

Useful? React with 👍 / 👎.

Comment thread .github/scripts/agent-guides-drive.sh Outdated
Comment on lines +621 to +622
[ "$rc" -eq 0 ] || { echo "[$AGENT] ${label} transcript (tail):"; tail -30 "$out" 2>/dev/null || true; }
if [ "$after" -gt "$before" ]; then RESULT="PERSISTED"; else RESULT="WIPED"; fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail the resume experiment when the launch fails

Here a non-zero agent launch only prints the transcript tail, then the pass is judged solely by whether the tracked file count increased. If an agent creates or updates a session DB/log before exiting with an API or CLI error, after > before makes the pass look PERSISTED and the workflow can report the launch path as working even though the actual turn failed; the resume job should treat rc != 0 as a guide failure before trusting the file-count delta.

Useful? React with 👍 / 👎.

Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +186 to +187
if resume and launch and not passthrough:
return list(_RESUME_LAUNCH_FLAGS.get(agent, []))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include resume tokens in printed no-launch recipes

When a user runs a bare unsloth start <agent> --resume --no-launch to copy the recipe into a remote shell or WSL, this launch guard suppresses the native resume tokens (codex resume --last / --continue) in the printed command. The stable config is created, but executing the recipe starts a fresh session instead of reopening the last one; the no-launch path should only skip these tokens when passthrough args are present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 7f6060b by removing the auto-append entirely rather than adding it to the no-launch recipe, so launch and no-launch behave the same.

Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +136 to +138
_RESUME_OPTION = typer.Option(
False,
"--resume/--no-resume",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid shadowing agents' native resume flag

Because these commands are passthrough wrappers, adding a top-level --resume consumes native agent options that used to be forwarded. For example, Claude's CLI reference documents --resume, -r as resuming a specific session by ID/name, and Pi documents --resume, -r as the session picker; after this change unsloth start claude --resume auth-refactor sets the wrapper boolean and forwards only auth-refactor, so the requested native resume no longer happens unless the user knows to switch to -r or another escape hatch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by renaming the wrapper flag to --persist; there is no top-level --resume anymore, so native --resume passes through unchanged (test_native_resume_flag_passes_through_unchanged).

The session flag collided with agents' own resume flags. `unsloth start
claude --resume <id>` used to forward `--resume <id>` straight to Claude
(which keeps its history in ~/.claude regardless), so a boolean --resume on
unsloth start would have swallowed the session id and turned it into a stray
prompt. Name the persistence flag --persist instead, so every agent's native
resume flag (claude --resume <id>, codex resume, opencode --continue, ...)
still passes through untouched. Behavior is otherwise identical: --persist
keeps a launched agent's session under the Unsloth agents dir, and a bare
--persist reopens the last conversation.

Add a regression test that `--resume <id>` passes through verbatim, and in the
CI resume experiment skip the redundant second pass for opencode/claude (they
persist either way, and a second CPU turn only risks a timeout).
@danielhanchen danielhanchen changed the title unsloth start: add --resume to persist and reopen agent sessions unsloth start: add --persist to keep and reopen agent sessions Jul 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4a744e003

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +140 to +143
"Keep this agent's session so you can resume it later. Without --persist a "
"launched agent's home is a throwaway temp dir wiped on exit (nothing "
"persists); with it, the session lives under the Unsloth agents dir (never "
"your own ~/.<agent>). A bare `--persist` also reopens the last conversation. "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop advertising ephemeral defaults for all agents

When users run the default launch for claude or opencode, this promise is false: claude() does not relocate or disable Claude's history store, and opencode() only relocates the config overlay while sessions still live under the user's OpenCode data dir (the new resume CI even counts ~/.claude and ~/.local/share/opencode as persisted). Users relying on this help text for privacy will still leave transcripts on disk without --persist, so either session-scope/disable those stores or qualify the help for the agents that cannot be made ephemeral.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7f6060b: reworded the --persist help to name codex/openclaw/hermes/pi as the relocated-home agents whose session --persist stabilizes, and to note claude/opencode keep sessions in their own stores (~/.claude, ~/.local/share/opencode) and resume regardless.

Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +188 to +189
if persist and launch and not passthrough:
return list(_RESUME_LAUNCH_FLAGS.get(agent, []))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't resume when no persisted session exists

For a first bare --persist launch in a fresh project, this branch still appends the native resume token even though there may be nothing to resume. I checked the current CLI references: Codex resume --last and the Claude/Pi/OpenCode --continue flags load or continue the most recent session, so a user trying unsloth start codex --persist (or the mapped agents) before any saved session exists is sent down the agent's no-session path instead of creating the persistent session they asked for. Gate these tokens on existing history, or split “persist” from “resume”.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7f6060b: dropped the bare-launch auto-append of native resume tokens entirely. --persist now only keeps the session dir; you resume via the agent's own command (e.g. unsloth start codex --persist resume), which avoids the first-run no-session error and the launch/no-launch inconsistency.

Comment thread .github/scripts/agent-guides-drive.sh Outdated
popd >/dev/null || true
after="$(count_session_files)"
echo "[$AGENT] ${label}: session files ${before} -> ${after} (rc=${rc})"
[ "$rc" -eq 0 ] || { echo "[$AGENT] ${label} transcript (tail):"; tail -30 "$out" 2>/dev/null || true; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail the resume pass on agent errors

In the resume experiment, a non-zero unsloth start result is only logged and the pass is still classified from the file-count delta. If an agent exits with an API/CLI error after creating a log, DB, or partial session file, after > before makes the job report PERSISTED and the new CI can pass while the launched resume path is actually broken; mirror the file-edit mode and fail before trusting side effects.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7f6060b: run_pass now guide_fails on a non-zero launch before trusting the file-count delta, so a write-then-error is not misread as PERSISTED.

Reword the --persist help to be accurate: claude and opencode keep sessions in
the user's own stores and resume regardless, so --persist only stabilizes the
otherwise-ephemeral relocated home of codex/openclaw/hermes/pi. Drop the
bare-launch auto-append of native resume tokens: it errored on a first launch
with no prior session, and was inconsistent between launch and no-launch.
--persist now only keeps the session dir; resume via the agent's own command
(e.g. `unsloth start codex --persist resume`), which now finds it.

In the CI resume experiment, fail the pass when the launched turn exits
non-zero, so a write-then-error is not misread as PERSISTED.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 7f6060b8fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@wasimysaid
wasimysaid merged commit c1e06e9 into main Jul 9, 2026
48 checks passed
@wasimysaid
wasimysaid deleted the start-session-resume branch July 9, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants