OpenCode Actors keep an idle ~260 MiB TUI attach process because delivery goes through the PTY
Reported against: cccc built from upstream main
0d73fced, Linux.
Summary
For every OpenCode Actor, CCCC starts a managed OpenCode ACP session and an opencode attach TUI in a PTY. On a host with several background OpenCode Actors, the attach process sits idle at ~0% CPU while holding about 260 MiB per Actor. The ACP process itself is about 548 MiB.
The attach can't simply be skipped for background Actors, because message delivery depends on it:
actor_profile_runtime::resolvenormalizes OpenCode toRunnerKind::Pty, so a stored headless runner is overwritten and no "interactive or not" signal survives actor resolution (cccc-contractsnormalize_runtime_constraints/ActorRuntime::runner);local_headless::supervisor::submit_batchwrites messages through the PTY and returnsfalsewhen the managed session has no terminal (attach_managed/submit_batch).
Question
Could CCCC deliver Actor messages through the managed ACP session, and make the native TUI optional or on-demand (started when someone opens the Actor's terminal)? Background Actors could then run without an idle attach process, while the same provider session stays available for interactive inspection.
A design would need to keep delivery acceptance, turn correlation, cancellation, and model changes made in the native TUI, without creating a second provider session.
We haven't written a patch, because this is a design choice about the runtime rather than a local fix. We're happy to help test or implement whichever direction you prefer.
Related: #125 (per-bridge memory held after cccc_bootstrap).
Thank you for the detailed report, and for opening a design discussion before writing a patch. We investigated this against the current CCCC implementation and OpenCode 1.18.33.
For now, we have decided to retain the existing native TUI delivery path. The memory cost you identified is real; our hesitation is about preserving the current behavior with an implementation that remains small and maintainable.
Currently, each OpenCode Actor has a managed opencode acp backend and an opencode attach TUI connected to the same provider session. CCCC delivers Actor messages through the TUI’s PTY. Consequently, the TUI is started even for unattended Actors, and a subsequent delivery recreates it if it has exited. Recent lifecycle changes allow the backend to survive a TUI exit, but they do not remove this delivery dependency.
We confirmed that upgrading to 1.18.33 does not change this situation. In two isolated Linux samples, the attach process accounted for approximately 243–285 MiB of PSS. These are sample measurements rather than a universal saving, but they support your concern about the cumulative cost across several Actors.
We also tested direct delivery to the existing backend using a local mock model. It successfully accepted follow-up input while work was in progress, maintained the same session, and associated replies with the correct source messages. So the basic approach is feasible.
The harder part is configuration and behavioral consistency. A model or reasoning setting selected in the native TUI can remain local to that TUI until a message is submitted. Today, delivery through the TUI uses its current selection. A direct backend submission may instead use previously persisted settings. We also reproduced a case where omitting the reasoning variant from a backend request lost the previously selected high setting.
Delivery semantics need care as well. An asynchronous HTTP success response is not sufficient evidence that the message has been durably accepted. CCCC would need to preserve acceptance, turn correlation, cancellation, and uncertain-delivery handling. Simply switching to our existing ACP prompt path would not preserve behavior either: our current adapter rejects a controlled prompt while another turn is active. This is a constraint in CCCC’s adapter, not a general claim that OpenCode cannot accept input while busy.
We considered a hybrid approach—backend delivery when no TUI is running, and PTY delivery when one is present. That could preserve more native behavior, but it introduces two delivery paths and transition cases that also require careful validation.
We would prefer to keep CCCC as a thin orchestration layer and continue relying on OpenCode’s native interface for interactive configuration. Building an OpenCode-specific settings panel, or duplicating its configuration logic, would bring ongoing coupling and maintenance costs. It would also leave us responsible for reconciling changes made through two interfaces.
Given these tradeoffs, retaining the current implementation is the most balanced choice for us at this stage. We recognize that this leaves a meaningful resource cost for background Actors.
We would welcome a focused follow-up if you find a simpler way to preserve native configuration behavior and reliable delivery without substantial additional machinery. There is no need to prepare a large PR before discussing that approach. Your report and the issue-first discussion have been useful, and we appreciate your willingness to help investigate and test it.
Thanks for the careful write-up, and for testing the direct-backend route far enough to show the basic approach is feasible. Retaining the TUI path is completely understandable given the configuration-consistency tradeoff you described — the two-delivery-paths issue and the settings-duplication cost are real, and keeping this thin is the right instinct.
Noted for later: if we find a simpler way to keep native selection behaviour and reliable delivery acceptance, we'll bring it as a small idea first rather than a PR, exactly as you suggested.
Closing this. Thank you again for taking the design question seriously.