Skip to content

Let idle desktop chat views beyond the three most recent go - #2472

Merged
AbirAbbas merged 2 commits into
app/v3from
perf/chat-release-fds
Nov 6, 2026
Merged

AbirAbbas merged 2 commits into
app/v3from
perf/chat-release-fds

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2471.

Problem

Every chat the desktop app shows stayed held by codeaf app until the app quit, along with its open files and per-chat timers.

What one held chat costs, measured with lsof on a standalone codeaf app driven over its wire:

  • 6 fds from the presence watch on the session folder: fsnotify's kqueue backend opens the folder and each entry in it (.cell, .codeaf, meta.json, presence.json, meta.lock).
  • 1 fd for the journal, .cell/transcript.jsonl.
  • Once for all held chats: the watcher's kqueue and its two pipes.
  • The SQLite stores (4 handles, 7 WAL/shm) are process-wide and do not grow per chat.
  • agents.close already gives all of this back: 47 fds, then 59/65/71 with 1/2/3 chats open, then 47 after closing, the same on every cycle.

Fix

The idle sweep keeps an open view's conversation only for the appViewHolds (3) most recently used views. An older view idle for appAgentIdle (10 min) is let go the same way a background chat is: its state stays idle, and its next read or send opens it again through the normal ownership check.

internal/manual/chat/desktop-sync.md is updated to match.

Measurements

Standalone codeaf app on macOS. Before is the soak binary (app/v3 3a6aa31 + #2466); after is this branch. 10 seeded chats, each opened with agents.open and then left idle, no desk UI:

before after
fds at baseline 44 44
fds with 10 chats opened 108 107
fds after 11.5 idle minutes 107 64 (3 views held)
open 10, then close 10 44 → 107 → 44 44 → 107 → 44

Tests

  • New TestAppIdleViewsBeyondTheRecentHoldsAreLetGo. It opens 7 views and checks that all are kept within the idle rule. Past the rule, it checks that exactly the 3 most recently used are kept, that further opened-and-idle chats never grow the holds, and that every other open is released once.
  • Run 3 times: go test ./cmd/codeaf -run '^(TestAppIdleViewsBeyondTheRecentHoldsAreLetGo|TestAppLetsAnIdleConversationGoAndTheNextSendReopensIt)$' -count=3.
  • Run once: the idle-release, relay-fence and lazy-open tests (TestAppIdleRelease.*, TestAppBackgroundE13.*, TestAppLazy.*, TestALiveServiceKeepsItsAgentThroughTheIdleSweep), go vet ./cmd/codeaf, gofmt and go test ./internal/manual/.

🤖 Generated with Claude Code

AbirAbbas and others added 2 commits November 6, 2026 13:14
The window opens every chat it shows and never says when it stops showing
one, while an open view kept its conversation through the idle sweep until
agents.close. Each chat shown in a session therefore stayed held, with its
journal, presence watch and timers, until the app quit (#2471).

The idle sweep now keeps an open view's conversation only for the three most
recently used views. An older view idle for ten minutes is let go like a
background chat and opens again on its next read or send. Running turns,
waiting questions, crews, services and explicit closes behave as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AbirAbbas
AbirAbbas merged commit 2c717c0 into app/v3 Nov 6, 2026
6 checks passed
@AbirAbbas
AbirAbbas deleted the perf/chat-release-fds branch November 6, 2026 18:26
AbirAbbas added a commit that referenced this pull request Nov 6, 2026
…2473)

* Revert "Let idle desktop chat views beyond the three most recent go (#2472)"

This reverts commit 2c717c0.

Releasing an open view lets another process (the codeaf CLI on the same home)
run a turn in a chat the window is showing. Before #2472 that turn was refused
("this conversation is open in another window"). After it, the turn runs, the
window gets only working/idle state for it and none of its entries, and the
app's next open of that chat starts a spurious "the app closed unexpectedly"
resume turn. Restore the held view until a fix keeps both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* changelog: revert of bounded desktop view holds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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