Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion emrg/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,14 @@ async def _reconnect():
_last_center = server_id or "emrg"
status.update(center=_last_center)
term.set_title(f"{session_title or session_id} @ {project_name}")
msg_count += 1; _update_left_extra()
# rant 21:52:18: daemon's done frame reports the authoritative
# current-context message count (system + history + tool results);
# fall back to the local +1 approximation when absent.
if data.get("context_messages") is not None:
msg_count = int(data["context_messages"])
else:
msg_count += 1
_update_left_extra()
term.render()
if "error" in data:
err = data["error"]; logger.error("server error: %s", err)
Expand Down
6 changes: 6 additions & 0 deletions emrg/server/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,8 @@ async def _run_tool_loop(
"done": True,
"delta": False,
"session_id": session.session_id,
# rant 21:52:18: authoritative current-context message count.
"context_messages": len(messages),
})

# Fire-and-forget: reflect on whether to save memories
Expand Down Expand Up @@ -2448,6 +2450,10 @@ async def _run_tool_loop(
"done": True,
"delta": False,
"session_id": session.session_id,
# rant 21:52:18: current LLM context size (system + history +
# user + all tool results + assistant replies) — authoritative
# for the TUI status bar message count.
"context_messages": len(messages),
})

# Fire-and-forget: reflect on whether to save memories
Expand Down
7 changes: 7 additions & 0 deletions tests/test_ws_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ async def _test():
}
await ws.send(json.dumps(task, ensure_ascii=False))
got_delta = got_tool = got_done = False
context_messages = None
while True:
frame = await asyncio.wait_for(ws.recv(), timeout=10)
resp = json.loads(frame)
Expand All @@ -231,8 +232,14 @@ async def _test():
got_tool = True
if resp.get("done"):
got_done = True
# rant 21:52:18: done frame must report the
# current LLM context size — system(1) + user(1)
# + assistant(tool_calls)(1) + tool result(1) +
# final assistant(1) = 5 for this one-round flow.
context_messages = resp.get("context_messages")
break
assert got_delta and got_tool and got_done
assert context_messages == 5
finally:
await ws.close()
finally:
Expand Down
Loading