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): session reset, gap-safe reconcile, per-backend effort, codex startup release (Codex round 8)

cyhe0afb4adca65
diff --git a/modules/agents/codex/agent.py b/modules/agents/codex/agent.py
index de6f339ee..fa9d5670a 100644
--- a/modules/agents/codex/agent.py
+++ b/modules/agents/codex/agent.py
@@ -73,6 +73,9 @@ class CodexAgent(BaseAgent):
"❌ Codex CLI not found. Please install it or set CODEX_CLI_PATH.",
)
await self._remove_ack_reaction(request)
+ # Codex gave up before a turn started — release the web-Chat
+ # working/Stop state now instead of leaving it until the fallback.
+ self._event_handler._release_stream_turn(request.context)
return
except Exception as e:
logger.error("Failed to start Codex transport: %s", e, exc_info=True)
@@ -82,6 +85,7 @@ class CodexAgent(BaseAgent):
f"❌ Failed to start Codex CLI: {e}",
)
await self._remove_ack_reaction(request)
+ self._event_handler._release_stream_turn(request.context)
return
# Track session_key and cwd for scoped invalidation
@@ -122,6 +126,7 @@ class CodexAgent(BaseAgent):
f"❌ Failed to interrupt previous Codex turn: {e}",
)
await self._remove_ack_reaction(request)
+ self._event_handler._release_stream_turn(request.context)
return
interrupted_request = self._event_handler.clear_pending(active_turn)
if interrupted_request:
@@ -186,6 +191,10 @@ class CodexAgent(BaseAgent):
error_text,
)
await self._remove_ack_reaction(request)
+ # The turn never started (all retries failed) — release the
+ # web-Chat working/Stop state instead of leaving it until the
+ # fallback timeout (Codex P2).
+ self._event_handler._release_stream_turn(request.context)
async def handle_stop(self, request: AgentRequest) -> bool:
"""Gracefully interrupt the active turn."""
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index aeaa82f67..88e08dfb1 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -15,7 +15,18 @@ import { Button } from '../ui/button';
import { Input } from '../ui/input';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
-const EFFORT_OPTIONS = ['low', 'medium', 'high', 'max'];
+// Reasoning-effort options are backend-specific (mirrors the backend's own
+// lists in modules/agents/opencode/utils.py): Codex is minimal..xhigh, Claude is
+// low/medium/high. Offering a global low/medium/high/max let a Codex session
+// pick an invalid 'max' and hid valid 'minimal'/'xhigh' (Codex P2). OpenCode's
+// is model-dependent; use the broad superset as a reasonable default.
+const EFFORT_BY_BACKEND: Record<string, string[]> = {
+ claude: ['low', 'medium', 'high'],
+ codex: ['minimal', 'low', 'medium', 'high', 'xhigh'],
+ opencode: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
+};
+const DEFAULT_EFFORTS = ['low', 'medium', 'high'];
+const effortOptionsFor = (backend: string): string[] => EFFORT_BY_BACKEND[backend] ?? DEFAULT_EFFORTS;
// Last-resort failsafe for a LOST ``turn.end`` event. The controller is the
// authority on turn end (``turn.start`` / ``turn.end`` over the bus) and its own
@@ -95,9 +106,6 @@ export const ChatPage: React.FC = () => {
// boolean, so a second create-via-chat flow that reuses this ChatPage
// instance (React Router swaps only the :sessionId) still fires.
const initialHandledSessionRef = useRef<string | null>(null);
- // Latest appended message id — the cursor for reconciling durable storage
- // after a missed-event window (see ``reconcile``).
- const lastIdRef = useRef<string | null>(null);
// The session the component is currently on. Async loads capture their
// request's sessionId and compare against this before committing state, so a
// load that resolves after the user switched chats can't leak the previous
@@ -112,35 +120,25 @@ export const ChatPage: React.FC = () => {
setMessages((prev) => (prev.some((m) => m.id === msg.id) ? prev : mergeById(prev, [msg])));
}, []);
- // The transcript is append-ordered, so the last row is the newest — track its
- // id as the reconcile cursor without threading it through every setter.
- useEffect(() => {
- lastIdRef.current = messages.length ? messages[messages.length - 1].id : null;
- }, [messages]);
-
// Reconcile against durable storage after a window where ``message.new`` could
// have been missed — the SSE broker is an in-memory fan-out with no replay, so
// a reconnect or a backgrounded mobile tab can drop events while the reply is
- // safely in SQLite. Fetches everything after the last-seen row and appends it
- // (deduped); a terminal agent row also clears the working indicator. Cheap
- // (one bounded query) and idempotent, so it's safe to call on every reconnect
- // / page-visible transition.
+ // safely in SQLite. Re-fetches the RECENT WINDOW (not just rows after a cursor)
+ // and merges (deduped), so a missed EARLIER row — a flushed queued prompt, or a
+ // prompt sent from another tab — is recovered even if a later row already
+ // arrived; a cursor-after query would skip past the gap forever (Codex P2).
+ // Does NOT touch ``working``: ``turn.end`` is the authoritative end signal, and
+ // clearing on a fetched (possibly older) result could hide Stop on a newer
+ // queued turn that is still in flight (Codex P2). Cheap + idempotent.
const reconcile = useCallback(async () => {
if (!sessionId) return;
- const after = lastIdRef.current;
try {
- const res = await api.listSessionMessages(sessionId, after ? { afterId: after, limit: 50 } : { limit: 50 });
+ const res = await api.listSessionMessages(sessionId, { limit: 50 });
if (sessionId !== sessionIdRef.current) return; // switched chats mid-fetch
const fresh = res.messages.filter(isTranscriptMessage);
if (fresh.length) {
setMessages((prev) => mergeById(prev, fresh));
}
- // Recover a lost ``turn.end``: a freshly-seen agent ``result`` is a
- // definitive turn output, so the turn is over. Don't use ``notify`` here —
- // it can be a mid-turn status row (Codex P2); turn.end is the real signal.
- if (res.messages.some((m) => m.author === 'agent' && m.type === 'result')) {
- setWorking(false);
- }
} catch {
/* keep the current transcript; the next reconnect retries */
}
@@ -228,6 +226,12 @@ export const ChatPage: React.FC = () => {
// load/subscribe — so the previous conversation / queue / draft never leak in
// and the merge in ``refresh`` only ever unions same-session rows.
useEffect(() => {
+ // Clear ``session`` too (not just messages/queue/draft): otherwise the header
+ // keeps rendering the previous chat's title + agent picker until the new load
+ // finishes, and a rename / agent change would patch() the STALE session.id
+ // while the URL is already on the new chat (Codex P2). Nulling it shows the
+ // loading state until refresh() resolves the new session.
+ setSession(null);
setMessages([]);
setWorking(false);
setQueue([]);
@@ -905,9 +909,9 @@ const AgentRoutePicker: React.FC<AgentRoutePickerProps> = ({ session, agents, on
)}
</RouteColumn>
- {/* Column 3 — Effort */}
+ {/* Column 3 — Effort (options match the selected backend) */}
<RouteColumn title={t('chat.picker.effort')}>
- {EFFORT_OPTIONS.map((opt) => (
+ {effortOptionsFor(backend).map((opt) => (
<RouteItem
key={opt}
active={opt === currentEffort}
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 07f3ad5f0..0ebd8cd82 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1499,9 +1499,11 @@
"newAgent": "New agent",
"noModels": "No models found",
"effortOptions": {
+ "minimal": "Minimal",
"low": "Low",
"medium": "Medium",
"high": "High",
+ "xhigh": "Extra High",
"max": "Max"
}
},
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index ae085f7e7..9cef5700d 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1498,9 +1498,11 @@
"newAgent": "新建 Agent",
"noModels": "未找到模型",
"effortOptions": {
+ "minimal": "极简",
"low": "低",
"medium": "中",
"high": "高",
+ "xhigh": "极高",
"max": "最高"
}
},