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

bug(chat): eager startup restore causes resource spike and severe desktop lag

Open harshitsinghbhandari opened this issue 3 months ago • 3 comments

Bug

After updating/restarting AO with many non-terminated Chat sessions, startup reconciliation eagerly restores every Chat controller. The desktop becomes severely laggy during the restore burst and Activity Monitor can show approximately 2.42 GB attributed to AO/the daemon. Once reconciliation settles, the same app becomes responsive and the daemon stabilizes around 200 MB.

Source: Live local report by @harshitsinghbhandari on 2026-08-28 Installed build: 0.12.10-nightly.202608280852 Analyzed against: a5c12e706f35c99712b066ba931130fc195a6753 Environment: macOS Darwin 27.0.0 arm64, Go 1.27.0 Confidence: High for the eager-restore/resource-storm mechanism; low for Activity Monitor’s transient 2.42 GB attribution because the surviving daemon PID reports a 214 MB physical-footprint peak. Priority: P2 — severe temporary desktop degradation with a workaround (wait for reconciliation or terminate stale sessions), no observed data loss.

Reproduction

  1. Accumulate multiple non-terminated Codex Chat sessions, including idle sessions.
  2. Install/restart the desktop app.
  3. Observe AO during background startup reconciliation.
  4. The UI becomes severely laggy while AO starts one codex app-server per live Chat session and restores browser views.
  5. After reconciliation finishes, the UI returns to normal responsiveness and daemon memory stabilizes.

Live evidence

The affected machine had 14 non-terminated sessions, all Chat mode:

  • 10 idle
  • 2 working
  • 1 changes-requested
  • 1 exited

Immediately after restart AO owned:

  • 13 codex app-server children (about 430 MiB RSS total)
  • 10 Electron renderer children
  • approximately 1.15 GiB measured application-tree physical footprint after stabilization
  • daemon PID 67086 at about 178 MiB RSS / 210 MiB physical footprint after stabilization

All 13 app-server children were started by the daemon during the same startup window. The app became responsive again without a restart after reconciliation settled.

Root cause

reconcileLivePass selects every non-terminated session without considering Chat activity or whether an idle controller needs to be hot:

  • backend/internal/session_manager/manager.go:2480

For Chat, reconcileLive assumes the controller cannot survive a daemon restart and unconditionally falls through to in-place relaunch:

  • backend/internal/session_manager/manager.go:2242

PR #4553 fixed Chat relaunch failures and preservation semantics. That made accumulated sessions restore reliably, but also exposed the unbounded steady-state/process-count and burst-cost behavior on machines with many live idle sessions.

The worker pool bounds simultaneous session-manager jobs, but each successful job leaves another provider process resident. Startup also overlaps Electron/browser initialization, so bounded restore concurrency still produces a substantial CPU/I/O/graphics burst and poor UI responsiveness.

Proposed fix

Implement cold/lazy Chat-controller restoration rather than eagerly warming every idle session:

  1. Eagerly restore only sessions that require a live provider boundary (active turn, pending approval/input, or durable transition/retry work).
  2. Leave safely idle Chat sessions cold while preserving their durable session, worktree, provider conversation ID, and transcript.
  3. Add an idempotent, per-session ensureChatController boundary used by human Send, ao send, automation/outbox delivery, and explicit Resume. It must acquire the existing agent-operation/controller gates, resume the saved provider conversation once, and then deliver.
  4. Do not persist a derived display status merely to represent coldness. Derive controller availability at service read time or expose a provider-neutral transient controller state.
  5. Add an idle TTL/LRU follow-up so long-running desktops can hibernate inactive Chat controllers, not only skip them at boot.
  6. Keep sessions with active turns or unresolved provider requests hot; never hibernate across an in-flight turn/approval.

A smaller mitigation can skip eager restore for durable idle Chat sessions and surface them as resumable, but requiring users to click Resume after every restart is less desirable than lazy rehydration on first input.

Tests

  • Startup with N idle Chat sessions starts zero provider children.
  • Startup with working/pending-input Chat sessions restores only those that require continuity.
  • First human send to a cold session resumes exactly once and delivers exactly once.
  • Concurrent human/automation sends share one resume and preserve idempotency keys/order.
  • Resume failure preserves worktree/session/provider identity and returns a typed retryable error.
  • Explicit kill cannot race lazy resume into recreating a controller.
  • Startup reconciliation remains bounded and the desktop API becomes ready without waiting for cold sessions.
  • Process-level test asserts idle-session count does not imply app-server process count.

Impact

  • Noticeable desktop freezes/lag after updates or restarts.
  • Memory and process count scale with every non-terminated Chat session, even when idle.
  • Users with accumulated sessions experience the worst startup behavior.
  • Resource pressure can make Activity Monitor attribution confusing and may amplify memory compression.

Related

  • #4526 — preserves native Chat harness processes across daemon restart; the lifecycle design must distinguish active continuity from idle hibernation.
  • PR #4553 — made failed Chat recovery safe and restored controllers reliably, exposing this resource-scaling behavior.

harshitsinghbhandari avatar Aug 28 '26 17:08 harshitsinghbhandari

@diyaavirmani — could you take this Mac-reproduced issue? GitHub currently won’t let me formally assign your account on this repo. I’m removing my assignment to flag this handoff request, but the issue will not list you as assignee unless repo access changes.

codebanditssss avatar Sep 24 '26 06:09 codebanditssss

Additional Linux evidence from a 2026-09-27 incident is tracked in #6111. On Linux, systemd-oomd selected and killed the AO app scope twice after sustained user-session memory PSI exceeded its configured threshold; an ACP Chat initialization timeout occurred before the first kill. Eager Chat restoration is a plausible AO-side contributor, but the evidence does not identify a sole initiating process and does not prove the timeout caused the pressure. This corroborates the resource-risk pattern across platforms, while keeping the incident evidence and root-cause confidence distinct.

LaibaFirdouse avatar Oct 01 '26 14:10 LaibaFirdouse

closing as superseded

Vaibhaav-Tiwari avatar Nov 02 '26 13:11 Vaibhaav-Tiwari