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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(workbench): clear model/effort on agent switch, stable send-now intent, claude startup persist, ref-guarded events (Codex round 13)
cyh618067e05bce
diff --git a/core/internal_server.py b/core/internal_server.pyindex 19e2c58d1..4eabce9a4 100644--- a/core/internal_server.py+++ b/core/internal_server.py@@ -466,23 +466,25 @@ def create_app(controller: "Controller") -> FastAPI:entry = in_flight.get(session_id)if entry is not None and not entry[0].done():_task, turn_context = entry- # Interrupt the running turn FIRST and only opt into flush-on-cancel- # once the backend stop is CONFIRMED — a best-effort stop that didn't- # actually interrupt the agent must not start the queued turn, or two- # turns would overlap and the first turn's late output could land- # after the cut-in (Codex P2). If the stop didn't take, leave the turn- # + queue untouched and report it.+ # Record the flush intent BEFORE awaiting the interrupt: if the stop+ # lets the turn settle normally during the await, _run_turn's finally+ # consumes the flag and flushes (send-now WANTS the queue to run).+ # Adding it afterwards would either be too late (the finished turn+ # already discarded nothing) or leave a STALE flag that makes a later+ # plain Stop wrongly flush (Codex P2). On a refused/failed stop we+ # drop it again and leave the turn + queue untouched.+ flush_on_cancel.add(session_id)stopped = Falsetry:stopped = bool(await controller.command_handler.handle_stop(turn_context))except Exception:logger.exception("internal send-now: backend stop failed for session=%s", session_id)if not stopped:+ flush_on_cancel.discard(session_id)return JSONResponse(status_code=409,content={"ok": False, "code": "stop_failed", "session_id": session_id},)- flush_on_cancel.add(session_id)_task.cancel()return {"ok": True, "session_id": session_id, "status": "interrupted"}# No running turn — flush the queue directly as a new turn (it rebuildsdiff --git a/modules/agents/claude_agent.py b/modules/agents/claude_agent.pyindex 6eb4ef7b1..fd326f073 100644--- a/modules/agents/claude_agent.py+++ b/modules/agents/claude_agent.py@@ -122,6 +122,17 @@ class ClaudeAgent(BaseAgent):)if not handled:await self.session_handler.handle_session_error(runtime_session_key, context, e)+ # ``handle_session_error`` sends through the IM client, but+ # ``AvibeBot.send_message`` doesn't persist to ``messages`` and the+ # web Chat renders only durable ``message.new`` rows — so persist a+ # terminal notify too, or the avibe user sees their prompt stop+ # with no explanation (Codex P2). Mirrors _stream_terminal_error.+ try:+ from core.message_mirror import persist_agent_message++ persist_agent_message(context, "notify", f"❌ Claude error: {e}")+ except Exception:+ logger.debug("claude: failed to persist terminal error row", exc_info=True)# Synchronous failure (query/setup raised) — no async receiver# result is coming for this turn, so release the web-Chat stream# waiter now (token-guarded, no-op for IM/CLI) instead of waitingdiff --git a/storage/workbench_sessions_service.py b/storage/workbench_sessions_service.pyindex 923e1f59b..8f9fe1994 100644--- a/storage/workbench_sessions_service.py+++ b/storage/workbench_sessions_service.py@@ -27,6 +27,11 @@ from storage.models import agent_sessions, scope_settings, scopesSESSION_ID_ALPHABET = "23456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"+# Distinguishes an omitted update field from a present ``None`` (clear). See+# ``update_session``: a present ``model=None`` must clear the column, but an+# omitted ``model`` must leave it untouched.+_UNSET: Any = object()+def _utc_now_iso() -> str:return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")@@ -206,8 +211,8 @@ def update_session(agent_name: Optional[str] = None,agent_backend: Optional[str] = None,agent_variant: Optional[str] = None,- model: Optional[str] = None,- reasoning_effort: Optional[str] = None,+ model: Any = _UNSET,+ reasoning_effort: Any = _UNSET,) -> dict[str, Any]:existing = conn.execute(select(agent_sessions.c.id).where(agent_sessions.c.id == session_id)@@ -227,9 +232,13 @@ def update_session(values["agent_backend"] = agent_backendif agent_variant is not None:values["agent_variant"] = str(agent_variant)- if model is not None:+ # ``model`` / ``reasoning_effort`` use a sentinel default so a PRESENT+ # ``None`` clears the column (switching to an agent whose default model /+ # effort is empty must drop the previous agent's override), while an omitted+ # field leaves the stored value untouched (Codex P2).+ if model is not _UNSET:values["model"] = model or None- if reasoning_effort is not None:+ if reasoning_effort is not _UNSET:values["reasoning_effort"] = reasoning_effort or Noneconn.execute(update(agent_sessions).where(agent_sessions.c.id == session_id).values(**values))diff --git a/tests/test_core_services_sessions.py b/tests/test_core_services_sessions.pyindex e3d236c95..1383e4c51 100644--- a/tests/test_core_services_sessions.py+++ b/tests/test_core_services_sessions.py@@ -140,3 +140,32 @@ def test_archive_marks_session(isolated_state):with engine.connect() as conn:page = sessions_service.list_sessions(conn, scope_id=scope_id, status="active")assert page["sessions"] == [], "archived sessions should not appear in the active list"+++def test_update_session_present_null_clears_model_and_effort(isolated_state):+ """Switching to an agent with no default model/effort sends present nulls;+ update_session must CLEAR the columns (drop the prior agent's override),+ while omitting the fields leaves them untouched (Codex P2)."""+ engine = create_sqlite_engine()+ with engine.begin() as conn:+ scope_id = _seed_avibe_scope(conn)+ session = sessions_service.create_session(+ conn, scope_id=scope_id, agent_backend="codex", model="gpt-5-codex", reasoning_effort="high"+ )+ sid = session["id"]+ # Present null → clear both.+ sessions_service.update_session(conn, sid, model=None, reasoning_effort=None)+ with engine.connect() as conn:+ cleared = sessions_service.get_session(conn, sid)+ assert cleared["model"] is None+ assert cleared["reasoning_effort"] is None++ # Omitting the fields leaves the (re-set) values untouched.+ with engine.begin() as conn:+ sessions_service.update_session(conn, sid, model="claude-sonnet-4-6", reasoning_effort="low")+ sessions_service.update_session(conn, sid, title="renamed") # model/effort omitted+ with engine.connect() as conn:+ kept = sessions_service.get_session(conn, sid)+ assert kept["model"] == "claude-sonnet-4-6"+ assert kept["reasoning_effort"] == "low"+ assert kept["title"] == "renamed"diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsxindex 499ead529..7291d84eb 100644--- a/ui/src/components/workbench/ChatPage.tsx+++ b/ui/src/components/workbench/ChatPage.tsx@@ -271,8 +271,13 @@ export const ChatPage: React.FC = () => {useEffect(() => {if (!sessionId) return;const disconnect = api.connectWorkbenchEvents({+ // NB: match against sessionIdRef.current (the CURRENT route), NOT the+ // captured ``sessionId`` — there is a window after a chat switch before+ // React runs this subscription's cleanup, during which an event for the+ // PREVIOUS chat would otherwise pass the stale check and append into the+ // new chat (Codex P2).onMessageNew: (msg) => {- if (msg.session_id !== sessionId) return;+ if (msg.session_id !== sessionIdRef.current) return;if (!isTranscriptMessage(msg)) return;appendMessage(msg);// ``turn.end`` is the authoritative end signal, but a ``result`` row is@@ -286,16 +291,16 @@ export const ChatPage: React.FC = () => {}},onTurnStart: (data) => {- if (data.session_id === sessionId) setWorking(true);+ if (data.session_id === sessionIdRef.current) setWorking(true);},onTurnEnd: (data) => {// The controller confirms the turn settled (result, agent error, cancel,// or its own timeout) — the authoritative end of the working state.- if (data.session_id === sessionId) setWorking(false);+ if (data.session_id === sessionIdRef.current) setWorking(false);},onQueueUpdated: (data) => {// The send-while-busy queue changed (enqueue / flush / per-item delete).- if (data.session_id === sessionId) void refreshQueue();+ if (data.session_id === sessionIdRef.current) void refreshQueue();},onConnected: () => {// Every (re)connect recovers any state missed while the socket was down:@@ -948,8 +953,11 @@ const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({ session, agents, onagent_name: agent.name,agent_id: agent.id,agent_backend: agent.backend,- model: agent.model,- reasoning_effort: agent.reasoning_effort,+ // Explicit null (not undefined, which JSON.stringify+ // drops) so switching to an agent with no default model /+ // effort CLEARS the previous agent's override server-side.+ model: agent.model ?? null,+ reasoning_effort: agent.reasoning_effort ?? null,})}>