Skip to content
Merged
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
15 changes: 15 additions & 0 deletions apps/mobile/src/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
ThreadListV2SettledShelfHeader,
ThreadListV2ShowMoreRow,
ThreadListV2SnoozedShelfHeader,
ThreadListV2StuckShelfHeader,
ThreadListV2WorkingShelfHeader,
} from "../threads/thread-list-v2-items";
import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
Expand Down Expand Up @@ -386,10 +387,12 @@ export function HomeScreen(props: HomeScreenProps) {
snoozedShelfExpanded,
workingShelfEnabled,
workingShelfExpanded,
stuckShelfExpanded,
expandedPipelineKeys,
toggleSettledShelf,
toggleSnoozedShelf,
toggleWorkingShelf,
toggleStuckShelf,
togglePipelineExpanded,
} = useThreadListV2ShelfPreferences();
const now = useThreadListNow(props.threads);
Expand Down Expand Up @@ -433,6 +436,7 @@ export function HomeScreen(props: HomeScreenProps) {
shelfPreferencesLoaded,
workingShelfEnabled,
workingShelfExpanded,
stuckShelfExpanded,
snoozedShelfExpanded,
settledShelfExpanded,
expandedPipelineKeys,
Expand Down Expand Up @@ -505,6 +509,16 @@ export function HomeScreen(props: HomeScreenProps) {
/>
);
}
if (item.type === "v2-stuck-shelf") {
return (
<ThreadListV2StuckShelfHeader
count={item.count}
disabled={item.disabled}
expanded={item.expanded}
onToggle={toggleStuckShelf}
/>
);
}
if (item.type === "v2-snoozed-shelf") {
return (
<ThreadListV2SnoozedShelfHeader
Expand Down Expand Up @@ -539,6 +553,7 @@ export function HomeScreen(props: HomeScreenProps) {
stepStatus={item.item.stepStatus}
stepLabel={item.item.stepLabel}
suppressUnseenDone={item.item.suppressUnseenDone}
possiblyStuck={item.item.possiblyStuck}
earlierAttempt={item.item.earlierAttempt}
earlierFold={item.item.earlierFold}
attentionTarget={item.item.attentionTarget}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ vi.mock("../../state/preferences", () => ({
updateMobilePreferencesAtom: {},
}));
vi.mock("./components/AutoSettleDaysField", () => ({ AutoSettleDaysField: () => null }));
vi.mock("./components/PossiblyStuckHoursField", () => ({ PossiblyStuckHoursField: () => null }));
vi.mock("./components/SourceControlSignInSection", () => ({
SourceControlSignInSection: () => null,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const AUTO_SETTLE_SETTING_KEYS: ReadonlySet<string> = new Set([
"sidebarAutoSettleAfterDays",
"autoResumeLimitedThreads",
"snoozeLimitedThreads",
"possiblyStuckAfterHours",
]);

function planServerSettingsWrites(
Expand Down
26 changes: 25 additions & 1 deletion apps/mobile/src/features/settings/ThreadSettingsSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
} from "@t3tools/contracts";
import { useEnvironmentsWithScope } from "../../state/session";
import { AutoSettleDaysField } from "./components/AutoSettleDaysField";
import { PossiblyStuckHoursField } from "./components/PossiblyStuckHoursField";
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
import { useAtomSet, useAtomValue } from "@effect/atom-react";
import { AsyncResult } from "effect/reactivity";
import type { ComponentProps } from "react";
import { View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";

import { DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts";
import { DEFAULT_POSSIBLY_STUCK_AFTER_HOURS, DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts";
import { supportsSharedSettingsSync } from "@t3tools/client-runtime/state/shared-settings";
import { AppText as Text } from "../../components/ui/AppText";
import { useEnvironments } from "../../state/environments";
Expand Down Expand Up @@ -101,6 +102,7 @@ export function AutoSettleSettingsRows(props: {
patch: Partial<AutoSettleSettings> & {
autoResumeLimitedThreads?: boolean;
snoozeLimitedThreads?: boolean;
possiblyStuckAfterHours?: number;
},
) => props.write(patch);

Expand Down Expand Up @@ -145,6 +147,28 @@ export function AutoSettleSettingsRows(props: {
/>
</SettingsSection>
) : null}
{!projectSelected ? (
<SettingsSection title="Possibly stuck">
<View className="flex-row items-center gap-4 px-4 py-4 android:min-h-14 android:py-3">
<View className="flex-1 gap-1">
<Text className="text-foreground text-lg android:text-base">
Mark threads as possibly stuck after
</Text>
<Text className="text-sm text-foreground-muted">
A thread whose last turn ended while background work kept running this long is
listed under Possibly stuck. Pull request watches never count. 0 turns it off.
</Text>
</View>
<PossiblyStuckHoursField
value={
referenceSettings.possiblyStuckAfterHours ?? DEFAULT_POSSIBLY_STUCK_AFTER_HOURS
}
disabled={disabledFor("possiblyStuckAfterHours")}
onValueChange={(value) => writeToAll({ possiblyStuckAfterHours: value })}
/>
</View>
</SettingsSection>
) : null}
<SettingsSection title="Auto-settle">
<SettingsSwitchRow
icon="arrow.triangle.branch"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MAX_POSSIBLY_STUCK_AFTER_HOURS } from "@t3tools/contracts";
import type { ComponentProps } from "react";
import { NumberField } from "../../../components/ui/NumberField";

export type PossiblyStuckHoursFieldProps = Pick<
ComponentProps<typeof NumberField>,
"value" | "onValueChange" | "disabled"
>;

export function PossiblyStuckHoursField(props: PossiblyStuckHoursFieldProps) {
return (
<NumberField
{...props}
min={0}
max={MAX_POSSIBLY_STUCK_AFTER_HOURS}
label="Hours before a thread is marked possibly stuck"
formatValue={(value) => (value === 0 ? "Off" : `${value} ${value === 1 ? "hour" : "hours"}`)}
/>
);
}
67 changes: 48 additions & 19 deletions apps/mobile/src/features/threads/PipelineRunPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ import {
pipelineStepAwaitsHandoff,
pipelineStepPosition,
pipelineStepStatusLabel,
pipelineStepWaitLabel,
stepName,
threadWatchesPullRequest,
} from "@t3tools/client-runtime/pipeline-run-presentation";
import { pipelineRunStepShells } from "@t3tools/client-runtime/state/pipeline-nesting";
import {
pipelineRunStepShells,
possiblyStuckClock,
threadBackgroundWait,
type PipelineStepWait,
} from "@t3tools/client-runtime/state/pipeline-nesting";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
Expand All @@ -38,6 +43,8 @@ import { Button } from "../../components/ui/Button";
import * as Dialog from "../../components/ui/Dialog";
import { ThemedSwitch } from "../../components/ui/ThemedSwitch";
import { formatMessageTime } from "../../lib/time";
import { useNowMinuteMs } from "../../lib/clock";
import { environmentPresentations } from "../../state/presentation";
import { useQuietThreadShell, useQuietThreadShells } from "../../state/entities";
import { resolveThreadListV2Status, threadHasUnseenCompletion } from "./threadListV2";
import { useEnvironmentQuery } from "../../state/query";
Expand Down Expand Up @@ -73,25 +80,32 @@ function reportFailure(title: string, result: AtomCommandResult<unknown, unknown
}
}

function useRunWaitingOnPullRequest(
environmentId: EnvironmentId,
run: PipelineRun | null,
): boolean {
/** What the current step's thread waits on after ending its turn without a handoff, and the stuck threshold. */
function useStepWait(environmentId: EnvironmentId, run: PipelineRun | null) {
const childThreadId = pipelineAwaitingHandoffThreadId(run);
const shell = useQuietThreadShell(
childThreadId === null ? null : { environmentId, threadId: childThreadId },
);
return threadWatchesPullRequest(shell);
const config = useAtomValue(environmentPresentations.serverConfigsAtom).get(environmentId);
const nowMs = useNowMinuteMs();
const clock = possiblyStuckClock(config?.settings, nowMs);
return {
wait: threadBackgroundWait(shell, clock),
waitOf: (step: Parameters<typeof threadBackgroundWait>[0]) => threadBackgroundWait(step, clock),
afterHours: clock?.afterHours,
};
}

function runTone(run: PipelineRun, waitingOnPullRequest: boolean): StatusTone {
function runTone(run: PipelineRun, wait: PipelineStepWait | null): StatusTone {
switch (run.status) {
case "running":
return { label: "Running", ...STEP_TONES.active };
case "paused":
if (!pipelineRunNeedsAttention(run, waitingOnPullRequest)) {
if (!pipelineRunNeedsAttention(run, wait)) {
return { label: "Waiting", ...STEP_TONES.active };
}
if (wait === "possibly_stuck")
return { label: pipelineStepWaitLabel(wait), ...ATTENTION_TONE };
return {
label: run.pauseReason === "awaiting_continue" ? "Paused" : "Needs attention",
...ATTENTION_TONE,
Expand Down Expand Up @@ -155,9 +169,9 @@ export function PipelineRunSummaryHeader(props: {
}),
);
const run = runQuery.data?.run ?? null;
const waitingOnPullRequest = useRunWaitingOnPullRequest(props.environmentId, run);
const { wait } = useStepWait(props.environmentId, run);
if (run === null) return <View style={{ paddingTop: props.topInset }} />;
const tone = runTone(run, waitingOnPullRequest);
const tone = runTone(run, wait);
const stepIndex = Math.min(run.currentStepIndex, run.steps.length - 1);
return (
<View
Expand Down Expand Up @@ -195,7 +209,7 @@ export function PipelineRunPanel(props: {
serverEnvironment.pipelineRunLive({ environmentId, input: { runId: props.runId } }),
);
const run = runQuery.data?.run ?? null;
const waitingOnPullRequest = useRunWaitingOnPullRequest(environmentId, run);
const { wait, waitOf, afterHours } = useStepWait(environmentId, run);
const [expanded, setExpanded] = useState(false);
const [promptExpanded, setPromptExpanded] = useState(false);
const [previewFile, setPreviewFile] = useState<FilePreviewSource | null>(null);
Expand Down Expand Up @@ -296,7 +310,7 @@ export function PipelineRunPanel(props: {

const actions = availablePipelineActions(run);
const stepIndex = run.currentStepIndex;
const tone = runTone(run, waitingOnPullRequest);
const tone = runTone(run, wait);
const stepInput = { runId: run.id, stepIndex };
const startingText = composerContextProse(run.input);
// Image and file chips only bind the attachments listed above them.
Expand All @@ -309,6 +323,8 @@ export function PipelineRunPanel(props: {
run,
pipelineRunStepShells(shells, environmentId, run.id),
resolveThreadListV2Status,
waitOf,
afterHours,
);
const needsYouThreadId = needsYou?.threadId ?? null;

Expand Down Expand Up @@ -339,8 +355,7 @@ export function PipelineRunPanel(props: {
</View>
</View>
<Text textRole="footnote" className="text-foreground-secondary" numberOfLines={1}>
{runProgressLabel(run)} · {currentStepName} ·{" "}
{pipelineRunStateLabel(run, waitingOnPullRequest)}
{runProgressLabel(run)} · {currentStepName} · {pipelineRunStateLabel(run, wait)}
</Text>
</Pressable>
{needsYou !== null ? (
Expand Down Expand Up @@ -506,6 +521,7 @@ export function PipelineRunPanel(props: {
environmentId={environmentId}
run={run}
step={step}
wait={step.index === stepIndex ? wait : null}
current={step.index === stepIndex && run.status !== "completed"}
needsYou={needsYou?.threadId != null && needsYou.stepIndex === step.index}
pauseBeforeEditable={
Expand Down Expand Up @@ -544,6 +560,8 @@ function PipelineStepRow(props: {
readonly environmentId: EnvironmentId;
readonly run: PipelineRun;
readonly step: PipelineRun["steps"][number];
/** What the step's thread waits on after ending its turn without a handoff. */
readonly wait: PipelineStepWait | null;
readonly current: boolean;
/** The step the run's "needs you" line points at. */
readonly needsYou: boolean;
Expand All @@ -563,11 +581,22 @@ function PipelineStepRow(props: {
const childShell = useQuietThreadShell(
childThreadId === null ? null : { environmentId: props.environmentId, threadId: childThreadId },
);
const tone = props.needsYou ? ATTENTION_TONE : STEP_TONES[pipelineStepTone(step.status)];
// A wake turn runs the step again, so it reads as running whatever work is still pending.
const awaitsHandoff =
step.status === "running" &&
pipelineStepAwaitsHandoff(run, step.index) &&
childShell?.runtime?.activeRunId == null;
const tone = props.needsYou
? ATTENTION_TONE
: awaitsHandoff && props.wait !== null
? STEP_TONES.muted
: STEP_TONES[pipelineStepTone(step.status)];
const statusLabel =
props.needsYou && step.status === "running" && pipelineStepAwaitsHandoff(run, step.index)
? "No handoff"
: pipelineStepStatusLabel(step);
awaitsHandoff && props.wait !== null
? pipelineStepWaitLabel(props.wait)
: props.needsYou && awaitsHandoff
? "No handoff"
: pipelineStepStatusLabel(step);
const revisions = stepRevisions(run, step.index);
const needsInput = childShell?.runtime?.status === "waiting";
const details = [
Expand Down
15 changes: 15 additions & 0 deletions apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
ThreadListV2SettledShelfHeader,
ThreadListV2ShowMoreRow,
ThreadListV2SnoozedShelfHeader,
ThreadListV2StuckShelfHeader,
ThreadListV2WorkingShelfHeader,
} from "./thread-list-v2-items";
import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
Expand Down Expand Up @@ -245,10 +246,12 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
snoozedShelfExpanded,
workingShelfEnabled,
workingShelfExpanded,
stuckShelfExpanded,
expandedPipelineKeys,
toggleSettledShelf,
toggleSnoozedShelf,
toggleWorkingShelf,
toggleStuckShelf,
togglePipelineExpanded,
} = useThreadListV2ShelfPreferences();
const now = useThreadListNow(threads);
Expand Down Expand Up @@ -292,6 +295,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
shelfPreferencesLoaded,
workingShelfEnabled,
workingShelfExpanded,
stuckShelfExpanded,
snoozedShelfExpanded,
settledShelfExpanded,
expandedPipelineKeys,
Expand Down Expand Up @@ -425,6 +429,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
stepStatus={item.item.stepStatus}
stepLabel={item.item.stepLabel}
suppressUnseenDone={item.item.suppressUnseenDone}
possiblyStuck={item.item.possiblyStuck}
earlierAttempt={item.item.earlierAttempt}
earlierFold={item.item.earlierFold}
attentionTarget={item.item.attentionTarget}
Expand Down Expand Up @@ -511,6 +516,16 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
pane="sidebar"
/>
);
case "v2-stuck-shelf":
return (
<ThreadListV2StuckShelfHeader
count={item.count}
disabled={item.disabled}
expanded={item.expanded}
onToggle={toggleStuckShelf}
pane="sidebar"
/>
);
case "v2-snoozed-shelf":
return (
<ThreadListV2SnoozedShelfHeader
Expand Down
Loading
Loading