Skip to content

Commit 0a4c1bb

Browse files
committed
fix: break out of exec loop after end marker to prevent hanging
1 parent 8a93733 commit 0a4c1bb

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

centml/cli/shell.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,35 +213,35 @@ async def _exec_session(ws_url, token, command):
213213
exit_code = 0
214214
buffer = ""
215215
is_capturing = False
216+
is_done = False
216217
async for raw_msg in ws:
217218
msg = json.loads(raw_msg)
218219
if msg.get("data"):
219220
buffer += msg["data"]
220-
# Process complete lines from buffer
221221
while "\n" in buffer:
222222
line, buffer = buffer.split("\n", 1)
223223
clean = _strip_ansi(line).rstrip("\r")
224224
if _BEGIN_MARKER in clean:
225225
is_capturing = True
226226
continue
227227
if _END_MARKER in clean:
228-
# Parse exit code from marker line
229228
parts = clean.split(_END_MARKER + ":")
230229
if len(parts) > 1:
231230
try:
232231
exit_code = int(parts[1].strip())
233232
except ValueError:
234233
pass
235-
is_capturing = False
236-
continue
234+
is_done = True
235+
break
237236
if is_capturing:
238237
sys.stdout.write(line + "\n")
239238
sys.stdout.flush()
240239
elif msg.get("error"):
241240
sys.stderr.write(f"Error: {msg['error']}\n")
242241
return 1
243-
if "Code" in msg:
244-
exit_code = msg["Code"]
242+
if is_done or "Code" in msg:
243+
if "Code" in msg:
244+
exit_code = msg["Code"]
245245
break
246246
return exit_code
247247

0 commit comments

Comments
 (0)