Skip to content
Open
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
8 changes: 6 additions & 2 deletions agentex-ui/components/agentex-ui-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ export function AgentexUIRoot() {
// than bouncing a possibly-valid deep link to the home grid.
const couldNotDetermine = !agentInList && isAgentByNameError;

if (agentName && !isAgentValid && !couldNotDetermine) {
// Only validate/clear on the home surface. With a task open its agent wins (hydrated in
// ChatView) even if non-Ready, so this doesn't ping-pong against that restore.
if (agentName && !taskID && !isAgentValid && !couldNotDetermine) {
updateParams({ [SearchParamKey.AGENT_NAME]: null });
setLocalAgentName(undefined);
}

if (!agentName && localAgentName) {
// With a task open, its agent wins (hydrated in ChatView) — don't restore from storage.
if (!agentName && !taskID && localAgentName) {
updateParams({ [SearchParamKey.AGENT_NAME]: localAgentName });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
sgpAccountID,
taskID,
isAgentsFetching,
isAgentByNameFetching,
isAgentByNameError,
Expand Down
37 changes: 35 additions & 2 deletions agentex-ui/components/primary-content/chat-view.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useRef } from 'react';
import { useCallback, useEffect, useRef } from 'react';

import { APIError } from 'agentex';
import { motion } from 'framer-motion';

import { TaskProvider, useAgentexClient } from '@/components/providers';
Expand All @@ -9,6 +10,7 @@ import {
SearchParamKey,
useSafeSearchParams,
} from '@/hooks/use-safe-search-params';
import { useTask } from '@/hooks/use-tasks';

import { TaskHeader } from '../task-header/task-header';

Expand All @@ -29,10 +31,41 @@ export function ChatView({
}: ChatViewProps) {
const { agentexClient } = useAgentexClient();
const { data: agents = [] } = useAgents(agentexClient);
const { updateParams } = useSafeSearchParams();
const { agentName, updateParams } = useSafeSearchParams();
const {
data: task,
isError: isTaskError,
error: taskError,
} = useTask({ agentexClient, taskId: taskID });

const headerRef = useRef<HTMLDivElement>(null);

// Deep links may carry only task_id — fill the agent pill from the task's own agent.
const taskAgentName = task?.agents?.[0]?.name;
useEffect(() => {
if (agentName || !taskAgentName) return;
updateParams({ [SearchParamKey.AGENT_NAME]: taskAgentName }, true);
}, [agentName, taskAgentName, updateParams]);
Comment thread
greptile-apps[bot] marked this conversation as resolved.

// Drop a task_id the client can't use: a 4xx means it's bad/off-limits (400/403/404/422).
// 401 is handled by the session refresh + login redirect, and 429/5xx are transient.
useEffect(() => {
const status = taskError instanceof APIError ? taskError.status : undefined;
if (
isTaskError &&
status !== undefined &&
status >= 400 &&
status < 500 &&
status !== 401 &&
status !== 429
) {
updateParams(
{ [SearchParamKey.TASK_ID]: null, [SearchParamKey.AGENT_NAME]: null },
true
);
}
}, [isTaskError, taskError, updateParams]);

const handleSelectAgent = useCallback(
(agentName: string | undefined) => {
updateParams({
Expand Down
9 changes: 9 additions & 0 deletions agentex-ui/hooks/use-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
import { APIError } from 'agentex';

import type AgentexSDK from 'agentex';
import type {
Expand Down Expand Up @@ -42,6 +43,14 @@ export function useTask({
});
},
enabled: !!taskId,
// A 4xx (bad/forbidden task_id) is definitive — fail fast so a deep-link denial clears on
// the first response instead of after retry backoff. Still retry transient 5xx/network.
retry: (failureCount, error) =>
!(
error instanceof APIError &&
error.status >= 400 &&
error.status < 500
) && failureCount < 3,
});
}

Expand Down
Loading