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
+14 -1
View File
@@ -10,7 +10,7 @@ import (
)
func decodeControl(text string, value any) error {
// Both control blocks are flat objects. Reject duplicate keys before decoding.
// Control blocks are flat objects. Reject duplicate keys before decoding.
keys := json.NewDecoder(strings.NewReader(text))
if token, err := keys.Token(); err != nil || token != json.Delim('{') {
return fmt.Errorf("expected object")
@@ -44,6 +44,12 @@ func decodeControl(text string, value any) error {
}
func parseControl(s *Stage, fields map[string]string) error {
if text, ok := fields["resources"]; ok {
if err := decodeControl(text, &s.Resources); err != nil || s.Resources == nil || !ValidResourceKey(s.Resources.Exclusive) {
return fmt.Errorf("resources must contain exactly one exclusive key (1–128 ASCII letters, digits, _ or -; start with a letter)")
}
delete(fields, "resources")
}
if text, ok := fields["limits"]; ok {
if err := decodeControl(text, &s.Limits); err != nil || s.Limits == nil {
return fmt.Errorf("limits must be an object with max_visits and optional on outcomes")
@@ -76,6 +82,9 @@ func parseControl(s *Stage, fields map[string]string) error {
}
func validateControl(s Stage, stages map[string]bool) error {
if s.Resources != nil && s.Type == "human" {
return fmt.Errorf("stage %s: human stages cannot declare resources", s.Key)
}
if s.Limits != nil {
for _, outcome := range s.Limits.On {
target, exists := s.Edges[outcome]
@@ -95,3 +104,7 @@ func validateControl(s Stage, stages map[string]bool) error {
}
return nil
}
func ValidResourceKey(key string) bool {
return len(key) <= 128 && identifier.MatchString(key)
}