Fix reaper killing live sessions by updating last_used_at timestamp#70
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The opencode server pool's idle reaper kills live sessions because
last_used_aton eachServerEntryis only set once at spawn time and never updated. The reaper comparesInstant::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
src/opencode_sdk/pool.rs: Addedupdate_timestamp(user_id)method toOpenCodeServerPool, restructuredget_or_spawn()to check-and-refresh the inner pool before the spawn path, improving code clarity with aClientRefstruct for the cached-client return path.src/providers/opencode_sdk_provider.rs: Addeduser_id: Uuidparameter tosubscribe_and_spawn(), added periodic timestamp update (every 5 min) to the event stream reader task viatokio::select!, and updated callers atstart_turn()andresume_turn()to passuser_id.src/opencode_sdk/server.rs: AddedServerEntry::update_timestamp()convenience method.Testing
update_timestamp(),get_or_spawnfast-path timestamp update, andreap_idlewith refreshed entriescargo fmtandcargo clippypassCloses #14