Skip to content

Commit ca74a33

Browse files
Merge pull request #72 from AI-Hypercomputer/shangkun-fix-session-save
fix: save session.json even when auto agent client fail
2 parents e73792e + 2368782 commit ca74a33

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

MaxKernel/auto_search/worker.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,16 @@ async def _run_agent(
133133
)
134134

135135
await client.create_session(initial_state)
136-
await client.run_async()
137136
try:
138-
session_json_path = os.path.join(session_dir, "session.json")
139-
with open(session_json_path, "w") as f:
140-
json.dump(client.get_session_data(), f, indent=2)
141-
logger.info(f"Saved session data to {session_json_path}")
142-
except Exception as se:
143-
logger.warning(f"Failed to save session data for {node_id}: {se}")
137+
await client.run_async()
138+
finally:
139+
try:
140+
session_json_path = os.path.join(session_dir, "session.json")
141+
with open(session_json_path, "w") as f:
142+
json.dump(client.get_session_data(), f, indent=2)
143+
logger.info(f"Saved session data to {session_json_path}")
144+
except Exception as se:
145+
logger.warning(f"Failed to save session data for {node_id}: {se}")
144146
return client.get_state()
145147

146148
def _process_results(

0 commit comments

Comments
 (0)