Add a name on client and resume from it #1
Labels
No labels
ai::retry
ai::retry_once
ai::retry_until_green
ai::validate_plan
status::blocked
status::done
status::functional_analysis
status::in_ci
status::in_development
status::in_review
status::technical_analysis
status::waiting_info
status::waiting_validation
type::analysis
type::bug
type::question
type::task
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Alchemic.Studio/Alfred#1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When we use not-ai agent like codex or claude, add a name to the session that came from the branch name and try to resume from it.
Functional analysis
Status: ready. All open points were settled by @SebastienDenooz on 2026-10-26, who accepted the proposed defaults for q1–q6.
Understanding of the request
Sometimes a run is executed by a local coding-agent CLI (Claude Code, Codex, … — §16.5) instead of a model provider API. In that case the engine names the CLI session after the issue's agent branch name (
{BRANCH_PREFIX}issue-{iid}-{slug}, §7.3). On every later run for the same issue, it tries to resume that session. This way the agent keeps the context it built in earlier runs: analysis, plan, code it wrote, CI fixes.Decisions
agent/issue-128-add-name). It is used from the very first run, so analysis phases use it too, whether or not the branch has been pushed yet.AGENT_SESSION_RESUME, defaulttrue, scopes organization and project, §23.3). The deliverable is an update todocs/specification.md.Expected behaviour
llm_sessions, §22.3) stores the session name and whether the run was resumed or started fresh. This lets the audit trail show what the agent "remembered".Acceptance criteria
resumed = false.resumed = true.resumed = false. The fallback changes no status, counter or label and posts no comment.AGENT_SESSION_RESUME = falseat organization or project scope all behave exactly as today.docs/specification.mdis updated in these places:llm_sessionsgains the session name andresumedcolumns.AGENT_SESSION_RESUMEsetting.Out of scope
Thanks @1, I am on it. I will post my analysis here.
type — I could not tell the type of this issue. Please add one of these labels: task, bug, analysis, question.
You can also answer every question at once in a comment of your own.
I need a few answers before going further. Reply in a comment; without an answer by 2026-10-27 00:08 UTC, I will apply the defaults.
q1 — Which runtimes are in scope? I read "not-ai agent like codex or claude" as the local agent mode (§16.5: a coding-agent CLI run inside the runner container), as opposed to API mode. Which adapters must get the named-session-and-resume behaviour?
q2 — What exactly is the session name? The agent branch
{BRANCH_PREFIX}issue-{iid}-{slug}(§7.3) only exists fromin_developmenton, but analysis phases run before it. Also, two projects of one organization can produce the same branch name.agent/issue-128-add-name, same value whether or not the branch has been pushed yet (default){org}-{project}-agent-issue-128-add-name, avoids cross-project collisionsq3 — Which runs should try to resume the session? The same issue goes through several phases (analysis, development, ci_fix, review_fix, conflict_resolution, answer).
q4 — What must happen when resuming is not possible (no session with that name yet — always the case on the first run —, session storage lost, CLI version that does not support it, or the CLI refuses the resume)?
q5 — Today the runner container is disposable with a temporary home directory (§17.2), so a CLI's session files vanish at the end of each run; resuming therefore implies keeping the agent's session state somewhere between runs of the same issue. How long should that session state live, and is persisting it acceptable given §17 and non-goal 3 ("one prompt, one execution")?
q6 — Should the behaviour be configurable, and what is the deliverable in this repository, which only contains
docs/specification.md?llm_sessions), 28.1 and non-goal 3 amendedAGENT_SESSION_RESUME, default true, added to §23.3 (default)You can also answer every question at once in a comment of your own.
Ok with your proposition, you can go further with that.
Plan
Implementation plan — named, resumable local-agent sessions per issue
The repository contains only
docs/specification.md, so the only deliverable is an update to that file. It has no code, no test suite and no CI, so the "tests" below are the new rows of the testing contract (§28.1).Findings from the spec that shape the design
{base}/.worktrees/{organization}-{project}-{target}-{run}(§3.4), and the worktree is removed in afinallyblock (§7.3, §13.1). Session state therefore cannot live in the worktree. It needs its own directory on the host, scoped to the mailbox./workspace(§17.2). CLIs that key their sessions on the working directory (Claude Code, for example) will find their prior session even though the host worktree path changes on every run.reviewphase, §8.5) are not issue mailboxes, so they behave exactly as today.codex exec resume <id>. Claude Code's--session-idmust be a UUID. So the "session name" is the engine's logical name. Each adapter maps it to the CLI's native session id, and the engine stores that id in the database. It is never read back from a file the container can write.BRANCH_PREFIXcan change. A name recomputed on every run could drift.Technical decisions taken (no human input needed)
{BRANCH_PREFIX}issue-{iid}-{slug}and writes it tomailboxes.branch_nameimmediately, even before the branch is pushed. That stored value is reused afterwards, so the session name and the later branch name are always the same, and editing the title cannot break resume. §7.3 is adjusted to say the name is fixed at the first run instead of atin_development.adapter_changed. A change of provider or model with the same adapter still resumes.llm_sessionsrow of the mailbox with the sameadapter_idand a non-nullnative_session_id.~/.claude,~/.codex, etc. that would then run in later runs. Credentials in those directories must never be persisted either.Outcomeand retry rules (§13.4).Changes to
docs/specification.md§3.4 Filesystem layout
Add the line
{base}/.agent-sessions/{organization}-{project}-issue-{iid}/{adapter_id}/ session state of a local agent, per issue mailbox. Explain that this directory outlives runs, sits outside every worktree and is removed at mailbox cleanup (§21.3).§7.3 Invariants
mailboxes.branch_name. The branch itself still exists only fromin_developmentonward.finallyclause removes the worktree and the container but not the mailbox's session state.§13.1 Sequence
Add one step before "start container": resolve the session (setting, capability, name, prior native id) and mount its state directory. Add one step after the invocation: record the native id and
resumed.§16.2 Contract
LlmRequestgains?SessionRef $session(null when resume is off or not supported):name: the logical name, i.e. the branch name;resumeId: nullable, the prior native id for this adapter;stateDir: host path mounted by the sandbox.LlmResultgains:?string $sessionId: the native id reported by the CLI;bool $resumed;?string $resumeFallback: one ofno_prior_session,adapter_changed,state_missing,unsupported_version,refused.§16.3 Capabilities
bool $resumableSessions.?string $sessionStatePath: the path inside the container home that holds sessions only, never credentials or settings.false.trueonly for CLI versions verified to support non-interactive resume. Detection (§16.6) can lower it per installed version, and theagent_installationsrow records the result.§16.5 Local agents
Add a "Named sessions and resume" subsection:
When the capability is used: the setting is on, the adapter declares the capability and the target is an issue mailbox.
Name derivation (frozen branch name).
The resume path versus the fresh path, and the silent fallback with its reasons.
The fallback changes no status, counter or label and posts no comment.
When the CLI accepts a human-readable label, the session is given the name. Otherwise the name exists only on the engine side.
Add a column "Resume (indicative)" to the agent table:
--resume <id>; a fresh session is started with--session-id <uuid>; state in~/.claude/projects/;codex exec resume <id>, id read from the JSON events; state in~/.codex/sessions/;--session <id>;--resume <id>;As with the other options, these belong to each adapter and its tests.
Add a trap to encode: detecting "session not found / cannot resume" from the exit code and output is per-CLI and fragile. When the cause is ambiguous, the failure is treated as a normal failure, never silently as a fallback.
§17.2 Container specification
sessionStatePath, for every phase including read-only ones". It never overlapsAGENT_CREDENTIAL_MOUNTS. The "no home directory" rule still holds: only that subdirectory is mounted.§17.5 What the sandbox does not cover
State the accepted risk: content written in one run can influence later runs of the same issue. That covers untrusted context the CLI saw and a tampered transcript planted by repository code. Persisted state is limited to the sessions subdirectory, so no config, hooks or credentials are kept.
§21.2 / §21.3 Reconciler
doneor cancelled (§7.2 rows: closed by merge, unassigned or closed without merge).blockedkeeps the state, soretryresumes with memory.§22.3
llm_sessionsAdd a row:
session_namenullable,native_session_idnullable,resumedbool (default false),resume_fallbacknullable. Rows stay null or false for API mode, MR mailboxes and runs with the setting off.§23.3 Runtime settings
Add
AGENT_SESSION_RESUME | true | organization, project.§24.3 / §24.5 Security
RETENTION_DAYS. It lives until mailbox cleanup (decision q5). Thellm_sessionsmetadata follows the usual retention.§25.2 Run traceability
The session detail shows the name, the native id and resumed or fallback with its reason.
§28.1 Testing contract
Add the rows below. §28.2: the fake LLM adapter and the fake container runtime support sessions, so mounts and arguments can be asserted.
resumed = falseresumed = true; an agent MR's ci_fix resumes the issue's sessionresumed = falseand a fallback reason; no status, counter, label or comment changes; no LLM retry countedAGENT_SESSION_RESUME = falseat organization or project scope produce exactly today's request and mounts§29 Non-goals
Reword item 3 to: "No interactive session with the LLM: one prompt, one execution per run. A local agent may resume the context of earlier runs of the same issue (§16.5)."
§30 Appendix A
Processmount option.CleanupWorktreesAndContainersalso removes orphaned session directories.Risks
Validation
This repository has no code or CI, so validation is a careful review of the spec. Check that every cross-reference resolves (§3.4, §7.3, §11.7, §13.1, §16.2–16.6, §17.2, §17.5, §21, §22.3, §23.3, §24, §25.2, §28, §29, §30), that tables keep valid Markdown, and that the Mermaid diagrams still render. Creating CI pipelines (GitLab, Forgejo/GitHub) or Playwright is out of scope here, since there is nothing executable to test.
The implementation plan is ready for validation. Add the ai::validate_plan label to let me start.
Plan validated by @SebastienDenooz. Starting the development.
No pipeline ran on this merge request. It is ready for review.