Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(workbench): close web-Chat stream on turn end, token-safely (#2, codex)

cyh0e1bf1e8a992
diff --git a/core/controller.py b/core/controller.py
index e7bbcd3f0..a3dfee4ab 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -614,10 +614,18 @@ class Controller:
if context is None:
return
sink = self.get_turn_sink(self._get_session_key(context))
- if sink is not None:
- done = sink.get("done_event")
- if done is not None:
- done.set()
+ if sink is None:
+ return
+ # Turn-token guard (mirrors ``_stream_chunk``): a SUPERSEDED turn ending
+ # (e.g. a stopped turn whose backend later fires turn/completed) must not
+ # close the CURRENT turn's stream. Fail-open when either token is absent.
+ sink_token = sink.get("turn_token")
+ ctx_token = (getattr(context, "platform_specific", None) or {}).get("turn_token")
+ if sink_token is not None and ctx_token is not None and sink_token != ctx_token:
+ return
+ done = sink.get("done_event")
+ if done is not None:
+ done.set()
def get_settings_manager_for_context(self, context: Optional[MessageContext] = None) -> SettingsManager:
if context is None:
diff --git a/modules/agents/codex/event_handler.py b/modules/agents/codex/event_handler.py
index ad3d41441..e2925c8b5 100644
--- a/modules/agents/codex/event_handler.py
+++ b/modules/agents/codex/event_handler.py
@@ -127,6 +127,9 @@ class CodexEventHandler:
self._clear_generated_image_snapshot(params)
self._agent._turn_registry.pop_turn(turn_id)
await self._agent._remove_ack_reaction(tracked_request)
+ # Turn ended without a result — release any web-Chat stream waiter
+ # (token-guarded, so a superseded turn won't close a newer stream).
+ self._agent.controller.mark_turn_complete(tracked_request.context)
return
if status == "failed":
@@ -161,6 +164,9 @@ class CodexEventHandler:
self._agent._turn_registry.pop_turn(turn_id)
if error_was_user_visible:
await self._agent._remove_ack_reaction(tracked_request)
+ # Failed turn surfaced an error notify but no result — close the
+ # web-Chat stream now instead of waiting out the safety timeout.
+ self._agent.controller.mark_turn_complete(tracked_request.context)
return
if not should_emit_result:
@@ -170,6 +176,7 @@ class CodexEventHandler:
self._clear_generated_image_snapshot(params)
self._agent._turn_registry.pop_turn(turn_id)
logger.debug("Ignoring inactive turn/completed for turn %s", turn_id)
+ self._agent.controller.mark_turn_complete(tracked_request.context)
return
pending = turn_state.pending_assistant if turn_state else None