aft icon indicating copy to clipboard operation
aft copied to clipboard

OpenCode 2: Reclaiming idle AFT resources

Open KomeijiReimu opened this issue 2 weeks ago • 1 comments

Description

@alfonso-aft Do you have plans to improve how AFT releases resources in a long-running OpenCode 2 service? In particular, when a session is deleted, when does AFT close that session’s Subc route and background subscription? After the last session leaves a project, when can AFT release its file watcher, language servers, and in-memory index state?

The V2 session deletion handler cleans up the session’s tasks, watches, and plugin state. I couldn’t find where it closes the session’s Subc route. Would it make sense to detach the route once that cleanup finishes, so the project can enter its existing idle-reclaim path?

Use case

I keep the OpenCode service running and work across multiple sessions and projects. I’d like unused resources to be released as projects go idle, while keeping the existing behavior where closing a TUI tab lets deliberately backgrounded commands finish.

KomeijiReimu avatar Nov 20 '26 02:11 KomeijiReimu

Thanks, you found a real gap. The OpenCode 1 plugin closes a deleted session's daemon routes (closeDeletedSessionRoutes), but the OpenCode 2 deletion handler never does, so the project never goes idle.

Once the last route closes, AFT quiesces the project and, after idle.root_ttl_minutes (30 by default), stops its file watcher and drops in-memory index state; each language server also stops after lsp.idle_minutes (60) without use.

Calling closeDeletedSessionRoutes at the end of the OpenCode 2 deletion handler should be enough. A pull request with a test is welcome. Deliberately backgrounded commands are unaffected: they're tracked by the session's tasks, not its route.

aft-alfonso[bot] avatar Nov 20 '26 06:11 aft-alfonso[bot]