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:
2026-12-03 12:55:12 +00:00
parent c4de1de27b
commit f061675fc1
20 changed files with 1344 additions and 180 deletions
+24
View File
@@ -0,0 +1,24 @@
package pipeline
import (
"context"
"encoding/json"
)
// RunWritePaths returns the write paths a run declared (relative to its
// workspace; empty when it declared none). The workspace reservation check
// reads it only when two runs' workspaces nest outside any repository.
func (s *Store) RunWritePaths(ctx context.Context, id int64) ([]string, error) {
var encoded string
if err := s.db.QueryRowContext(ctx, "SELECT write_paths FROM pipeline_runs WHERE id=?", id).Scan(&encoded); err != nil {
return nil, err
}
var paths []string
if encoded == "" {
return nil, nil
}
if err := json.Unmarshal([]byte(encoded), &paths); err != nil {
return nil, err
}
return paths, nil
}
+1 -1
View File
@@ -99,7 +99,7 @@ func (s *Store) CreateRunTitled(ctx context.Context, d *protocol.PipelineDetail,
// Acquire the SQLite writer lock while checking the original saved
// revision and occurrence. Edits/deletes between claim and admission
// invalidate admission, including while a title was being generated.
result, err := tx.ExecContext(ctx, `UPDATE saved_schedule_events SET status='admitted' WHERE schedule_id=? AND due=? AND revision=? AND status='claimed' AND run_id IS NULL AND EXISTS(SELECT 1 FROM saved_schedules WHERE id=? AND revision=? AND enabled=1 AND deleted=0)`, origin.ID, origin.Due.UTC().Format(time.RFC3339Nano), origin.Revision, origin.ID, origin.Revision)
result, err := tx.ExecContext(ctx, `UPDATE saved_schedule_events SET status='admitted' WHERE schedule_id=? AND due=? AND revision=? AND status IN ('claimed','delayed') AND run_id IS NULL AND EXISTS(SELECT 1 FROM saved_schedules WHERE id=? AND revision=? AND enabled=1 AND deleted=0)`, origin.ID, origin.Due.UTC().Format(time.RFC3339Nano), origin.Revision, origin.ID, origin.Revision)
if err != nil {
return 0, false, err
}
+9
View File
@@ -409,6 +409,15 @@ func (s *Store) FinishSavedSchedule(ctx context.Context, id int64, due time.Time
return err
}
// SavedScheduleOccurrence reads one occurrence's history entry: its status
// (claimed, delayed, admitted, started, skipped, skipped_missed, skipped_day),
// diagnostic and admitted run (0 when none).
func (s *Store) SavedScheduleOccurrence(ctx context.Context, id int64, due time.Time) (status, diagnostic string, runID int64, err error) {
var run sql.NullInt64
err = s.db.QueryRowContext(ctx, `SELECT status,diagnostic,run_id FROM saved_schedule_events WHERE schedule_id=? AND due=?`, id, due.UTC().Format(time.RFC3339Nano)).Scan(&status, &diagnostic, &run)
return status, diagnostic, run.Int64, err
}
// ScheduleAdmission is an internal capability, never decoded from public messages.
type ScheduleAdmission struct {
ID, Revision int64