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
3 changes: 3 additions & 0 deletions apps/mobile/src/app/task/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ export default function NewTaskScreen() {
repository: selection.repository,
githubIntegrationId: selection.integrationId,
composerIsEmpty: !hasContent,
runtimeAdapter: "claude",
model,
reasoningEffort: showReasoningPill ? reasoning : null,
});

if (isLoading && hasGithubIntegration === null) {
Expand Down
6 changes: 6 additions & 0 deletions apps/mobile/src/features/tasks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ export async function warmTask(options: {
repository: string;
github_integration: number;
branch?: string | null;
runtime_adapter?: string | null;
model?: string | null;
reasoning_effort?: string | null;
}): Promise<{ task_id: string; run_id: string } | null> {
const baseUrl = getBaseUrl();
const projectId = getProjectId();
Expand All @@ -318,6 +321,9 @@ export async function warmTask(options: {
repository: options.repository,
github_integration: options.github_integration,
branch: options.branch ?? null,
runtime_adapter: options.runtime_adapter ?? null,
model: options.model ?? null,
reasoning_effort: options.reasoning_effort ?? null,
}),
},
);
Expand Down
37 changes: 37 additions & 0 deletions apps/mobile/src/features/tasks/api.warm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ describe("warmTask", () => {
repository: "posthog/posthog",
github_integration: 7,
branch: "main",
runtime_adapter: null,
model: null,
reasoning_effort: null,
}),
}),
);
});

it("forwards the selected runtime, model, and reasoning effort", async () => {
mockFetch.mockResolvedValueOnce(
new Response(JSON.stringify({ task_id: "task-1", run_id: "run-1" }), {
status: 200,
}),
);

await warmTask({
repository: "posthog/posthog",
github_integration: 7,
branch: "main",
runtime_adapter: "claude",
model: "claude-opus-4-8",
reasoning_effort: "high",
});

expect(mockFetch).toHaveBeenCalledWith(
"https://app.posthog.test/api/projects/42/tasks/warm/",
expect.objectContaining({
body: JSON.stringify({
repository: "posthog/posthog",
github_integration: 7,
branch: "main",
runtime_adapter: "claude",
model: "claude-opus-4-8",
reasoning_effort: "high",
}),
}),
);
Expand All @@ -72,6 +106,9 @@ describe("warmTask", () => {
repository: "posthog/posthog",
github_integration: 7,
branch: null,
runtime_adapter: null,
model: null,
reasoning_effort: null,
}),
}),
);
Expand Down
60 changes: 46 additions & 14 deletions apps/mobile/src/features/tasks/hooks/useWarmTask.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ interface Props {
githubIntegrationId?: number | null;
branch?: string | null;
composerIsEmpty: boolean;
runtimeAdapter?: string | null;
model?: string | null;
reasoningEffort?: string | null;
}

const composing: Props = {
Expand All @@ -38,6 +41,12 @@ const composing: Props = {
composerIsEmpty: false,
};

const NULL_RUNTIME = {
runtime_adapter: null,
model: null,
reasoning_effort: null,
};

function render(initial: Props) {
let current = initial;
function Wrapper() {
Expand Down Expand Up @@ -87,6 +96,7 @@ describe("useWarmTask", () => {
repository: "acme/repo",
github_integration: 42,
branch: "main",
...NULL_RUNTIME,
});
});

Expand Down Expand Up @@ -131,37 +141,59 @@ describe("useWarmTask", () => {

it.each<{
name: string;
initial?: Partial<Props>;
change: Partial<Props>;
expectedRepository: string;
expectedBranch: string;
expected: Record<string, unknown>;
}>([
{
name: "repository",
change: { repository: "acme/other" },
expectedRepository: "acme/other",
expectedBranch: "main",
expected: {
repository: "acme/other",
github_integration: 42,
branch: "main",
...NULL_RUNTIME,
},
},
{
name: "branch",
change: { branch: "feature/x" },
expectedRepository: "acme/repo",
expectedBranch: "feature/x",
expected: {
repository: "acme/repo",
github_integration: 42,
branch: "feature/x",
...NULL_RUNTIME,
},
},
{
name: "model",
initial: {
runtimeAdapter: "claude",
model: "claude-opus-4-8",
reasoningEffort: "high",
},
change: { model: "claude-sonnet-4-6" },
expected: {
repository: "acme/repo",
github_integration: 42,
branch: "main",
runtime_adapter: "claude",
model: "claude-sonnet-4-6",
reasoning_effort: "high",
},
},
])(
"warms the new selection when the $name changes",
async ({ change, expectedRepository, expectedBranch }) => {
const { rerender } = render(composing);
async ({ initial, change, expected }) => {
const base = { ...composing, ...initial };
const { rerender } = render(base);
await flushDebounce();
expect(mockWarmTask).toHaveBeenCalledOnce();

rerender({ ...composing, ...change });
rerender({ ...base, ...change });
await flushDebounce();

expect(mockWarmTask).toHaveBeenLastCalledWith({
repository: expectedRepository,
github_integration: 42,
branch: expectedBranch,
});
expect(mockWarmTask).toHaveBeenLastCalledWith(expected);
expect(mockWarmTask).toHaveBeenCalledTimes(2);
},
);
Expand Down
28 changes: 26 additions & 2 deletions apps/mobile/src/features/tasks/hooks/useWarmTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,37 @@ interface UseWarmTaskOptions {
githubIntegrationId?: number | null;
branch?: string | null;
composerIsEmpty: boolean;
runtimeAdapter?: string | null;
model?: string | null;
reasoningEffort?: string | null;
}

export function useWarmTask({
repository,
githubIntegrationId,
branch,
composerIsEmpty,
runtimeAdapter,
model,
reasoningEffort,
}: UseWarmTaskOptions): void {
const enabled = useFeatureFlag(TASKS_PREWARM_SANDBOX_FLAG);

const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const lastWarmedKeyRef = useRef<string | null>(null);

const normalizedBranch = branch ?? null;
const normalizedRuntimeAdapter = runtimeAdapter ?? null;
const normalizedModel = model ?? null;
const normalizedReasoningEffort = reasoningEffort ?? null;
const eligible =
!!enabled &&
!!repository &&
githubIntegrationId != null &&
!composerIsEmpty;
const key =
repository && githubIntegrationId != null
? `${githubIntegrationId}:${repository}:${normalizedBranch ?? ""}`
? `${githubIntegrationId}:${repository}:${normalizedBranch ?? ""}:${normalizedRuntimeAdapter ?? ""}:${normalizedModel ?? ""}:${normalizedReasoningEffort ?? ""}`
: null;

useEffect(() => {
Expand All @@ -56,19 +65,34 @@ export function useWarmTask({
const repo = repository;
const githubIntegration = githubIntegrationId;
const warmBranch = normalizedBranch;
const warmRuntimeAdapter = normalizedRuntimeAdapter;
const warmModel = normalizedModel;
const warmReasoningEffort = normalizedReasoningEffort;
debounceRef.current = setTimeout(() => {
debounceRef.current = null;
lastWarmedKeyRef.current = key;
void warmTask({
repository: repo,
github_integration: githubIntegration,
branch: warmBranch,
runtime_adapter: warmRuntimeAdapter,
model: warmModel,
reasoning_effort: warmReasoningEffort,
}).catch((error) => {
lastWarmedKeyRef.current = null;
log.warn("Failed to warm task", error);
});
}, WARM_DEBOUNCE_MS);

return clearDebounce;
}, [eligible, key, repository, githubIntegrationId, normalizedBranch]);
}, [
eligible,
key,
repository,
githubIntegrationId,
normalizedBranch,
normalizedRuntimeAdapter,
normalizedModel,
normalizedReasoningEffort,
]);
}
Loading