Skip to content

fix(agent-pane): don't persist agent panes into window layout (#275) - #360

Merged
Kai Tao (vanzue) merged 2 commits into
mainfrom
dev/vanzue/fix-275-agent-pane-persist
Jun 26, 2026
Merged

Kai Tao (vanzue) merged 2 commits into
mainfrom
dev/vanzue/fix-275-agent-pane-persist

Conversation

@vanzue

Copy link
Copy Markdown
Contributor

Problem

Fixes #275. When Restore window layout / Restore window layout and content is enabled, opening the terminal after a restart fails the agent pane's ACP transport and litters the window with broken/duplicate cmd panes.

Root cause

The agent pane was serialized into state.json like an ordinary terminal pane. Its command line embeds session-specific state:

wta.exe --connect-master "\\.\pipe\wta-master-DD3592BF-..." --owner-tab-id "{40550ecc-...}" ... --start-stashed

Both the --connect-master named pipe (the previous run's wta-master) and the --owner-tab-id are gone after a restart. On restore, WT replays the saved command line, so a fresh wta-helper tries to connect to the now-dead pipe:

WARN  helper: master pipe connect giving up ... attempts=21
ERROR helper: run_acp_client_over_pipe failed error=connect to master pipe '\\.\pipe\wta-master-DD3592BF-...': os error 2
INFO  failure: agent failure class="handshake_failed"

Combined with the per-tab pre-warmed agent pane each restored tab already re-creates (which connects to the new live master fine), the window ends up with broken + duplicate panes.

Fix

Agent panes are ephemeral per-tab infrastructure and must not be persisted. In Pane::BuildStartupActions, on the Persist path only, when one child of a split is an agent-pane leaf we collapse the split and serialize just the other child — so no agent-pane command line is ever written to the layout.

Nothing is lost:

  • Cross-window move (Content / MovePane) still reattaches via ContentId — unaffected.
  • Each restored tab already re-warms a fresh stashed agent pane bound to the live master.
  • The user can re-open the agent pane after restore to get a fresh one.

Testing

  • Built TerminalAppLib (contains Pane.cpp) — 0 errors.
  • Manual repro confirmed via logs (dead-pipe handshake_failed vs live-pipe success). Suggested manual regression: enable layout restore, open several tabs, close & reopen, verify the shell layout restores cleanly with no leftover agent/cmd panes.

When "Restore window layout (and content)" is enabled, the agent pane was
serialized into state.json like an ordinary terminal pane. Its command line
embeds session-specific state -- the previous run's wta-master named pipe
(--connect-master) and the old tab StableId (--owner-tab-id) -- both of which
are gone after a restart.

On restore WT replays that saved command line, so a fresh wta-helper tries to
connect to the now-dead master pipe and fails its ACP transport
(handshake_failed, os error 2 after 21 retries). Combined with the per-tab
pre-warmed agent pane that each restored tab already re-creates, the window
ends up littered with broken/duplicate panes.

Fix: in Pane::BuildStartupActions, skip agent panes on the Persist path -- when
one child of a split is an agent-pane leaf, collapse the split and only
serialize the other child. Nothing is lost: cross-window move (Content /
MovePane) still reattaches via ContentId, and each restored tab re-warms a
fresh stashed agent pane bound to the live master. The user can re-open the
agent pane after restore to get a fresh one.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 26, 2026 00:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents agent panes (which embed run-specific wta connection state) from being serialized into the persisted window layout (state.json) during app restart restores, avoiding broken ACP transports and duplicated/bad panes on startup when “Restore window layout(/and content)” is enabled.

Changes:

  • In Pane::BuildStartupActions, special-case BuildStartupKind::Persist to omit agent-pane leaves from persisted layouts by collapsing any split where exactly one child is an agent-pane leaf.
  • Keep cross-window move behavior unchanged (agent panes can still reattach via ContentId).

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@vanzue
Kai Tao (vanzue) force-pushed the dev/vanzue/fix-275-agent-pane-persist branch from a0e31d6 to c8d1a1c Compare June 26, 2026 02:04
Copilot AI review requested due to automatic review settings June 26, 2026 02:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

check-spelling-bot Report

⚠️ Dictionary not found

Problems were encountered retrieving check dictionaries (cspell:software-terms/dict/softwareTerms.txt cspell:public-licenses/src/additional-licenses.txt cspell:python/src/python/python.txt cspell:dotnet/dict/dotnet.txt cspell:cpp/src/people.txt cspell:ruby/dict/ruby.txt cspell:dart/src/dart.txt cspell:html/dict/html.txt cspell:cpp/src/ecosystem.txt cspell:python/src/common/extra.txt cspell:cpp/src/stdlib-cerrno.txt cspell:shell/dict/shell-all-words.txt cspell:cpp/src/compiler-clang-attributes.txt cspell:cpp/src/lang-jargon.txt cspell:cpp/src/lang-keywords.txt cspell:sql/src/sql.txt cspell:redis/dict/redis.txt cspell:ada/dict/ada.txt cspell:k8s/dict/k8s.txt cspell:docker/src/docker-words.txt cspell:lua/dict/lua.txt cspell:cpp/src/template-strings.txt cspell:css/dict/css.txt cspell:php/dict/php.txt cspell:cpp/src/compiler-gcc.txt cspell:scala/dict/scala.txt cspell:node/dict/node.txt cspell:swift/src/swift.txt cspell:typescript/dict/typescript.txt cspell:cpp/src/stdlib-cpp.txt cspell:python/src/python/python-lib.txt cspell:fullstack/dict/fullstack.txt cspell:elixir/dict/elixir.txt cspell:sql/src/tsql.txt cspell:latex/dict/latex.txt cspell:rust/dict/rust.txt cspell:powershell/dict/powershell.txt cspell:clojure/src/clojure.txt cspell:cpp/src/stdlib-c.txt cspell:gaming-terms/dict/gaming-terms.txt cspell:cpp/src/stdlib-cmath.txt cspell:cpp/src/compiler-msvc.txt cspell:npm/dict/npm.txt cspell:haskell/dict/haskell.txt cspell:python/src/additional_words.txt cspell:svelte/dict/svelte.txt cspell:java/src/java-terms.txt cspell:java/src/java.txt cspell:monkeyc/src/monkeyc_keywords.txt cspell:public-licenses/src/generated/public-licenses.txt cspell:django/dict/django.txt cspell:r/src/r.txt cspell:software-terms/dict/webServices.txt cspell:golang/dict/go.txt).

⚠️ For more information, see check-dictionary-not-found.

🔴 Please review

See the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.

Unrecognized words (10)

BITMAPFILEHEADER
cands
hmem
nbody
offbits
pastable
Pels
rescans
wingdi
YPels

These words are not needed and should be removed Backgrounder CANTCALLOUT Ccc cplusplus ctl Debian dotnet drv endptr EOFs evt Fullwidth gitlab hdr idl IME inbox ININPUTSYNCCALL intelligentterminal Ioctl KVM lbl lld lsb NODEFAULT NONINFRINGEMENT notif oss outdir Podcast pri prioritization rcv segfault SND sourced SWP Tbl testname transitioning unk unparseable unregisters Virt VMs webpage websites WINVER xsi

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/intelligent-terminal.git repository
on the dev/vanzue/fix-275-agent-pane-persist branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
perl - 'https://github.com/microsoft/intelligent-terminal/actions/runs/28212858438/attempts/1' &&
git commit -m 'Update check-spelling metadata'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2064) from .github/actions/spelling/expect/alphabet.txt .github/actions/spelling/expect/expect.txt .github/actions/spelling/expect/web.txt and unrecognized words (10)

Dictionary Entries Covers Uniquely
cspell:csharp/csharp.txt 32 2 2
cspell:aws/aws.txt 232 2 2
cspell:fonts/fonts.txt 536 1 1

Consider adding to the extra_dictionaries array (in the .github/actions/spelling/config.json file):

    "cspell:csharp/csharp.txt",
    "cspell:aws/aws.txt",
    "cspell:fonts/fonts.txt",

To stop checking additional dictionaries, put (in the .github/actions/spelling/config.json file):

"check_extra_dictionaries": []

Forbidden patterns 🙅 (1)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

Should be preexisting
[Pp]re[- ]existing
Errors and Warnings ❌ (2)

See the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.

❌ Errors and Warnings Count
⚠️ check-dictionary-not-found 54
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@vanzue
Kai Tao (vanzue) merged commit 88a1c28 into main Jun 26, 2026
10 checks passed
@vanzue
Kai Tao (vanzue) deleted the dev/vanzue/fix-275-agent-pane-persist branch June 26, 2026 03:10
Kai Tao (vanzue) added a commit that referenced this pull request Jul 3, 2026
* docs(release-check-list): sync with v0.1.2 features

Reviewed the release checklist against the v0.1.2 release notes and fixed two outdated statements plus added seven missing test cases for new features.

Outdated statements corrected:
- Session view refresh: now F5 on-demand re-scan (incl. WSL distros started after launch), not gated on hooks (#344).
- Historical state: history is now sourced from ACP session/list, not on-disk file parsing (#365).

Missing test cases added:
- Alt+V clipboard image paste into agent chat (#354)
- GitHub Enterprise Copilot sign-in (#362)
- Bash/WSL shell integration incl. set -u safety (#340)
- Shells self-report identity via OSC 9001;ShellType + nested-shell autofix targeting (#345)
- Environment-aware answers/fixes: investigate PATH before answering/autofixing (#306)
- WSL distro sessions visible and resumable in the correct distro (#323)
- Agent panes not persisted into saved window layout (#360/#275)

Co-authored-by: Copilot <[email protected]>

* docs(release-check-list): tag new v0.1.2 cases with [new] + add 5 more

Second review pass over the release checklist against the v0.1.2 release notes:

- Added a [new] coverage marker to the legend and tagged all 12 genuinely-new v0.1.2 test cases with it (the two reworded existing cases — F5 refresh, ACP-sourced historical — are corrections, not new cases, so they stay untagged).
- Added 5 more previously-missing cases surfaced by a closer read:
  - FRE execution-policy detection is correct / no false-block on probe timeout (#336/#338/#309)
  - wta-master death is a consistent degraded state requiring /restart, no split-brain (#329)
  - Session titles are clean (no bare '# AGENTS.md instructions' heading) (#355)
  - Focus brings the target window to the foreground (#353)
  - Agent-created terminals inherit the active pane profile (#366, closes #351)

Co-authored-by: Copilot <[email protected]>

* test(e2e): add master-death degraded-state integration test (#329); drop rolled-back WSL session checklist item

Adds Feature.AgentMasterDeath.Tests.ps1: kills this app's wta-master out from under a live helper and asserts the full #329 contract end-to-end — the pane leaves Connected, the / popup is filtered to only /restart, NO master is silently respawned while degraded (anti-split-brain), and /restart brings up exactly one fresh master and reconnects. Verified passing live against the deployed dev package.

Also removes the '[new] WSL distro sessions are visible and resumable' checklist item (#323) since WSL in-distro session support is being rolled back for v0.1.2, and drops the WSL example from the F5 refresh item to match.

Co-authored-by: Copilot <[email protected]>

* Address Copilot review: tighten master-count assertion and clarify Alt+V behavior

- Feature.AgentMasterDeath.Tests.ps1: assert exactly one wta-master while connected (-Be 1, was -BeGreaterThan 0) so the connected-state gate itself catches a split-brain regression. Re-verified passing live.

- release-check-list.md: correct the Alt+V item — Alt+V queues the image until the next prompt, and an unsupported agent / empty clipboard surfaces a clear system message rather than being a silent no-op.

The [WSL-<distro>] raw-angle-bracket comment is already resolved: that checklist item was removed with the WSL session rollback.

Co-authored-by: Copilot <[email protected]>

* Address Copilot review round 2: block /stop in degraded popup test, release-agnostic [new] marker, spelling fix

- Feature.AgentMasterDeath.Tests.ps1: add /stop to the blocked-slash-command list so a regression that offers /stop while transport-lost is caught (it's a real CommandKind::Stop). Re-verified passing live.

- release-check-list.md: reword the [new] marker in release-agnostic terms and say when to clear it (was hard-coded to v0.1.2); fix forbidden spelling non-existent -> nonexistent (check-spelling CI).

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
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.

ACP transport failed when trying to restore multiple tabs on startup

3 participants