fix(agent): add drop_session for cleanup paths; require base_sample in finish_session#2117
Closed
jingshenghang wants to merge 2 commits into
Closed
fix(agent): add drop_session for cleanup paths; require base_sample in finish_session#2117jingshenghang wants to merge 2 commits into
jingshenghang wants to merge 2 commits into
Conversation
added 2 commits
June 22, 2026 03:17
…n finish_session
- TrajectoryManager.drop_session / BaseAdapter.drop_session: free a session's
state without linearizing it into Samples, for rollouts that ended before the
trajectory could be consumed.
- finish_session: base_sample is now required (was =None) so the consume path
can never silently produce Samples from a None base.
- generate.py finally: use drop_session instead of finish_session(sid).
- run_command: skip empty done-marker reads (echo > truncates before write) to
avoid int('') crashes; keep polling instead.
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.
What
In the SWE coding-agent rollout,
generate()callsadapter.finish_session(session_id)in itsfinallyblock as a catch-all cleanup. Since this path passes nobase_sample,finish_session/get_trajectorydefaultedbase_sample=None.On the normal path the trajectory is already consumed (the
finallycall is a no-op), but when the rollout raises before consuming the trajectory (e.g. sandbox boot,evaluate, or the wall-clock timeout guard fires), the session tree is still in the manager. The cleanup call then reachesto_sample(base_sample=None)and crashes onNone.index.Overloading
base_sample=Noneto mean "cleanup only" also hid the intent: a reader can't tell from the call site whether it consumes the trajectory into trainable Samples or just frees state.Changes
TrajectoryManager.drop_session(sid)/BaseAdapter.drop_session(sid)— free a session's state (drain in-flight turns, pop the tree) without linearizing it intoSamples. For paths that must release the session but produce nothing trainable.finish_session:base_sampleis now required (was=None). The consume path can never silently build Samples from aNonebase; misuse fails loudly.generate.pyfinally: usedrop_session(session_id)instead offinish_session(session_id)— the cleanup path now states its intent and can't crash.run_command(harness/common.py): thedonemarker holds the exit code as text, butecho N > donetruncates the file before writing, so a poll landing in that window reads""andint("")raised. Skip empty reads and keep polling instead.Behavior
finish_session(base_sample=...)consumes and returns Samples; thefinallydrop_sessionis a no-op (tree already popped).drop_sessionreleases the session cleanly, no crash, nothing trained.