Run every pipeline run in its own worktree
A fresh run started from a repository's main checkout gets its own worktree and branch next to the repository, so runs never share a tree or see the operator's uncommitted work, and several can run at once. Retries and runs started in a linked worktree keep their directory. A clean, landed run tree is removed after success; anything else is kept. The delivery gate commits what the land stage left uncommitted in a run worktree, and no longer requires the operator's main checkout to be clean: Git's fast-forward refuses safely when a local change conflicts.
This commit is contained in:
@@ -319,7 +319,29 @@ func (r *runner) startWithSchedule(request protocol.Message, origin *pipeline.Sc
|
||||
if info, err := os.Stat(workspace); err != nil || !info.IsDir() {
|
||||
return nil, fmt.Errorf("run workspace is no longer available: %s", workspace)
|
||||
}
|
||||
// A fresh run started from a repository's main checkout gets its own
|
||||
// worktree and branch, so runs never share a tree with each other or with
|
||||
// the operator's uncommitted work. A retry keeps its run's tree.
|
||||
isolated := ""
|
||||
if existing == 0 && request.RetrySource == 0 {
|
||||
isolateCtx, isolateCancel := context.WithTimeout(r.ctx, time.Minute)
|
||||
tree, isolateErr := isolateRunWorkspace(isolateCtx, workspace, runTitle.Text)
|
||||
isolateCancel()
|
||||
if isolateErr != nil {
|
||||
return nil, isolateErr
|
||||
}
|
||||
if tree != workspace {
|
||||
isolated = tree
|
||||
}
|
||||
workspace = tree
|
||||
request.Input["pwd"] = workspace
|
||||
}
|
||||
id, created, err := r.store.CreateRunTitled(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, pipeline.RunOverrides{Schedule: origin, Model: request.Model, StageModels: request.StageModels, NotifyMode: request.NotifyMode, OutputFormat: request.OutputFormat}, runTitle, retryOf...)
|
||||
if isolated != "" && (err != nil || !created) {
|
||||
// The run was refused or an identical request won the race: the fresh
|
||||
// tree holds nothing yet.
|
||||
discardRunWorktree(isolated)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -405,6 +427,16 @@ func (r *runner) launch(id int64, workspace string, fn func(context.Context)) {
|
||||
if detail.FinishedAt != "" || detail.Status == protocol.RunStatusWaiting {
|
||||
delete(r.active, id)
|
||||
}
|
||||
// A landed (or change-free) successful run's own worktree is no
|
||||
// longer needed; anything unlanded or uncommitted is kept.
|
||||
if detail.Status == "succeeded" && detail.FinishedAt != "" {
|
||||
workspace := detail.Workspace
|
||||
go func() {
|
||||
if removeLandedRunWorktree(workspace) {
|
||||
log.Printf("run %d: removed its landed worktree %s", id, workspace)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
fn(ctx)
|
||||
}()
|
||||
@@ -2053,7 +2085,7 @@ func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, na
|
||||
} else {
|
||||
gateCtx, gateCancel := context.WithTimeout(stageCtx, modelConfig.Timeout)
|
||||
var catchUp string
|
||||
catchUp, err = verifyDelivery(gateCtx, workspace, landing, checks)
|
||||
catchUp, err = verifyDelivery(gateCtx, workspace, landing, checks, r.deliveryCommitMessage(id))
|
||||
gateCancel()
|
||||
// A failed gate already carries the note in its diagnostic. A step
|
||||
// diagnostic on success renders as a stop, so success is logged.
|
||||
|
||||
Reference in New Issue
Block a user