agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

Xterm handle replacement can dispose queued viewport work

Open maplenk opened this issue 3 months ago • 6 comments

Bug

Replacing a retained terminal's live xterm handle can dispose the old terminal while xterm still has queued viewport work for that instance.

The queued callback later reaches Viewport.syncScrollArea through the disposed terminal and throws in the renderer. This is most visible during same-session handle/generation replacement after agent switching, but the lifetime bug is provider-independent.

Expected behavior

AO should detach its listeners and transport synchronously, while deferring only the old terminal object's final dispose() call until xterm's already-queued viewport work has drained.

A replacement must remain immediate from AO's routing and input-ownership perspective; this fix must not keep the old transport writable for another tick.

Proposed focused fix

  • Detach AO listeners and transport immediately.
  • Schedule only the final old-terminal disposal on the next macrotask.
  • Cover exact active-handle replacement with real xterm in the retained-terminal Playwright suite.

The prepared patch is limited to XtermTerminal.tsx and one focused regression in terminal-viewport-retention.spec.ts.

Validation prepared

  • Frontend typecheck
  • E2E typecheck
  • 49 focused XtermTerminal Vitest tests
  • Exact real-xterm Playwright handle-replacement regression
  • git diff --check

This is a small follow-up to the retained-terminal work in #3371.

maplenk avatar Aug 10 '26 07:08 maplenk

I'd like to work on this. I opened draft PR #3804 before waiting for assignment, which did not follow CONTRIBUTING.md's expected order. I will not request review or continue upstream implementation unless maintainers assign this issue and confirm the scope. If you prefer, I will close the draft.

maplenk avatar Aug 10 '26 08:08 maplenk

Hey @maplenk , thank you for raising this. Would like to connect with you to understand more about this issue. I am a core contributor in the project, could we connect on discord. Here is the link to the server and my profile: Server: https://discord.gg/JuaXT7SVh My username: illegalcall

illegalcall avatar Aug 10 '26 09:08 illegalcall

Thanks for contributing to Agent Orchestrator.

This issue is being picked up by the current external contributor on-call pair:

  • @neversettle17-101
  • @illegalcall

If someone is already working on this, please continue as usual. The on-call pair is added for visibility, tracking, and support, not to take over the work. If you need help with review, direction, reproduction, or next steps, please tag @neversettle17-101 and @illegalcall here.

For faster context or live questions, you can also join the AO Discord.

Join the session here: https://discord.gg/H6ZDcUXmq

Come by if you want to see what is being built, ask questions, or just hang around with the community.

somewherelostt avatar Aug 10 '26 15:08 somewherelostt

Hey @somewherelostt

The PR is already created.

maplenk avatar Aug 11 '26 04:08 maplenk

https://github.com/Untrivial-ai/agent-orchestrator/pull/3804

maplenk avatar Aug 11 '26 04:08 maplenk

Closing as fixed on current main by #5105. The terminal cleanup now detaches AO state synchronously but defers the old xterm object’s final dispose() to the next task, allowing queued viewport initialization work to drain; focused lifecycle coverage was added with the change.

codebanditssss avatar Sep 23 '26 14:09 codebanditssss