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
+23 -2
View File
@@ -27,6 +27,14 @@ type AgentClient struct {
}
func (c OpenCodeClient) Interrupt(ctx context.Context, id string) error {
return c.interrupt(ctx, id, false)
}
func (c OpenCodeClient) InterruptAndConfirm(ctx context.Context, id string) error {
return c.interrupt(ctx, id, true)
}
func (c OpenCodeClient) interrupt(ctx context.Context, id string, confirm bool) error {
if !sessionIDPattern.MatchString(id) {
return fmt.Errorf("invalid session ID")
}
@@ -46,7 +54,20 @@ func (c OpenCodeClient) Interrupt(ctx context.Context, id string) error {
c.Backend = connection.Backend
}
_, err := c.call(ctx, "post", "/api/session/"+id+"/interrupt", map[string]any{})
return err
if err != nil || !confirm {
return err
}
// An interrupt acknowledgement is not a cleanup receipt. Keep ownership
// until the harness positively reports settlement, bounded by the caller.
if c.Backend == "v1" {
_, err := c.call(ctx, "post", "/api/experimental/session/"+id+"/wait", nil)
return err
}
// The failed stage wait already records deadline evidence. Cleanup settlement
// must still be confirmed, but must not add a second duplicate operation entry.
confirmed := c
confirmed.Operations = nil
return confirmed.waitForSessionIdle(ctx, id)
}
func (c *AgentClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
@@ -100,7 +121,7 @@ func (c *AgentClient) Generate(ctx context.Context, config ModelConfig, prompt s
defer cancel()
if err != nil {
c.captureTimedOutEvidence(ctx, err, config, watch)
if stopErr := c.Interrupt(cleanup, c.SessionID); stopErr != nil {
if stopErr := c.InterruptAndConfirm(cleanup, c.SessionID); stopErr != nil {
err = fmt.Errorf("agent interrupt failed; retained session %s needs inspection: %w", c.SessionID, errors.Join(err, stopErr, ErrStageCleanup))
return
}