Skip to content

Fix reaper killing live sessions by updating last_used_at timestamp#70

Merged
olsonjeffery merged 2 commits into
mainfrom
task/14-reaper-killing-live-sessions
Jul 24, 2026
Merged

Fix reaper killing live sessions by updating last_used_at timestamp#70
olsonjeffery merged 2 commits into
mainfrom
task/14-reaper-killing-live-sessions

Conversation

@olsonjeffery

Copy link
Copy Markdown
Owner

Problem

The opencode server pool's idle reaper kills live sessions because last_used_at on each ServerEntry is only set once at spawn time and never updated. The reaper compares Instant::now() - entry.last_used_at > idle_timeout (15m) — so any session whose total lifetime exceeds 15 minutes is reaped, even if it's actively processing (e.g., waiting for cargo tests).

Changes

  1. src/opencode_sdk/pool.rs: Added update_timestamp(user_id) method to OpenCodeServerPool, restructured get_or_spawn() to check-and-refresh the inner pool before the spawn path, improving code clarity with a ClientRef struct for the cached-client return path.

  2. src/providers/opencode_sdk_provider.rs: Added user_id: Uuid parameter to subscribe_and_spawn(), added periodic timestamp update (every 5 min) to the event stream reader task via tokio::select!, and updated callers at start_turn() and resume_turn() to pass user_id.

  3. src/opencode_sdk/server.rs: Added ServerEntry::update_timestamp() convenience method.

Testing

  • Unit tests added for update_timestamp(), get_or_spawn fast-path timestamp update, and reap_idle with refreshed entries
  • 419 tests pass, 0 fail
  • cargo fmt and cargo clippy pass

Closes #14

- Add update_timestamp() method to OpenCodeServerPool in pool.rs
- Restructure get_or_spawn() to check inner pool first and update timestamp on cache hit
- Add user_id: Uuid parameter to subscribe_and_spawn() in opencode_sdk_provider.rs
- Add periodic timestamp update (every 5 min) to event stream reader task
- Update start_turn() and resume_turn() callers to pass user_id
- Add unit tests for update_timestamp, reap_idle, and get_or_spawn fast path
- Update spec/extra/harnesses/opencode.md step 6 to describe new behavior
- Add test-only OpenCodeServer::test_dummy constructor in server.rs
- pool.rs: use HashMap::entry() in get_or_spawn, HashMap::retain in reap_idle, remove redundant drop
- provider.rs: reuse s_id.clone, flatten prompt extraction combinator chain, reuse spawn_transient
@olsonjeffery
olsonjeffery merged commit 357cfe3 into main Jul 24, 2026
3 checks passed
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