Skip to content

fix: recover interactive input after resume - #88

Open
angeiv wants to merge 2 commits into
mainfrom
fix/resume-input-init
Open

fix: recover interactive input after resume#88
angeiv wants to merge 2 commits into
mainfrom
fix/resume-input-init

Conversation

@angeiv

@angeiv angeiv commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Problem

After resuming a session via /resume, the interactive UI can stop submitting later input correctly. Text remains in the input surface instead of flowing through the active session prompt loop.

Root Cause

The first fix attempted to call runtime.session.init(), but runtime.session is an AgentSession, not the upstream InteractiveMode, so that path is effectively a no-op. The actual resume path replaces the active AgentSession and invokes the interactive mode setRebindSession callback.

Fix

Install a GLM-side interactive rebind recovery hook in runChatSession:

  • preserve the upstream rebindCurrentSession() behavior after session replacement
  • refresh the editor submit handler after resume/new/fork/import replacement
  • restore editor focus and request a render after the rebind
  • remove the previous no-op AgentSession.init() call

Verification

  • pnpm test tests/runtime/chat-runtime.test.ts
  • pnpm test tests/runtime/chat-runtime.test.ts tests/session/create-session.test.ts
  • pnpm test
  • pnpm build

The upstream createAgentSessionRuntime creates a new InteractiveMode
during switchSession but never calls init() on it. This leaves the
editor's submit action unbound, causing typed input to be displayed
in the input box instead of being sent as a message after resuming
a session.

Calling init() is safe: it has an isInitialized guard and is idempotent.
@angeiv

angeiv commented Apr 30, 2026

Copy link
Copy Markdown
Owner Author

Review note: I do not think this PR fixes the reported resume input issue as written.

The added code calls runtime.session.init?.() after originalSwitchSession(), but in the current upstream @mariozechner/pi-coding-agent@0.70.0, AgentSessionRuntime.session is an AgentSession, not InteractiveMode. AgentSession does not expose init(), so this guard is expected to be a no-op in the actual runtime path.

The interactive layer is created separately in src/runtime/chat-runtime.ts as new InteractiveMode(runtime, ...). Upstream InteractiveMode registers runtimeHost.setRebindSession(async () => this.rebindCurrentSession()) in its constructor, and AgentSessionRuntime.switchSession() calls finishSessionReplacement(), which invokes that rebind callback. That means the real resume path should already rebind the current InteractiveMode rather than creating a new one or requiring AgentSession.init().

Suggested next step: please trace why InteractiveMode.rebindCurrentSession() / renderCurrentSessionState() / editor submit state is insufficient after resume. A regression test should prove that after switchSession(), the editor submit handler is still bound to the active interactive session. Without that, this change can pass CI while leaving the user-visible bug unchanged.

@angeiv angeiv changed the title fix: call session.init() after switchSession to bind input handlers fix: recover interactive input after resume Apr 30, 2026
@angeiv

angeiv commented Apr 30, 2026

Copy link
Copy Markdown
Owner Author

Updated this PR with a real interactive-layer fix.

What changed:

  • Removed the previous runtime.session.init() call because runtime.session is AgentSession, not InteractiveMode, so that path does not reliably execute.
  • Added installInteractiveSessionRebindRecovery() in src/runtime/chat-runtime.ts.
  • The recovery hook replaces the interactive runtime rebind callback with: upstream rebindCurrentSession(), then submit handler refresh, editor focus restore, and render request.
  • Added regression coverage in tests/runtime/chat-runtime.test.ts for the recovery hook and for runChatSession installing it before starting interactive mode.

Local verification passed:

  • pnpm test tests/runtime/chat-runtime.test.ts
  • pnpm test tests/runtime/chat-runtime.test.ts tests/session/create-session.test.ts
  • pnpm test
  • pnpm build

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