Skip to content

Create sessions unnamed; name them from the first prompt - #697

Merged
mohitranka merged 7 commits into
mainfrom
feat/unnamed-session-creation
Sep 15, 2026
Merged

mohitranka merged 7 commits into
mainfrom
feat/unnamed-session-creation

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Problem

Starting a session is currently a prompt-first act: n opens an inline composer on the Sessions tab, and the text typed there is submitted as CreateSession { label: "", first_prompt: Some(text) }. That one string both creates the session and names it, so there is no way to open a session's panes and then decide what to ask. The session does not exist until you have already decided.

This reorders that: n allocates the session and its worktree immediately, selects it, and puts the cursor in the composer. The name arrives from the first prompt submitted in that composer.

Approach

Most of the machinery for this already existed and is reused rather than rebuilt:

  • Empty label already means "unnamed". render.rs already synthesizes session 1 / session 2 for an empty label at render time, and session_title_hint already falls back for /resume. Nothing new is persisted to show a temporary name, and no UUID is invented — a persisted placeholder would have deleted that behavior.
  • Prompt-less creation already existed, along with a test asserting it does not park on the trust modal (supervisor.rs). That is why the trust modal needs no change here: it fires on first_prompt.is_some() && !already_trusted, and managed worktrees already inherit trust by the ancestor walk in is_trusted_at.
  • Branch ordering was already correct. SubmitPrompt renames before enqueueing and before starting the driver, so by the time materialize_managed_branch runs at the end of turn 1, the label is set and the branch gets a real name. No ordering change was needed — only the discipline of keeping the rename on submit.

The one substantive naming change: title_from_prompt now emits lowercase kebab-case capped at 4 normalized tokens, and is documented as not display-only, which its old doc comment wrongly claimed (unique_session_branch already read task.label into forge/<slug>).

User-visible changes

  • Session names are now lowercase kebab-case: Rewrite the lexer becomes rewrite-the-lexer. This is deliberate — it makes the navigator row and the branch name the same string by construction, and it is the only way the invariant can be exact.
  • n creates a session and focuses its composer instead of opening an inline task buffer.
  • /resume rows now agree with the navigator instead of echoing the raw truncated first message.
  • Fixed: --help fails previously produced the branch forge/-help-fails; trim_matches('-') only stripped the ends, so the leading - survived. It is now help-fails.

Safety implications

  • The trust modal is unchanged for prompt-first creation. Creation stays prompt-less on purpose: passing a prompt would park on the modal, and n should not put a modal in front of an operator who is not expecting one.
  • The trust overlay depends on selection order. CreateSession now selects before the first_prompt.is_some() && !already_trusted branch, because the overlay only opens when the new session is already selected; selecting afterwards would make the modal unreachable for the one case it still exists for.
  • rollback_creation clears a selection naming the rolled-back session. Selecting before trust is confirmed means a cancelled creation would otherwise leave durable state pointing at a removed row.
  • sanitize_label is untouched. It remains the ../ and ref-reserved-character boundary, and it still guards the subagent label path (create_worktree), whose labels are model-authored and do not get the 4-word rule.
  • The primary session is not disturbed. set_selected writes only repository_state.selected_session_id; ownership, slot and lifecycle live on the sessions row.

Validation

  • cargo test --package forge-types --locked title_from_prompt → 6 passed
  • cargo test --package forge-core --locked session_title_hint → 2 passed
  • cargo test --package forge-storage --locked sanitize_label → 1 passed
  • cargo test --package forge-session --locked create → 2 passed, including a new ordering regression test asserting a prompt-less session ends up with label fix-the-login-bug and branch forge/fix-the-login-bug
  • cargo test --package forge-session --locked trust → 6 passed
  • cargo test --package forge-tui --locked multi_task → 30 passed, including the new n_allocates_an_unnamed_session_and_hands_the_cursor_to_its_composer
  • cargo check --package forge-tui --all-targets --locked → clean
  • cargo fmt --all -- --check → clean for every touched crate

Not run, and called out per CONTRIBUTING: cargo test --workspace / clippy --workspace were not run (AGENTS.md forbids the full suite, and a shared volume hit 100% during development). One pre-existing environmental failure remains in forge-session: primary_and_managed_actors_share_hitl_question_and_continue_commands fails with sandbox-exec: sandbox_apply: Operation not permitted because the test's own nested sandbox cannot start inside an already-sandboxed host. It does not touch CreateSession, and it fails at the sandbox call before any of this code runs.

Known limits

  • The label/branch invariant holds only for names ≤ 40 characters. sanitize_label truncates to 40 while TITLE_MAX_CHARS is 60, so a name that is a single very long token is shortened on the way into Git and the two diverge. Ordinary prompts are far under 40 tokens-wise, so this is unreachable in practice, but it is a real hole in the "one value, never two" property. Closing it means aligning the two caps, which crosses into the forge-storage security bound.
  • forge/untitled-session is now reachable in a way it was not before: a first prompt that normalizes to nothing, or a turn that writes a file before any valid name exists, can produce that branch name permanently, since set_session_branch is one-way.
  • AttachWorktree still registers without selecting — same class of bug as the one fixed here, deliberately out of scope.
  • No screenshots. This is a meaningful TUI change and CONTRIBUTING asks for them; I could not capture any in the sandboxed environment. The visual delta is limited to the n binding's behavior and lowercase session names in the navigator, task strip and /resume.

Design doc

docs/unnamed-session-creation-plan.md is the decision record: the frozen contract, what already worked and must not be "fixed", the hazards, and the limits above. FORGE-DESIGN.md §7.7 and §12 are updated in-tree.

CreateSession now selects authoritatively, so the TUI's roster-diff
selection leg could mis-pick in the 128-event window and is removed.
The follow-up only adopts focus, and only for the session the
supervisor already made selected.

Also update the /resume title fixture: it now shares the session naming
rule instead of echoing the raw first message.

refs: 2cce550, 5845d38
CI builds the PR merge commit, not the branch head. main still carried the
inline composer for `n`, so the merge produced a tree where types.rs had
the field removed and input.rs/tests still used it. That is what #697 was
failing on, not the branch itself.

- drop the `navigator_new_session` guard main added to the Up-to-tab-row
  path; with the inline composer gone, an open peek is the only prior
owner of Up
- rewrite the two tests that asserted the composer buffer: `n` at the strip
  is now a session verb, and the tab row swallows it as a bare key
@mohitranka
mohitranka force-pushed the feat/unnamed-session-creation branch from e087fe0 to ac61615 Compare September 15, 2026 07:52
@mohitranka
mohitranka merged commit 2b5541d into main Sep 15, 2026
3 checks passed
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.

1 participant