Skip to content

Handoff: support large sessions and fix menu input focus#1

Draft
pirate wants to merge 2 commits into
mainfrom
handoff-large-sessions
Draft

Handoff: support large sessions and fix menu input focus#1
pirate wants to merge 2 commits into
mainfrom
handoff-large-sessions

Conversation

@pirate

@pirate pirate commented May 30, 2026

Copy link
Copy Markdown
Owner

What

Two fixes to the handoff_agent_here (⌘⇧G) flow:

  1. Budget the transferred context so very large source sessions hand off cleanly.
  2. Focus the spawned pane so the target-agent picker actually receives keystrokes.

Why

1. Large sessions

A long-running source session (e.g. Codex) can be hundreds of MB on disk while its live context is only a few MB — it compacts repeatedly as it runs. The handoff shells out to casr to convert the source session into the target agent's native format; replaying the entire on-disk archive blows the target's resume size / context-window limits and the handoff fails.

This passes --max-context-tokens and --max-tool-output to casr (which honors the source's compaction and trims to those caps), so the new agent ends up with roughly the same context the source agent actually had — not the full archive. Both are env-overridable (CASR_MAX_CONTEXT_TOKENS, CASR_MAX_TOOL_OUTPUT), and older casr builds that don't understand the flags simply exit non-zero and fall through to the existing prompt-handoff fallback.

2. Menu input focus

async_split_pane() creates the new pane but leaves keyboard focus on the original session. The handoff launcher prints a "Choose target agent" menu and blocks on read, so with focus still on the original pane the menu looked frozen — keystrokes went to the wrong pane. Calling async_activate() on the child after the split fixes it. (The ⌘⇧F fork path auto-runs its command and needs no input, which is why only the handoff menu was affected; activation is added to both for consistency.)

Testing locally

  1. Check out this branch and copy fork_agent_here.py into your iTerm AutoLaunch dir (~/.config/iterm2/AppSupport/Scripts/AutoLaunch/), then restart iTerm (or relaunch the script) so the daemon reloads.
  2. In a pane running a long Codex (or other supported) session, press ⌘⇧G.
  3. The new split pane should take focus immediately — type a number to pick the target agent and press Enter.
  4. It converts via casr and resumes, even for a multi-hundred-MB source session that previously failed the handoff.
  5. To tune the budget: export CASR_MAX_CONTEXT_TOKENS=120000 before launching.

The budgeting needs a casr build that understands --max-context-tokens / --max-tool-output (companion change); without it the handoff still works via the prompt-handoff fallback.


Summary by cubic

Make the ⌘⇧G handoff robust for large sessions and fix input focus so the target-agent menu accepts keystrokes. Context is trimmed during casr resume, and the new split pane is activated.

  • Bug Fixes
    • Trim handoff context via casr --max-context-tokens/--max-tool-output (env: CASR_MAX_CONTEXT_TOKENS, CASR_MAX_TOOL_OUTPUT); older casr falls back to prompt path.
    • Activate the new split pane so the target-agent picker receives input (applies to fork and handoff).

Written for commit e5a3149. Summary will update on new commits.

Review in cubic

pirate added 2 commits May 29, 2026 17:02
Pass --max-context-tokens / --max-tool-output to casr so oversized source
sessions (which the source agent has already compacted many times) are
trimmed to the target's size/context limits instead of failing the handoff.
Env-overridable via CASR_MAX_CONTEXT_TOKENS / CASR_MAX_TOOL_OUTPUT; older
casr builds without these flags exit non-zero and fall through to the
existing prompt-handoff path.
async_split_pane created the new pane but left keyboard focus on the
original session, so the "Choose target agent" prompt (which blocks on
read) never saw the user's keystrokes and appeared frozen. Activate the
child session after splitting, for both fork and handoff.
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