Skip to content

fix: gate init "create a session" hint on active session - #781

Closed
gominimal-aw-bot[bot] wants to merge 1 commit into
mainfrom
inbox-patch/init-stale-session-hint-eacb0e8fc9786ad7
Closed

gominimal-aw-bot[bot] wants to merge 1 commit into
mainfrom
inbox-patch/init-stale-session-hint-eacb0e8fc9786ad7

Conversation

@gominimal-aw-bot

Copy link
Copy Markdown
Contributor

Fixes #771
Routing-Key: inbox-route/I_kwDOSUhdos8AAAABI2fYCw

Problem

Running minimal init from inside an already-active session printed a
stale "Next steps" block that told the user to run
minimal activate . # create a session, even though MINIMAL_SESSION_ID
was set (the session UUID even appeared in the surrounding output). The init
path in crates/minimal/src/lib.rs emitted the activate (and attach) hints
unconditionally and never consulted MINIMAL_SESSION_ID.

Change

In run_init_flow (crates/minimal/src/lib.rs), the post-creation hint lines
are now computed by a small pure helper, init_next_steps(matched, in_session). When the process is already inside a session — detected via
std::env::var("MINIMAL_SESSION_ID") being set and non-empty, the same env
var contract used elsewhere in the crate (client.rs) and in minimald — the
"create a session" and "attach" hints are omitted, leaving only the still-valid
minimal update step. Outside a session, behavior is unchanged: activate is
always suggested and attach is added only when the plan matched an existing
session.

The matched/in_session decision is extracted into the pure helper purely so
it can be unit-tested without touching the filesystem or environment; the
printing loop is otherwise a direct translation of the previous eprintln!
block.

A neighbouring open PR, #682, touches the reverse activate↔init interaction
(prompting to init when activate finds no minimal.toml); it is a distinct
scenario and does not overlap this change.

Verification

Gate run from the workspace root against crates/minimal:

  • cargo fmt --all --check --manifest-path target/Cargo.toml — clean, exit 0.
  • cargo clippy --workspace --manifest-path target/Cargo.toml -- -D warnings — no warnings, Finished exit 0.
  • cargo build --workspace --manifest-path target/Cargo.toml — exit 0.
  • cargo test --workspace --manifest-path target/Cargo.toml — exit 0; all suites 0 failed, including the two new tests init_next_steps_omits_session_hints_when_in_session and init_next_steps_shows_session_hints_when_not_in_session.

Generated by inbox-patch · ◷

The init command's post-creation 'Next steps' block printed
'minimal activate .  # create a session' (and the 'minimal attach'
hint) unconditionally, so running 'minimal init' from inside an active
session suggested creating a session that already exists.

Compute the hint lines in a pure init_next_steps helper and omit the
activate/attach hints when MINIMAL_SESSION_ID is set and non-empty.

Closes: #771
@gominimal-aw-bot gominimal-aw-bot Bot added kind:bug Something is not working. Applied by the inbox-route classifier. priority:should-have Should be done. Applied by the inbox-route classifier or a human. labels Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2f175a36-00eb-4ec9-a49b-1165bcb73b09

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Comment @coderabbitai help to get the list of available commands.

@norrietaylor

Copy link
Copy Markdown
Member

This guards a state that can't currently occur — the stale hint doesn't reproduce

I tried to confirm the repro from #771 and it doesn't hold up. The claimed flow is:

  1. minimal activate . — "verify $MINIMAL_SESSION_ID is set"
  2. minimal init inside that session → stale activate/attach hints

Step 1's premise is false: $MINIMAL_SESSION_ID is never set in a minimald session shell, and the real minimal init can't run in-session anyway.

Evidence

  • The var never enters a session process env. The session shell is spawned with BASELINE_VARS — literally just PS1 — plus the project's composition vars (crates/minimald/src/session_host.rs:796,982). MINIMAL_SESSION_ID is purely a channel-routing var: the host client puts it on the outgoing SSH channel (crates/minimal/src/client.rs:172, crates/minimal/src/lib.rs:1010 SendEnv), and minimald reads it back to select the session (connection.rs:390, exec.rs:779). The attach path (session.rs:695) uses the channel config only for PTY size + loadout and never injects its env vars into the spawned process — unlike stock OpenSSH, which places AcceptEnv vars into the shell. No test asserts the var is present in-session.
  • The real minimal init isn't reachable in-session. /usr/bin/min inside the sandbox is the relay shim crates/minimald/src/env_min_helper.sh — verbs add / search / run / build / test / patched-pkg / check, no init — and it never invokes the minimal binary. minimald's exec path also refuses arbitrary commands (only min run <task>).

So in_session is false on every real path; the activate/attach hints print exactly as before, and the new branch is dead code.

Why it looked plausible

The chain was machine-generated and never verified against a running session: #771 was inbox-auto-routed with an LLM-written repro (it assumed SendEnv ⇒ the var lands in the shell, i.e. stock-sshd behavior, which minimald doesn't do); inbox-patch failed to produce a verified fix twice; and this PR's Verification ran only fmt/clippy/build, not the in-session repro.

Suggestion

One-line check inside a real session settles it:

minimal activate .        # then, in the session shell:
echo "MINIMAL_SESSION_ID=[$MINIMAL_SESSION_ID]"   # → empty

If it's empty (per the code above, it will be), I'd close #771 as not-reproducible. If we want init to be session-aware, the real prerequisite is a minimald change to export MINIMAL_SESSION_ID into the session shell env (and make init reachable in-session) — only then does this gate become live. The change itself is harmless (the host path is unchanged), so this is a "does it fix anything?" question, not a correctness objection.

@norrietaylor

Copy link
Copy Markdown
Member

Closing as invalid — this targets the wrong root cause.

The real repro (see the reporter's terminal): minimal activate on a project with no minimal.toml auto-scaffolds one and, as a sub-step, prints run_init_flow's "Next steps" block including minimal activate . # create a session — while activate is already running and proceeds to create the session. The trailing session UUID in the original report is the session activate just created, not evidence of a pre-existing/active session — which is what led the auto-generated issue and this PR to gate on MINIMAL_SESSION_ID.

That gate is dead code: MINIMAL_SESSION_ID is never set in this flow (it's a channel-routing var on the SSH channel, never in the CLI process env; the session shell env is BASELINE_VARS = just PS1), and run_init_flow only ever runs host-side as minimal init / activate's scaffold step — never in-session (the in-session min is a socat relay shim with no init verb). Details in the earlier comment.

The correct fix keys off the caller (activate auto-scaffold vs standalone init), not the env var — omit the activate/attach hints when run_init_flow is invoked from offer_mfile_scaffold (crates/minimal/src/lib.rs:867). I've re-diagnosed and rewritten the tracking issue #771 accordingly.

norrietaylor added a commit that referenced this pull request Jul 16, 2026
…e mfile

`minimal activate` on a project without a `minimal.toml` auto-scaffolds
one via `run_init_flow`, which printed a "Next steps" block suggesting
`minimal activate .  # create a session` — nonsensical there, since
`activate` is already running and creates the session in the same
command. Just drop the block; `init` still reports the created path and
the next action is clear from context.

Supersedes #781, which gated the hint on `MINIMAL_SESSION_ID` — a
channel-routing var never set in this host-side flow.

Closes: #771
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
norrietaylor added a commit that referenced this pull request Jul 16, 2026
…e mfile (#785)

`minimal activate` on a project without a `minimal.toml` auto-scaffolds
one via `run_init_flow`, which printed a "Next steps" block suggesting
`minimal activate .  # create a session` — nonsensical there, since
`activate` is already running and creates the session in the same
command. Just drop the block; `init` still reports the created path and
the next action is clear from context.

Supersedes #781, which gated the hint on `MINIMAL_SESSION_ID` — a
channel-routing var never set in this host-side flow.

Closes: #771

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@norrietaylor
norrietaylor deleted the inbox-patch/init-stale-session-hint-eacb0e8fc9786ad7 branch July 23, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug Something is not working. Applied by the inbox-route classifier. priority:should-have Should be done. Applied by the inbox-route classifier or a human.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

activate auto-scaffold prints a nonsensical "minimal activate ." next-step hint

1 participant