Skip to content

Session mode is lost when loadSession falls back to new session #45

@z-x-yang

Description

@z-x-yang

Summary

acpx can lose session mode (for example plan) across reconnects when session/load fails and runtime falls back to session/new.

Observed behavior:

  • set-mode plan reports success
  • next command reconnects, loadSession fails (Resource not found / empty-session load failure)
  • acpx creates a fresh ACP session
  • effective mode silently reverts to default (auto)

Why this happens

Mode switching is applied to the current ACP session id. When reconnect creates a fresh ACP session, there is no replay of the user's intended mode.

Reproduction

  1. Ensure a persistent session.
  2. Run set-mode plan.
  3. Trigger reconnect where session/load falls back to session/new.
  4. Run another config command (for example set reasoning_effort high) and inspect configOptions.mode.currentValue.

Expected: mode remains plan.
Actual: mode may be auto.

Proposed fix

Persist a desired mode at the acpx session-record level and replay it when a fresh ACP session is created:

  • Persist record.acpx.desired_mode_id on successful:
    • set-mode <mode>
    • set mode <value>
  • In connectAndLoadSession, if fallback creates a fresh ACP session, call session/set_mode(desired_mode_id) before continuing.
  • Keep behavior best-effort: replay failures should warn in verbose mode but not hard-fail normal command flow.

Validation

Added regression coverage for fallback + replay in CLI tests:

  • set plan -> reconnect fallback -> verify mode still plan
  • set back to auto -> reconnect fallback -> verify mode still auto

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions