Problem
When LM Studio is closed (or the server stops) while lmcode is mid-generation, a raw traceback is printed to the terminal — likely an httpx connection error or an LM Studio SDK exception. The user sees a crash instead of a clean message.
Expected behaviour
Catch the disconnect and show something like:
LM Studio disconnected. Press Ctrl+C to exit or restart lmcode.
Or exit cleanly with a one-liner:
error: lost connection to LM Studio — exiting.
Implementation notes
- The error likely surfaces as an
httpx.RemoteProtocolError, httpx.ConnectError, websockets.exceptions.ConnectionClosedError, or an lmstudio.LMStudioClientError raised inside model.act() in Agent._run_turn().
- Wrap
await model.act(...) (and possibly the outer Agent.run() connection block) with a catch for those exception types.
- Print a clean Rich message using
ERROR color and a Rule separator, then either loop back to prompt (with reconnect logic) or exit via sys.exit(1).
- If looping back, the chat history is still intact and the user can reconnect by restarting LM Studio and pressing Enter.
Related
Problem
When LM Studio is closed (or the server stops) while lmcode is mid-generation, a raw traceback is printed to the terminal — likely an
httpxconnection error or an LM Studio SDK exception. The user sees a crash instead of a clean message.Expected behaviour
Catch the disconnect and show something like:
Or exit cleanly with a one-liner:
Implementation notes
httpx.RemoteProtocolError,httpx.ConnectError,websockets.exceptions.ConnectionClosedError, or anlmstudio.LMStudioClientErrorraised insidemodel.act()inAgent._run_turn().await model.act(...)(and possibly the outerAgent.run()connection block) with a catch for those exception types.ERRORcolor and aRuleseparator, then either loop back to prompt (with reconnect logic) or exit viasys.exit(1).Related