Add stage-exclusive resource waiting

Add durable FIFO capacity-one resource leases for executable stages, including cleanup-confirmed release, conservative restart quarantine, queue state events, and CLI/TUI/Android waiting presentation. Add scheduler, cleanup, protocol, client, and Android coverage plus a proposed Android v3 resource draft.

Checked packaged templates and authoring skill references: neither needs updating in this item. The per-item docs note records the shared documentation that docs-fold must update; no shared README or packaged reference was edited.
This commit is contained in:
2026-10-18 12:30:30 +01:00
parent 88595ebd55
commit 9130ae8c7a
39 changed files with 2657 additions and 79 deletions
+6
View File
@@ -19,6 +19,7 @@ const (
)
type Stage struct {
Resources *StageResources `json:"resources,omitempty"`
Limits *StageLimits `json:"limits,omitempty"`
Memory map[string]string `json:"memory,omitempty"`
Notify *NotificationPolicy `json:"notify,omitempty"`
@@ -33,6 +34,11 @@ type Stage struct {
Blocks map[string]string `json:"blocks,omitempty"`
}
// StageResources declares one capacity-one resource, local to this store authority.
type StageResources struct {
Exclusive string `json:"exclusive"`
}
// Limits are enforced by the runner and never included in the model prompt.
type StageLimits struct {
MaxVisits int `json:"max_visits"`
+29
View File
@@ -0,0 +1,29 @@
package protocol
import (
"encoding/json"
"strings"
"testing"
)
func TestResourceWaitOlderClientCompatibility(t *testing.T) {
data, err := json.Marshal(RunSummary{ID: 1, Status: RunStatusQueued, ResourceWait: &ResourceWait{Resource: "X", Stage: "review", Sequence: 2, QueuedSince: "now"}})
if err != nil {
t.Fatal(err)
}
var old struct {
ID int64 `json:"id"`
Status string `json:"status"`
}
if err := json.Unmarshal(data, &old); err != nil || old.Status != "queued" {
t.Fatal("old client no longer waits", old, err)
}
clear, err := json.Marshal(RunEventFrame{RunID: 1, ResourceWaitSet: true})
if err != nil || !strings.Contains(string(clear), `"resource_wait_set":true`) {
t.Fatal("no explicit clear", string(clear), err)
}
var current RunSummary
if err := json.Unmarshal([]byte(`{"id":2,"status":"running"}`), &current); err != nil || current.ResourceWait != nil {
t.Fatal("missing field changed old payload", err)
}
}
+5 -2
View File
@@ -24,8 +24,11 @@ const (
// from the frame instead of re-reading the whole list. They repeat on every
// frame (pipeline identity never changes mid-run).
type RunEventFrame struct {
RunID int64 `json:"run_id"`
Workspace string `json:"workspace,omitempty"`
// ResourceWaitSet makes a nil ResourceWait an explicit cache clear.
ResourceWaitSet bool `json:"resource_wait_set,omitempty"`
ResourceWait *ResourceWait `json:"resource_wait,omitempty"`
RunID int64 `json:"run_id"`
Workspace string `json:"workspace,omitempty"`
// PipelineID, Name, Title and Version identify the run's pipeline and its
// operator-facing title, so a new run's row can be built without a fetch.
PipelineID int64 `json:"pipeline_id,omitempty"`
+25 -3
View File
@@ -118,9 +118,10 @@ type SessionExport struct {
}
type RunSummary struct {
ID int64 `json:"id"`
PipelineID int64 `json:"pipeline_id"`
Name string `json:"name"`
ResourceWait *ResourceWait `json:"resource_wait,omitempty"`
ID int64 `json:"id"`
PipelineID int64 `json:"pipeline_id"`
Name string `json:"name"`
// Title is the operator-facing, bounded single-line description of what the
// run is for, generated from its prompt. It is never empty for a new run;
// historical rows predating the title column may omit it.
@@ -145,6 +146,19 @@ type RunSummary struct {
StageModels map[string]string `json:"stage_models,omitempty"`
}
// ResourceWait is bounded public queue metadata. Ownership credentials stay private.
type ResourceWait struct {
Resource string `json:"resource"`
Stage string `json:"stage"`
Sequence int `json:"sequence"`
QueuedSince string `json:"queued_since"`
}
// ResourceCleanupConfirmedKey lets a stage report failed restoration without
// pretending that tool idleness also proves the resource is ready. An explicit
// false (or malformed value) vetoes release; it never authorizes release alone.
const ResourceCleanupConfirmedKey = "resource_cleanup_confirmed"
// Label is the operator-facing name of a run: the generated Title when the
// server stored one, otherwise the pipeline Name (historical rows predate
// titles). It is the single definition shared by the CLI and TUI.
@@ -155,6 +169,14 @@ func (r RunSummary) Label() string {
return r.Name
}
// StatusLabel separates resource contention from a human decision everywhere.
func (r RunSummary) StatusLabel() string {
if r.ResourceWait != nil {
return "Waiting for resource " + r.ResourceWait.Resource
}
return r.Status
}
type RunStep struct {
Control *ControlEvidence `json:"control,omitempty"`
FileChanges *StageFileChanges `json:"file_changes,omitempty"`