mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 04:02:01 +00:00
wip (#256)
This commit is contained in:
parent
99abb9d42e
commit
57a07f6a0a
11 changed files with 206 additions and 113 deletions
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue