Repository navigation
unsloth start: add --persist to keep and reopen agent sessions - #7014
Conversation
`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.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
@codex review |
There was a problem hiding this comment.
💡 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".
| "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." |
There was a problem hiding this comment.
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 👍 / 👎.
| [ "$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 |
There was a problem hiding this comment.
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 👍 / 👎.
| if resume and launch and not passthrough: | ||
| return list(_RESUME_LAUNCH_FLAGS.get(agent, [])) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| _RESUME_OPTION = typer.Option( | ||
| False, | ||
| "--resume/--no-resume", |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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).
|
@codex review |
There was a problem hiding this comment.
💡 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".
| "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. " |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| if persist and launch and not passthrough: | ||
| return list(_RESUME_LAUNCH_FLAGS.get(agent, [])) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| 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; } |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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:There was no
--resumeonunsloth 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-resumeflag (default off):--no-launchalready 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>.--resume(no passthrough subcommand) also reopens the last conversation via the agent's native selector: codexresume --last, opencode/claude/pi--continue. openclaw/hermes persist only, so their own in-app picker resumes.The core is a small addition to
_session_config(apersistparameter that reuses the existing stable-dir branch) plus the per-command--resumeoption and the bare-launch native-resume mapping.Tests
unsloth_cli/tests/test_start.pygains 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.--resume, at a temp path without it.--resumeappends the native resume token;--resumewith an explicit subcommand does not.CI
Adds a dispatch-only
resumejob to Local Agent Guides CI that drives the real launch path and asserts the split end to end: codex/pi areWIPEDwithout--resumeandPERSISTEDwith it, opencode/claude arePERSISTEDeither way. openclaw/hermes share codex's relocation mechanism and are covered by the unit tests.Usage