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(auth): close latest Codex review gaps

Max58c33bba4129
diff --git a/core/controller.py b/core/controller.py
index 415be072a..ecc6a0195 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -2137,6 +2137,12 @@ class Controller:
# Reconciliation can start the sidecar, so settle it before closing the
# runtime or it could race shutdown and leave a process behind.
_stop_loop_coroutine(_cancel_memory_reconcile_task(), "Memory startup reconciliation")
+ message_handler = getattr(self, "message_handler", None)
+ if message_handler is not None:
+ _stop_loop_coroutine(
+ message_handler.drain_memory_capture_tasks(),
+ "Memory capture tasks",
+ )
memory_runtime = getattr(self, "memory_runtime", None)
if memory_runtime is not None:
_stop_loop_coroutine(memory_runtime.close(), "Memory runtime")
diff --git a/core/handlers/message_handler.py b/core/handlers/message_handler.py
index 147ccee69..1eb9b3351 100644
--- a/core/handlers/message_handler.py
+++ b/core/handlers/message_handler.py
@@ -84,6 +84,19 @@ class MessageHandler(BaseHandler):
task.add_done_callback(_on_done)
+ async def drain_memory_capture_tasks(self, timeout_seconds: float = 4.0) -> None:
+ """Finish queued Memory captures before the runtime closes on shutdown."""
+
+ pending = {task for task in self._memory_capture_tasks if not task.done()}
+ if not pending:
+ return
+ _done, pending = await asyncio.wait(pending, timeout=timeout_seconds)
+ if pending:
+ logger.warning("Cancelling %d Memory capture tasks after shutdown drain timeout", len(pending))
+ for task in pending:
+ task.cancel()
+ await asyncio.gather(*pending, return_exceptions=True)
+
async def handle_user_message(self, context: MessageContext, message: str):
"""Process regular human-originated messages and route to configured agent."""
await self._handle_turn(context, message, source=self.TURN_SOURCE_HUMAN)
diff --git a/tests/test_instance_authorization.py b/tests/test_instance_authorization.py
index b78210f9c..5401d6966 100644
--- a/tests/test_instance_authorization.py
+++ b/tests/test_instance_authorization.py
@@ -130,6 +130,7 @@ def test_http_policy_defaults_unknown_api_to_owner() -> None:
[
("POST", "/api/show-pages/ses-1/visibility"),
("GET", "/api/backend/codex/runtime"),
+ ("GET", "/api/backend/claude/auth"),
("GET", "/api/global-prompts"),
("GET", "/api/harness/runs"),
("GET", "/api/harness/runs/run-1"),
diff --git a/tests/test_memory_slice3.py b/tests/test_memory_slice3.py
index c4bba4835..a90bb2d93 100644
--- a/tests/test_memory_slice3.py
+++ b/tests/test_memory_slice3.py
@@ -115,6 +115,27 @@ def test_message_handler_retains_memory_capture_task_until_completion() -> None:
asyncio.run(run())
+def test_message_handler_drains_memory_capture_tasks_before_shutdown() -> None:
+ handler = MessageHandler.__new__(MessageHandler)
+ handler._memory_capture_tasks = set()
+
+ async def run() -> None:
+ completed = False
+
+ async def capture() -> None:
+ nonlocal completed
+ await asyncio.sleep(0)
+ completed = True
+
+ handler._track_memory_capture_task(asyncio.create_task(capture()))
+ await handler.drain_memory_capture_tasks()
+
+ assert completed is True
+ assert handler._memory_capture_tasks == set()
+
+ asyncio.run(run())
+
+
@pytest.mark.parametrize("platform", ["slack", "discord", "telegram", "feishu", "wechat"])
def test_capture_admits_every_enabled_bound_dm_user(platform: str) -> None:
controller = _controller(user=SimpleNamespace(enabled=True, is_admin=False))
diff --git a/ui/src/components/Workbench.tsx b/ui/src/components/Workbench.tsx
index 03ebbb28d..d25ace947 100644
--- a/ui/src/components/Workbench.tsx
+++ b/ui/src/components/Workbench.tsx
@@ -9,6 +9,7 @@ import { Composer } from './workbench/Composer';
import { ProjectPicker } from './workbench/ProjectPicker';
import { AgentRoutePicker } from './workbench/AgentRoutePicker';
import { useInstanceAuthorization } from '../context/InstanceAuthorizationContext';
+import { canCreateLocalProject } from '../lib/sessionInfo';
// Mirrors design.pen DnkGJ "Workbench" canvas: a centered hero panel +
// suggestion chips with the shared chat Composer below it. The Composer is
@@ -21,6 +22,7 @@ export const Workbench: React.FC = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { capabilities } = useInstanceAuthorization();
+ const canCreateProject = canCreateLocalProject(capabilities);
const ns = useNewSession({
active: capabilities.can_chat,
loadErrorText: t('newSession.loadError'),
@@ -45,7 +47,7 @@ export const Workbench: React.FC = () => {
// Quick chips under the hero — three of the most common first moves.
const suggestions = [
- ...(capabilities.can_manage_projects
+ ...(canCreateProject
? [{ key: 'newProject', icon: FolderPlus, onClick: () => setNewProjectOpen(true) }]
: []),
...(capabilities.can_manage_agents
@@ -133,7 +135,7 @@ export const Workbench: React.FC = () => {
)}
</div>
- {newProjectOpen && capabilities.can_manage_projects && (
+ {newProjectOpen && canCreateProject && (
<NewProjectDialog
onClose={() => setNewProjectOpen(false)}
onCreated={(project) => {
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index fe0c32cc1..fd29ed01e 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -218,6 +218,7 @@ export const ChatPage: React.FC = () => {
const readOnlyReason = sessionReadOnlyReason(session);
const readOnly = isSessionReadOnly(session);
const writable = canChat && !readOnly;
+ const metadataWritable = sessionCanChat && !readOnly;
// Chat-page-wide drag-and-drop: dropping files anywhere over the chat surface
// (not just the input row) stages them on the composer via its imperative
@@ -1930,7 +1931,8 @@ export const ChatPage: React.FC = () => {
canArchive,
} = useSessionActions({
session,
- writable,
+ writable: metadataWritable,
+ lifecycleWritable: writable,
// Rename focuses the header's existing click-to-edit title instead of adding
// a second editor for the same field.
onRenameStart: () => titleFieldRef.current?.startEditing(),
diff --git a/ui/src/components/workbench/ProjectPicker.tsx b/ui/src/components/workbench/ProjectPicker.tsx
index 3a9b2da48..62b4c659a 100644
--- a/ui/src/components/workbench/ProjectPicker.tsx
+++ b/ui/src/components/workbench/ProjectPicker.tsx
@@ -5,6 +5,7 @@ import clsx from 'clsx';
import type { WorkbenchProject } from '../../context/ApiContext';
import { Button } from '../ui/button';
import { useInstanceAuthorization } from '../../context/InstanceAuthorizationContext';
+import { canCreateLocalProject } from '../../lib/sessionInfo';
interface ProjectPickerProps {
projects: WorkbenchProject[];
@@ -22,6 +23,7 @@ interface ProjectPickerProps {
export const ProjectPicker: React.FC<ProjectPickerProps> = ({ projects, targetId, onSelect, onNewProject, disabled }) => {
const { t } = useTranslation();
const { capabilities } = useInstanceAuthorization();
+ const canCreateProject = canCreateLocalProject(capabilities);
return (
// min-w-0 lets this shrink inside the sheet's CSS grid so the chip row
// scrolls horizontally instead of stretching the whole sheet wide.
@@ -50,7 +52,7 @@ export const ProjectPicker: React.FC<ProjectPickerProps> = ({ projects, targetId
</Button>
);
})}
- {capabilities.can_manage_projects && (
+ {canCreateProject && (
<Button
type="button"
variant="outline"
diff --git a/ui/src/components/workbench/ProjectsPage.tsx b/ui/src/components/workbench/ProjectsPage.tsx
index b8a06a424..5a4c39a0e 100644
--- a/ui/src/components/workbench/ProjectsPage.tsx
+++ b/ui/src/components/workbench/ProjectsPage.tsx
@@ -25,6 +25,7 @@ import { useInstanceAuthorization } from '../../context/InstanceAuthorizationCon
import type { ProjectSessionsState } from '../../context/WorkbenchProjectsContext';
import type { WorkbenchProject, WorkbenchSession } from '../../context/ApiContext';
import { formatRelativeTime } from '../../lib/relativeTime';
+import { canCreateLocalProject } from '../../lib/sessionInfo';
import { Badge } from '../ui/badge';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
@@ -256,8 +257,9 @@ const MobileSessionRow: React.FC<{
session: WorkbenchSession;
unread: number;
canChat: boolean;
+ canManageMetadata: boolean;
onOpen: () => void;
-}> = ({ projectId, session, unread, canChat, onOpen }) => {
+}> = ({ projectId, session, unread, canChat, canManageMetadata, onOpen }) => {
const { t } = useTranslation();
const { renameSession } = useWorkbenchProjectsTree();
const navigate = useNavigate();
@@ -269,7 +271,8 @@ const MobileSessionRow: React.FC<{
const { actions, archiveDialog } = useSessionActions({
session,
- writable: canChat,
+ writable: canManageMetadata,
+ lifecycleWritable: canChat,
projectId,
onRenameStart: () => {
setDraft(session.title ?? '');
@@ -343,7 +346,7 @@ const MobileSessionRow: React.FC<{
</span>
)}
</button>
- {canChat && <Popover open={menuOpen} onOpenChange={setMenuOpen}>
+ {canManageMetadata && <Popover open={menuOpen} onOpenChange={setMenuOpen}>
<PopoverTrigger asChild>
<SessionActionsTrigger
label={t('workbench.sessionActions')}
@@ -373,6 +376,7 @@ export const ProjectsPage: React.FC = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { capabilities } = useInstanceAuthorization();
+ const canCreateProject = canCreateLocalProject(capabilities);
const { unreadBySession } = useWorkbenchInbox();
const {
projects,
@@ -407,7 +411,7 @@ export const ProjectsPage: React.FC = () => {
<div className="mx-auto flex max-w-xl flex-col gap-3">
<div className="flex items-center justify-between">
<h1 className="text-xl font-bold">{t('projects.title')}</h1>
- {capabilities.can_manage_projects && <Button
+ {canCreateProject && <Button
type="button"
variant="outline"
size="icon"
@@ -483,6 +487,7 @@ export const ProjectsPage: React.FC = () => {
session={session}
unread={unreadBySession[session.id] ?? 0}
canChat={capabilities.can_chat && project.capabilities.can_chat}
+ canManageMetadata={project.capabilities.can_chat}
onOpen={() => openSession(session.id)}
/>
))}
@@ -503,7 +508,7 @@ export const ProjectsPage: React.FC = () => {
);
})}
- {showNewProject && capabilities.can_manage_projects && (
+ {showNewProject && canCreateProject && (
<NewProjectDialog
onClose={() => setShowNewProject(false)}
onCreated={(project) => {
diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsx
index bd19e45aa..a53ab17f4 100644
--- a/ui/src/components/workbench/WorkbenchSidebar.tsx
+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx
@@ -37,6 +37,7 @@ import { SESSION_ROW_MENU_POSITION_CLASS, sessionRowActionPaddingClass } from '.
import { SessionActionMenuContent, SessionActionsTrigger } from './sessionActions';
import { useSessionActions } from './useSessionActions';
import { formatRelativeTime } from '../../lib/relativeTime';
+import { canCreateLocalProject } from '../../lib/sessionInfo';
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from '../ui/popover';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
@@ -210,7 +211,8 @@ const SessionRow: React.FC<{
session: WorkbenchSession;
unread: number;
canChat: boolean;
-}> = ({ projectId, session, unread, canChat }) => {
+ canManageMetadata: boolean;
+}> = ({ projectId, session, unread, canChat, canManageMetadata }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const { renameSession } = useWorkbenchProjectsTree();
@@ -227,7 +229,8 @@ const SessionRow: React.FC<{
const { actions, archiveDialog } = useSessionActions({
session,
- writable: canChat,
+ writable: canManageMetadata,
+ lifecycleWritable: canChat,
projectId,
onRenameStart: () => {
setDraft(session.title ?? '');
@@ -296,11 +299,11 @@ const SessionRow: React.FC<{
const displayName = session.title?.trim() || t('workbench.untitledSession');
return (
<>
- <Popover open={canChat && menuOpen} onOpenChange={(open) => canChat && setMenuOpen(open)}>
+ <Popover open={canManageMetadata && menuOpen} onOpenChange={(open) => canManageMetadata && setMenuOpen(open)}>
<PopoverAnchor asChild>
<div
onContextMenu={(e) => {
- if (!canChat) return;
+ if (!canManageMetadata) return;
e.preventDefault();
setMenuOpen(true);
}}
@@ -338,7 +341,7 @@ const SessionRow: React.FC<{
</span>
)}
</button>
- {canChat && (
+ {canManageMetadata && (
<>
{pinAction && (
<SessionPinAction
@@ -389,6 +392,7 @@ const ProjectRow: React.FC<{
onCreateSession: () => void;
creatingSession: boolean;
canChat: boolean;
+ canManageMetadata: boolean;
canManageProjects: boolean;
unreadBySession: Record<string, number>;
onRename: (next: string) => Promise<void>;
@@ -405,6 +409,7 @@ const ProjectRow: React.FC<{
onCreateSession,
creatingSession,
canChat,
+ canManageMetadata,
canManageProjects,
unreadBySession,
onRename,
@@ -604,6 +609,7 @@ const ProjectRow: React.FC<{
session={session}
unread={unreadBySession[session.id] || 0}
canChat={canChat}
+ canManageMetadata={canManageMetadata}
/>
))}
{hasMore && (
@@ -643,6 +649,7 @@ export const WorkbenchSidebar: React.FC<{ onOpenSearch?: () => void }> = ({ onOp
const navigate = useNavigate();
const authorizeRouteAction = useUnsavedChangesActionGuard();
const { capabilities } = useInstanceAuthorization();
+ const canCreateProject = canCreateLocalProject(capabilities);
const capabilityNav = CAPABILITY_NAV.filter(({ to }) => {
if (to === '/agents' || to === '/harness') return capabilities.can_manage_agents;
if (to === '/skills') return capabilities.can_use_skills;
@@ -845,7 +852,7 @@ export const WorkbenchSidebar: React.FC<{ onOpenSearch?: () => void }> = ({ onOp
>
<Search className="size-4" />
</Button>}
- <Button
+ {canCreateProject && <Button
type="button"
variant="ghost"
size="icon"
@@ -854,7 +861,7 @@ export const WorkbenchSidebar: React.FC<{ onOpenSearch?: () => void }> = ({ onOp
onClick={() => setShowNewProject(true)}
>
<FolderPlus className="size-4" />
- </Button>
+ </Button>}
</div>
</div>
@@ -902,6 +909,7 @@ export const WorkbenchSidebar: React.FC<{ onOpenSearch?: () => void }> = ({ onOp
}}
creatingSession={creatingSession(project.id)}
canChat={capabilities.can_chat && project.capabilities.can_chat}
+ canManageMetadata={project.capabilities.can_chat}
canManageProjects={capabilities.can_manage_projects}
unreadBySession={unreadBySession}
onRename={(next) => renameProject(project.id, next)}
@@ -912,7 +920,7 @@ export const WorkbenchSidebar: React.FC<{ onOpenSearch?: () => void }> = ({ onOp
</div>
</div>
- {showNewProject && capabilities.can_manage_projects && (
+ {showNewProject && canCreateProject && (
<NewProjectDialog
onClose={() => setShowNewProject(false)}
onCreated={(project) => {
diff --git a/ui/src/components/workbench/useSessionActions.test.tsx b/ui/src/components/workbench/useSessionActions.test.tsx
index 38ac96d40..de8b626f8 100644
--- a/ui/src/components/workbench/useSessionActions.test.tsx
+++ b/ui/src/components/workbench/useSessionActions.test.tsx
@@ -258,3 +258,13 @@ describe('a read-only session', () => {
expect(mount(options()).canArchive).toBe(true);
});
});
+
+describe('a metadata-only session', () => {
+ it('keeps organization actions but removes local lifecycle actions', () => {
+ const h = mount(options({ writable: true, lifecycleWritable: false }));
+
+ expect(h.actions.map((action) => action.id)).toEqual(['pin', 'rename', 'hide']);
+ expect(h.canArchive).toBe(false);
+ expect(h.archiveDialog).toBeNull();
+ });
+});
diff --git a/ui/src/components/workbench/useSessionActions.tsx b/ui/src/components/workbench/useSessionActions.tsx
index 2dac1d0b8..97b9c997d 100644
--- a/ui/src/components/workbench/useSessionActions.tsx
+++ b/ui/src/components/workbench/useSessionActions.tsx
@@ -30,6 +30,8 @@ export interface SessionActionsOptions {
/** Capability gate for otherwise-live sessions. Remote Organization readers
* can inspect a session but must not receive local write actions. */
writable?: boolean;
+ /** Local lifecycle writes such as Fork and Archive; metadata writes remain available remotely. */
+ lifecycleWritable?: boolean;
/** Project whose cached list holds the row — a CACHE address, not a permission.
* Defaults to ``session.project_id``, which is ``null`` for a standalone session
* (no project-bound scope); the writes run either way. */
@@ -65,6 +67,7 @@ export interface SessionActionsHandle {
export const useSessionActions = ({
session,
writable = true,
+ lifecycleWritable = writable,
projectId,
onRenameStart,
onOpenSession,
@@ -204,8 +207,8 @@ export const useSessionActions = ({
onSelect: () => insertTarget?.insertSessionReference(target.id, target.title),
});
}
- rows.push(
- {
+ if (lifecycleWritable) {
+ rows.push({
id: 'fork',
group: 'continue',
icon: GitFork,
@@ -217,15 +220,17 @@ export const useSessionActions = ({
pending: forking,
title: canFork ? undefined : t('workbench.sessionForkUnavailable'),
onSelect: () => void fork(),
- },
- {
- id: 'hide',
- group: 'continue',
- icon: EyeOff,
- label: t('workbench.sessionHideToBackground'),
- onSelect: hide,
- },
- {
+ });
+ }
+ rows.push({
+ id: 'hide',
+ group: 'continue',
+ icon: EyeOff,
+ label: t('workbench.sessionHideToBackground'),
+ onSelect: hide,
+ });
+ if (lifecycleWritable) {
+ rows.push({
id: 'archive',
group: 'lifecycle',
icon: Archive,
@@ -233,8 +238,8 @@ export const useSessionActions = ({
hint: archiveHint,
danger: true,
onSelect: requestArchive,
- },
- );
+ });
+ }
return rows;
}, [
target,
@@ -248,9 +253,10 @@ export const useSessionActions = ({
hide,
requestArchive,
archiveHint,
+ lifecycleWritable,
]);
- const archiveDialog = target ? (
+ const archiveDialog = lifecycleWritable && target ? (
<ArchiveSessionDialog
sessionId={archiveOpen ? archiveRequestId : null}
sessionTitle={target.title}
@@ -263,5 +269,5 @@ export const useSessionActions = ({
/>
) : null;
- return { actions, archiveDialog, requestArchive, canArchive: target != null };
+ return { actions, archiveDialog, requestArchive, canArchive: lifecycleWritable && target != null };
};
diff --git a/ui/src/lib/sessionInfo.test.ts b/ui/src/lib/sessionInfo.test.ts
index b641ffd70..04a9b2cf1 100644
--- a/ui/src/lib/sessionInfo.test.ts
+++ b/ui/src/lib/sessionInfo.test.ts
@@ -1,11 +1,24 @@
import { describe, expect, it } from 'vitest';
import {
+ canCreateLocalProject,
DENIED_INSTANCE_CAPABILITIES,
normalizeSessionInfo,
OWNER_INSTANCE_CAPABILITIES,
} from './sessionInfo';
+describe('canCreateLocalProject', () => {
+ it('requires project management and local file capabilities', () => {
+ expect(canCreateLocalProject(OWNER_INSTANCE_CAPABILITIES)).toBe(true);
+ expect(
+ canCreateLocalProject({
+ ...OWNER_INSTANCE_CAPABILITIES,
+ can_use_files: false,
+ }),
+ ).toBe(false);
+ });
+});
+
describe('normalizeSessionInfo', () => {
it('preserves legacy authenticated remote sessions as owners', () => {
expect(
diff --git a/ui/src/lib/sessionInfo.ts b/ui/src/lib/sessionInfo.ts
index d4ea11617..49341ac93 100644
--- a/ui/src/lib/sessionInfo.ts
+++ b/ui/src/lib/sessionInfo.ts
@@ -48,6 +48,9 @@ export const OWNER_INSTANCE_CAPABILITIES: InstanceCapabilities = Object.fromEntr
Object.keys(DENIED_INSTANCE_CAPABILITIES).map((key) => [key, true]),
) as InstanceCapabilities;
+export const canCreateLocalProject = (capabilities: InstanceCapabilities): boolean =>
+ capabilities.can_manage_projects && capabilities.can_use_files;
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === 'object' && value !== null && !Array.isArray(value);
diff --git a/vibe/authorization.py b/vibe/authorization.py
index 8d17d7525..89ec690b7 100644
--- a/vibe/authorization.py
+++ b/vibe/authorization.py
@@ -432,7 +432,7 @@ _REMOTE_OWNER_ALLOWED_HTTP_RULES = tuple(
),
(
frozenset({"GET", "HEAD"}),
- r"^/api/backend/(?:(?:claude|codex)/auth|[^/]+/auth/oauth/status/[^/]+)$",
+ r"^/api/backend/(?:(?:codex)/auth|[^/]+/auth/oauth/status/[^/]+)$",
),
(
frozenset({"GET", "HEAD"}),