Enable lock-free parallel agent runs

This commit is contained in:
ZacharyZhang-NY committed 2026-04-22 20:23:44 -04:00
1 parent d13c9d83e8
commit 1a7eb8f1b3
18 files changed
+327 -194

No files matched your search

@@ -81,6 +81,9 @@ export function reconcileWorkspaceArtifacts(
db: AppDatabase,
ctx: ArtifactProjectorRunContext,
): ProjectionOutcome[] {
if (ctx.workspaceMode !== "exclusive") {
return [{ kind: "skipped", reason: "workspace_not_exclusive" }];
}
return projectCollectedChanges(db, ctx, collectChangedPaths(ctx));
}
@@ -88,6 +91,9 @@ function projectBashArtifacts(
db: AppDatabase,
ctx: ArtifactProjectorRunContext,
): ProjectionOutcome[] {
if (ctx.workspaceMode !== "exclusive") {
return [{ kind: "skipped", reason: "workspace_not_exclusive" }];
}
return projectCollectedChanges(db, ctx, collectChangedPaths(ctx));
}
+1
View File
@@ -14,6 +14,7 @@ export type ArtifactProjectorRunContext = {
taskId: string | null;
workspaceId: string | null;
workspacePath: string | null;
workspaceMode: "exclusive" | "shared" | "none";
logger?: Logger;
/**
* mtime snapshot captured at run start for workspaces that are NOT
+2
View File
@@ -56,6 +56,7 @@ export interface ActiveRunContext {
taskSessionId: string;
workspaceId: string | null;
workspacePath: string | null;
workspaceMode: "exclusive" | "shared" | "none";
workspaceBaseline: import("./artifact-projector").WorkspaceBaseline | null;
state: ActiveRunLifecycleState;
}
@@ -162,6 +163,7 @@ export function handleAfterToolCall(
taskId: ctx.taskId,
workspaceId: ctx.workspaceId,
workspacePath: ctx.workspacePath,
workspaceMode: ctx.workspaceMode,
logger: deps.logger,
workspaceBaseline: ctx.workspaceBaseline,
};
+8 -7
View File
@@ -152,6 +152,7 @@ export class RuntimeBridge {
taskId: ctx.taskId,
workspaceId: ctx.workspaceId,
workspacePath: ctx.workspacePath,
workspaceMode: ctx.workspaceMode,
logger: this.deps.logger,
workspaceBaseline: ctx.workspaceBaseline,
});
@@ -394,14 +395,13 @@ export class RuntimeBridge {
modelId: string;
workspaceId: string | null;
workspacePath: string | null;
workspaceMode: "exclusive" | "shared" | "none";
};
// Capture an mtime baseline only for non-git workspaces so `bash`
// and the end-of-run reconciliation can still diff changed files
// against a known-start reference. Git workspaces skip the walk —
// `git status` is the source of truth there, and paying for an
// O(tree) scan on every run just to throw the result away is a
// hot-path tax the scheduler should not be paying.
const baseline = captureBaselineIfRequired(payload.workspacePath, this.deps.logger);
// Baseline scans are safe only while this run owns the workspace lock.
const baseline =
payload.workspaceMode === "exclusive"
? captureBaselineIfRequired(payload.workspacePath, this.deps.logger)
: null;
this.registerActiveRun({
runId,
agentId: payload.agentId,
@@ -412,6 +412,7 @@ export class RuntimeBridge {
taskSessionId: payload.taskSessionId,
workspaceId: payload.workspaceId,
workspacePath: payload.workspacePath,
workspaceMode: payload.workspaceMode,
workspaceBaseline: baseline,
state: "preparing",
});