This commit is contained in:
Nathan Flurry 2026-03-14 23:47:43 -07:00 committed by GitHub
parent 99abb9d42e
commit 57a07f6a0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 206 additions and 113 deletions

View file

@ -37,6 +37,11 @@ export const taskRuntime = sqliteTable(
(table) => [check("task_runtime_singleton_id_check", sql`${table.id} = 1`)],
);
/**
* Coordinator index of SandboxInstanceActor instances.
* Tracks all sandbox instances provisioned for this task. Only one
* is active at a time (referenced by taskRuntime.activeSandboxId).
*/
export const taskSandboxes = sqliteTable("task_sandboxes", {
sandboxId: text("sandbox_id").notNull().primaryKey(),
sandboxProviderId: text("sandbox_provider_id").notNull(),
@ -48,6 +53,12 @@ export const taskSandboxes = sqliteTable("task_sandboxes", {
updatedAt: integer("updated_at").notNull(),
});
/**
* Coordinator index of workbench sessions within this task.
* The task actor is the coordinator for sessions. Each row holds session
* metadata, model, status, transcript, and draft state. Sessions are
* sub-entities of the task no separate session actor in the DB.
*/
export const taskWorkbenchSessions = sqliteTable("task_workbench_sessions", {
sessionId: text("session_id").notNull().primaryKey(),
sandboxSessionId: text("sandbox_session_id"),

View file

@ -386,11 +386,24 @@ async function getTaskSandboxRuntime(
};
}
async function ensureSandboxRepo(c: any, sandbox: any, record: any): Promise<void> {
/**
* Track whether the sandbox repo has been fully prepared (cloned + fetched + checked out)
* for the current actor lifecycle. Subsequent calls can skip the expensive `git fetch`
* when `skipFetch` is true (used by sendWorkbenchMessage to avoid blocking on every prompt).
*/
let sandboxRepoPrepared = false;
async function ensureSandboxRepo(c: any, sandbox: any, record: any, opts?: { skipFetchIfPrepared?: boolean }): Promise<void> {
if (!record.branchName) {
throw new Error("cannot prepare a sandbox repo before the task branch exists");
}
// If the repo was already prepared and the caller allows skipping fetch, just return.
// The clone, fetch, and checkout already happened on a prior call.
if (opts?.skipFetchIfPrepared && sandboxRepoPrepared) {
return;
}
const auth = await resolveOrganizationGithubAuth(c, c.state.organizationId);
const repository = await getOrCreateRepository(c, c.state.organizationId, c.state.repoId, c.state.repoRemote);
const metadata = await repository.getRepositoryMetadata({});
@ -426,6 +439,8 @@ async function ensureSandboxRepo(c: any, sandbox: any, record: any): Promise<voi
if ((result.exitCode ?? 0) !== 0) {
throw new Error(`sandbox repo preparation failed (${result.exitCode ?? 1}): ${[result.stdout, result.stderr].filter(Boolean).join("")}`);
}
sandboxRepoPrepared = true;
}
async function executeInSandbox(
@ -1191,7 +1206,9 @@ export async function sendWorkbenchMessage(c: any, sessionId: string, text: stri
const meta = requireSendableSessionMeta(await readSessionMeta(c, sessionId), sessionId);
const record = await ensureWorkbenchSeeded(c);
const runtime = await getTaskSandboxRuntime(c, record);
await ensureSandboxRepo(c, runtime.sandbox, record);
// Skip git fetch on subsequent messages — the repo was already prepared during session
// creation. This avoids a 5-30s network round-trip to GitHub on every prompt.
await ensureSandboxRepo(c, runtime.sandbox, record, { skipFetchIfPrepared: true });
const prompt = [text.trim(), ...attachments.map((attachment: any) => `@ ${attachment.filePath}:${attachment.lineNumber}\n${attachment.lineContent}`)].filter(
Boolean,
);