Claude stages survive server restarts; non-repo folders don't falsely overlap; busy scheduled runs wait
- Claude stage CLIs now run in their own session (setsid) with the prompt from a file and stream-json written straight to cli-<n>.out in the evidence directory; owner.json records pid/pgid, session, invocation and output. A server shutdown leaves the CLI running and owned (ErrDetached). Start-up recovery re-adopts it (stage.ClaudeStageReattachable): the next process re-reads the output, follows the live CLI until it exits, or reads the result it left while the server was down; one that ended without a result marks the run interrupted with a clear reason. The outcome repair follow-up is re-adopted too (or asked again if its CLI died without a reply). - Workspace overlap: two folders outside any repository overlap only when they are the same folder or the inner one lies within the outer run's declared write paths; nested-repository rules are unchanged. - Scheduled admissions refused for a busy workspace are recorded as "delayed" and retried every 5 min for up to 2 h (env-configurable), then started or skipped with the reason; the operator gets a low-priority app notice (and ntfy when enabled) when a scheduled run is delayed or skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -122,10 +122,13 @@ func TestCleanupUnconfirmedReservesWorkspaceAcrossRecovery(t *testing.T) {
|
||||
|
||||
func TestWorkspaceOverlapIncludesParentsDescendantsAndSymlinks(t *testing.T) {
|
||||
_, r, pipelineID := concurrentStore(t)
|
||||
// One repository: its folder and a folder inside it are one shared tree.
|
||||
workspace := t.TempDir()
|
||||
child := filepath.Join(workspace, "child")
|
||||
if err := os.Mkdir(child, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
for _, dir := range []string{filepath.Join(workspace, ".git"), child} {
|
||||
if err := os.Mkdir(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
alias := filepath.Join(t.TempDir(), "alias")
|
||||
if err := os.Symlink(child, alias); err != nil {
|
||||
@@ -176,3 +179,73 @@ func TestWorkspaceOverlapSeparatesNestedRepositories(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two folders outside any repository (the operator's ~/caplens and a sibling
|
||||
// project folder under it) are not one tree merely because neither is in a
|
||||
// repository: nested, they overlap only where the outer run's declared write
|
||||
// paths reach the inner folder. The same folder always overlaps.
|
||||
func TestWorkspaceOverlapNonRepositoryFolders(t *testing.T) {
|
||||
hub := t.TempDir()
|
||||
brief := filepath.Join(hub, "brief")
|
||||
notes := filepath.Join(hub, "notes", "deep")
|
||||
for _, dir := range []string{brief, notes} {
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
paths := func(p ...string) func() []string { return func() []string { return p } }
|
||||
for _, test := range []struct {
|
||||
a, b string
|
||||
aPaths, bPaths func() []string
|
||||
want bool
|
||||
}{
|
||||
{hub, hub, nil, nil, true},
|
||||
{brief, brief, nil, nil, true},
|
||||
{hub, brief, nil, nil, false},
|
||||
{brief, hub, nil, nil, false},
|
||||
{brief, notes, nil, nil, false},
|
||||
{hub, brief, paths("notes"), nil, false},
|
||||
{hub, brief, paths("brief"), nil, true},
|
||||
{hub, notes, paths("notes"), nil, true},
|
||||
{hub, notes, paths("notes/deep/file.md"), nil, true},
|
||||
{notes, hub, nil, paths("notes"), true},
|
||||
{notes, hub, paths("notes"), nil, false}, // The inner run's paths do not reach out.
|
||||
{hub, brief, paths("."), nil, true},
|
||||
} {
|
||||
if got := workspaceScopesOverlap(test.a, test.b, test.aPaths, test.bPaths); got != test.want {
|
||||
t.Errorf("overlap(%s, %s) = %v, want %v", test.a, test.b, got, test.want)
|
||||
}
|
||||
}
|
||||
// Nested repository rules stay: a repository inside a plain folder is its
|
||||
// own tree whatever the folder's write paths.
|
||||
repo := filepath.Join(hub, "repo")
|
||||
if err := os.MkdirAll(filepath.Join(repo, ".git"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if workspaceScopesOverlap(hub, repo, paths("repo"), nil) {
|
||||
t.Fatal("a repository inside a plain folder overlaps it")
|
||||
}
|
||||
|
||||
// End to end: a scheduled brief in the hub is admitted while a run works in
|
||||
// a sibling folder below it, and refused only when it declares a write
|
||||
// path reaching that folder.
|
||||
_, r, pipelineID := concurrentStore(t)
|
||||
release := make(chan struct{})
|
||||
defer close(release)
|
||||
r.execute = func(ctx context.Context, _ stage.Definition, _ stage.Values) (stage.Result, error) {
|
||||
select {
|
||||
case <-release:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
return stage.Result{Outcome: "success"}, nil
|
||||
}
|
||||
if _, err := r.start(protocol.Message{PipelineID: pipelineID, Version: 1, RequestKey: "notes", Workspace: notes, Input: map[string]any{"prompt": "task"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.start(protocol.Message{PipelineID: pipelineID, Version: 1, RequestKey: "brief-scoped", Workspace: hub, WritePaths: []string{"notes"}, Input: map[string]any{"prompt": "task"}}); err == nil || !strings.Contains(err.Error(), "already active") {
|
||||
t.Fatal("a hub run writing into the active folder was admitted:", err)
|
||||
}
|
||||
if _, err := r.start(protocol.Message{PipelineID: pipelineID, Version: 1, RequestKey: "brief", Workspace: hub, Input: map[string]any{"prompt": "task"}}); err != nil {
|
||||
t.Fatal("a hub run was refused for a sibling folder's run:", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user