Skip to content
3 changes: 3 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23950,6 +23950,9 @@ components:
- 'null'
format: date-time
description: When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.
canTryAgain:
type: boolean
description: Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.
workingSince:
type:
- string
Expand Down
3 changes: 3 additions & 0 deletions api/openapi/conversations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,9 @@ components:
- 'null'
format: date-time
description: When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.
canTryAgain:
type: boolean
description: Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.
workingSince:
type:
- string
Expand Down
33 changes: 27 additions & 6 deletions app/src/components/tasks/task-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import {
tryTaskAgainMutationOptions,
} from "@/lib/tasks/mutations";
import {
canTryAgain,
couldNotFinish,
failureSentence,
stoppedByYou,
TASK_DONE_LABEL,
TASK_FAILED_LABEL,
TASK_STATUS_LABEL,
TASK_STOPPED,
TASK_STOPPED_LABEL,
Expand Down Expand Up @@ -112,6 +115,23 @@ function nextLine(listed: ListedTask): string | null {
return status === "working" ? "Just started." : null;
}

/**
* A task's status and line on the Needs you board. One that couldn't finish says so in its card's
* words, Couldn't finish, and its line is why, said once: the board read "Failed" beside a card
* that said "Couldn't finish", and "Couldn't finish: …" beside "Failed".
*/
function boardStatus(
listed: ListedTask,
settled = false,
): { label: string; line: string | null } {
if (listed.status === "failed" && !stopped(listed))
return {
label: TASK_FAILED_LABEL,
line: listed.task.failure ? failureSentence(listed.task.failure) : null,
};
return { label: statusLabel(listed, settled), line: nextLine(listed) };
}

/**
* Whether a row offers Mark done: only where it does something. Not while the task is working:
* there is nothing finished to mark, and its conversation would carry on behind a row that said it
Expand Down Expand Up @@ -210,7 +230,7 @@ export function TaskRow({
</ItemDescription>
) : null}
<ItemFooter className="mt-2 flex-wrap justify-start">
{status === "failed" ? (
{canTryAgain({ ...task, status }) ? (
<Button
disabled={busy}
onClick={() => again.mutate(task.id)}
Expand Down Expand Up @@ -290,6 +310,7 @@ export function TaskBoardRow({
const settled = !countsAsWaiting(listed) && status === "ready_for_review";
const openFirst =
!settled && (status === "ready_for_review" || status === "needs_input");
const said = boardStatus(listed, settled);
if (held)
return (
<BoardRow
Expand Down Expand Up @@ -318,10 +339,10 @@ export function TaskBoardRow({
</Button>
</>
}
detail={nextLine(listed)}
detail={said.line}
icon={<Icon />}
meta={[
<span key="status">{statusLabel(listed)}</span>,
<span key="status">{boardStatus(listed).label}</span>,
<span key="when">{relativeTime(task.updatedAt)}</span>,
...held.meta,
]}
Expand All @@ -336,7 +357,7 @@ export function TaskBoardRow({
<BoardRow
actions={
<>
{status === "failed" ? (
{canTryAgain({ ...task, status }) ? (
<Button
disabled={busy}
onClick={() => again.mutate(task.id)}
Expand Down Expand Up @@ -369,12 +390,12 @@ export function TaskBoardRow({
</Button>
</>
}
detail={nextLine(listed)}
detail={said.line}
// What a waiting task waits for is what the person has to answer: read in full, never cut.
readDetail={status === "needs_input"}
icon={<Icon />}
meta={[
<span key="status">{statusLabel(listed, settled)}</span>,
<span key="status">{said.label}</span>,
<span key="when">{relativeTime(task.updatedAt)}</span>,
error ? (
<span className="text-destructive" key="error" role="alert">
Expand Down
67 changes: 47 additions & 20 deletions app/src/components/tasks/task-thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
reactionsQueryOptions,
stoppedByYou,
TASK_DONE_LABEL,
TASK_FAILED_LABEL,
TASK_STOPPED,
TASK_STOPPED_LABEL,
type TaskStatus,
Expand Down Expand Up @@ -85,7 +86,7 @@ const STATE: Record<
text: "text-emerald-700 dark:text-emerald-400",
},
failed: {
label: "Couldn't finish",
label: TASK_FAILED_LABEL,
icon: IconAlertTriangle,
dot: "bg-destructive",
text: "text-destructive",
Expand Down Expand Up @@ -276,18 +277,16 @@ export function TaskCard({
);
/*
* What it waits for is said once, on the needs-you line the task posts, not here as well: the
* card says only that it needs the person, and leads into the thread.
* card says only that it needs the person, and leads into the thread. Why it couldn't finish is
* said once too, on the line it reports under the card, which also says what to do about it: the
* card said the same reason a second time just above it.
*/
const next =
state === "failed"
? task.data?.failure
? failureSentence(task.data.failure)
: null
: state === "stopped"
? TASK_STOPPED
: state === "working" && !taskId
? "Starting…"
: null;
state === "stopped"
? TASK_STOPPED
: state === "working" && !taskId
? "Starting…"
: null;
return (
<TaskFrame
below={children}
Expand Down Expand Up @@ -408,7 +407,21 @@ export function TaskReport({
* it) is not finished: its link reads as needing them, as the task's card does, not as done.
*/
const waiting = live === "needs";
const ResultIcon = waiting ? IconHandStop : IconCircleCheck;
/*
* A result whose task then couldn't finish (an admin dismissed the Request access it waited on)
* has no failed line under it, and the card says only that it couldn't finish: why is said here,
* once, and the link doesn't read as done.
*/
const failedSince = live === "failed";
const reason =
failedSince && task.data?.failure
? failureSentence(task.data.failure)
: null;
const ResultIcon = waiting
? IconHandStop
: failedSince
? IconAlertTriangle
: IconCircleCheck;
return (
<div
className="w-full space-y-2"
Expand All @@ -422,7 +435,7 @@ export function TaskReport({
{channelId ? (
<Link
className="inline-flex max-w-full items-center gap-1.5 rounded-md bg-muted px-2 py-1 text-muted-foreground text-xs transition-colors hover:bg-muted/70 hover:text-foreground"
data-state={waiting ? "needs" : "done"}
data-state={waiting ? "needs" : failedSince ? "failed" : "done"}
params={{ channelId }}
to="/channel/$channelId"
>
Expand All @@ -431,13 +444,23 @@ export function TaskReport({
"size-3.5 shrink-0",
waiting
? STATE.needs.text
: "text-emerald-600 dark:text-emerald-400",
: failedSince
? STATE.failed.text
: "text-emerald-600 dark:text-emerald-400",
)}
/>
<span className="truncate">{title ?? "Task"}</span>
<IconArrowUpRight className="size-3.5 shrink-0" />
</Link>
) : null}
{reason ? (
<p className="text-sm">
<span className={cn("font-medium text-xs", STATE.failed.text)}>
{TASK_FAILED_LABEL}
</span>
<span className="text-muted-foreground"> · {reason}</span>
</p>
) : null}
{children}
</div>
);
Expand Down Expand Up @@ -515,13 +538,17 @@ export function TaskReport({
);
}

/** What a needs-you line says once the person has answered, by where the task is now. */
/**
* What a needs-you line says once the person has answered, by where the task is now. Never where
* they answered: the thread, the Bots page's Needs you board and the inbox all answer it, and the
* line can't tell which.
*/
const ANSWERED: Record<CardState, string> = {
working: "You answered this in its thread. It's carrying on.",
needs: "You answered this in its thread. It needs you again there.",
done: "You answered this in its thread, and it's done.",
failed: "You answered this in its thread, but it couldn't finish.",
stopped: "You answered this in its thread, and stopped it after.",
working: "You answered this. It's carrying on.",
needs: "You answered this. It needs you again in its thread.",
done: "You answered this, and it's done.",
failed: "You answered this, but it couldn't finish.",
stopped: "You answered this, and stopped it after.",
};

/**
Expand Down
2 changes: 2 additions & 0 deletions app/src/lib/api/generated/model/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface Task {
* @nullable
*/
stoppedAt?: string | null;
/** Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true. */
canTryAgain?: boolean;
/**
* When the work it is doing now began. Null or absent unless it is working.
* @nullable
Expand Down
30 changes: 30 additions & 0 deletions app/src/lib/api/generated/tasks/tasks.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export const ListTasksResponse = zod.object({
.describe(
"When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.",
),
canTryAgain: zod
.boolean()
.optional()
.describe(
"Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.",
),
workingSince: zod.iso
.datetime({ offset: true })
.nullish()
Expand Down Expand Up @@ -265,6 +271,12 @@ export const GetTaskResponse = zod.object({
.describe(
"When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.",
),
canTryAgain: zod
.boolean()
.optional()
.describe(
"Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.",
),
workingSince: zod.iso
.datetime({ offset: true })
.nullish()
Expand Down Expand Up @@ -422,6 +434,12 @@ export const ResolveTaskResponse = zod.object({
.describe(
"When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.",
),
canTryAgain: zod
.boolean()
.optional()
.describe(
"Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.",
),
workingSince: zod.iso
.datetime({ offset: true })
.nullish()
Expand Down Expand Up @@ -579,6 +597,12 @@ export const ReopenTaskResponse = zod.object({
.describe(
"When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.",
),
canTryAgain: zod
.boolean()
.optional()
.describe(
"Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.",
),
workingSince: zod.iso
.datetime({ offset: true })
.nullish()
Expand Down Expand Up @@ -736,6 +760,12 @@ export const RetryTaskResponse = zod.object({
.describe(
"When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.",
),
canTryAgain: zod
.boolean()
.optional()
.describe(
"Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.",
),
workingSince: zod.iso
.datetime({ offset: true })
.nullish()
Expand Down
11 changes: 10 additions & 1 deletion app/src/lib/approvals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,16 @@ export const decideApprovalMutationOptions = (queryClient: QueryClient) =>
mutationOptions({
mutationFn: ({ id, choice }: { id: string; choice: ApprovalDecision }) =>
decideApproval(id, choice),
onSuccess: settle(queryClient),
/*
* The badge that counted it is read again at once, as for an answered question: left to its
* poll, it kept the old count for seconds beside a board that already showed the new one.
*/
onSuccess: () => {
void queryClient.invalidateQueries({
queryKey: botLifecycleKeys.attention,
});
return settle(queryClient)();
},
});
/** Answer a question a Bot asked mid-run; the run resumes with the answer. */
export const answerPersonQuestionMutationOptions = (queryClient: QueryClient) =>
Expand Down
29 changes: 26 additions & 3 deletions app/src/lib/tasks/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export type BotTask = {
* Stopped. Null once it carries on.
*/
stoppedAt?: string | null;
/**
* False when trying it again can't change how it ends: it couldn't finish for a reason asking
* again gets the same answer to (a Bot it asked isn't shared with the person). Absent from a
* server that does not say, which reads as true.
*/
canTryAgain?: boolean;
/** One line on what comes next, from the last thing said in its conversation. */
next: string | null;
/** When the work it is doing now began, for how long it has been working. Null unless working. */
Expand Down Expand Up @@ -204,9 +210,15 @@ export function couldNotFinish(failure: string | null): string {
}

/**
* Why a task couldn't finish, as a line of its own under its status: a sentence. The server words
* its reason to follow "Couldn't finish:" ("this Bot isn't shared with you any more"), so on its
* own it starts in capitals and ends with a full stop.
* A task that couldn't finish, in a word or two: what its card in the conversation says, and its
* row on the Needs you board, so the two never name one state twice.
*/
export const TASK_FAILED_LABEL = "Couldn't finish";

/**
* Why a task couldn't finish, as a line of its own after a status that already says so: a
* sentence. The server words its reason to follow "Couldn't finish:" ("Pipeline Bot isn't shared
* with you"), so on its own it starts in capitals and ends with a full stop.
*/
export function failureSentence(failure: string): string {
const said = failure.trim();
Expand All @@ -215,6 +227,17 @@ export function failureSentence(failure: string): string {
return /[.!?]$/.test(sentence) ? sentence : `${sentence}.`;
}

/**
* Whether Try again is offered: only on a task that couldn't finish, and not on one the server says
* asking again can't change, which would only be refused the same way again.
*/
export function canTryAgain(task: {
status: TaskStatus;
canTryAgain?: boolean;
}): boolean {
return task.status === "failed" && task.canTryAgain !== false;
}

/**
* Whether the person stopped this task. Its status is `failed` either way, and only a stop sets
* `stoppedAt`. A stop is the person's own choice, so nothing that lists the task calls it a failure.
Expand Down
Loading
Loading