Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions cmd/clawctl-hub/deploymentcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,32 @@ func writeDeploymentDetail(out io.Writer, result operator.DeploymentDetailResult
return err
}
}
_, err := fmt.Fprintf(out,
if _, err := fmt.Fprintf(out,
"actions: continue=%s (%d) retry=%s (%d) abandon=%s (%d)\n",
deploymentEligibilityLabel(result.Actions.Continue), result.Actions.Continue.AffectedTargets,
deploymentEligibilityLabel(result.Actions.Retry), result.Actions.Retry.AffectedTargets,
deploymentEligibilityLabel(result.Actions.Abandon), result.Actions.Abandon.AffectedTargets)
deploymentEligibilityLabel(result.Actions.Abandon), result.Actions.Abandon.AffectedTargets); err != nil {
return err
}
return writeDeploymentPreviousRelease(out, item.Channel, result.PreviousRelease)
}

func writeDeploymentPreviousRelease(out io.Writer, channel string, previous *operator.DeploymentPreviousRelease) error {
if previous == nil {
_, err := fmt.Fprintln(out, "previous release: none")
return err
}
if _, err := fmt.Fprintf(out, "previous release: %s (deployment %s, artifact %s)\n",
terminalSafe(previous.Version), terminalSafe(previous.DeploymentID), terminalSafe(previous.ArtifactSHA256)); err != nil {
return err
}
if !previous.ArtifactAvailable {
_, err := fmt.Fprintf(out, " artifact missing on Hub; fetch it first: clawctl-hub artifact fetch openclaw@%s --confirm-version %s --reason REASON --idempotency-key KEY\n",
terminalSafe(previous.Version), terminalSafe(previous.Version))
return err
}
_, err := fmt.Fprintf(out, " deploy it: clawctl-hub deployment preview --channel %s --version %s --artifact %s\n",
terminalSafe(channel), terminalSafe(previous.Version), terminalSafe(previous.ArtifactSHA256))
return err
}

Expand Down
31 changes: 31 additions & 0 deletions cmd/clawctl-hub/deploymentreadcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,34 @@ func TestDeploymentPreviewTextShowsEachTargetsCurrentVersion(t *testing.T) {
t.Fatalf("preview text:\n%s", out.String())
}
}

func TestDeploymentDetailTextGivesThePreviousReleaseNextStep(t *testing.T) {
sha := strings.Repeat("a", 64)
previous := &operator.DeploymentPreviousRelease{DeploymentID: "deployment-previous", Version: "2026.9.1",
ArtifactSHA256: sha, ArtifactAvailable: true}
for _, test := range []struct {
name string
previous *operator.DeploymentPreviousRelease
want []string
}{
{"available", previous, []string{
`previous release: "2026.9.1" (deployment "deployment-previous", artifact "` + sha + `")`,
`deploy it: clawctl-hub deployment preview --channel "canary" --version "2026.9.1" --artifact "` + sha + `"`,
}},
{"artifact missing", &operator.DeploymentPreviousRelease{DeploymentID: "deployment-previous", Version: "2026.9.1", ArtifactSHA256: sha},
[]string{`artifact missing on Hub; fetch it first: clawctl-hub artifact fetch openclaw@"2026.9.1" --confirm-version "2026.9.1"`}},
{"none", nil, []string{"previous release: none"}},
} {
t.Run(test.name, func(t *testing.T) {
var out bytes.Buffer
if err := writeDeploymentPreviousRelease(&out, "canary", test.previous); err != nil {
t.Fatal(err)
}
for _, want := range test.want {
if !strings.Contains(out.String(), want) {
t.Errorf("missing %q in:\n%s", want, out.String())
}
}
})
}
}
4 changes: 2 additions & 2 deletions docs/API-SURFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ verifier 不是第二個判斷,是一條用單一 bearer 控管的遠端執行
| `GET` | `/v1/operator/artifact-fetches/{id}` | Fetch operation detail | `artifact fetch show <operation-id>` 預設走 discovery HTTP | queued/running/succeeded/failed、phase、monotonic progress、attempt、result digest/size 或 bounded failure |
| `GET` | `/v1/operator/updates` | Updates 的概觀/Artifacts/Canary/Stable 共用 in-process service | —;strict Go operator client 已交付 | `schema_version=5`;channel/status/version/limit/cursor;同一 evaluation instant 組合 metadata-only artifacts、safe members、`last_observed_version`+Hub-trusted `last_observation_received_at`、latest deployment、rollout plan 與 stable promotion gate。Stable 的 promotion 帶 `independent_required`、通過 target 數,以及每台 machine 與 job 的十一種 typed state 與下一步;不把沒有 freshness threshold 的歷史 evidence 稱為 current |
| `GET` | `/v1/operator/deployments` | All/Active/Paused-Stuck/Finished ledger submenu 共用 in-process operator service;New 另做 isolated metadata-only catalog scan,只列 `available_unverified` 且具有可信 record 的候選材料 | `deployment list` 預設走 discovery HTTP;`--db` 僅 stopped-service break-glass | channel/state/stuck filters、1..100 limit、filter-bound live keyset cursor;safe summary;真正 deployment preview/apply 仍完整驗 artifact bytes |
| `GET` | `/v1/operator/deployments/{id}` | Deployment detail 共用 safe DTO | `deployment show` 預設走 discovery HTTP | `schema_version=3`;targets、material summary、batch/revision 與三個 action eligibility;revision 耗盡會明列 blocker。每個已開單 target 帶 `independent`(八種 verdict 之一、rows、live_producers),其中 `live_producers` 對該 target 的工作單按 distinct verifier 身分計數,不按規則列或重派次數;沒有開單的 target 為 `null`——沒有工作單就沒有東西可驗,與「有工作單但沒人驗」是兩件事,後者是 `absent`。另有 deployment 層的 `independent` rollup:`opened_targets`、`passed_targets`、逐 target 的 `live_producers` 加總與固定列出全部八種 verdict 的 target 計數,全部由 targets 推導,strict client 對不上就拒收整個回應。這個 rollup 只描述該 deployment;stable promotion 另依 latest canary lineage、派工、完整規則組與 exact release version 計算 gate。不回 raw spec/created_by |
| `GET` | `/v1/operator/deployments/{id}` | Deployment detail 共用 safe DTO | `deployment show` 預設走 discovery HTTP | `schema_version=4`;另帶 `previous_release`:同 channel、同資源、比這張早、至少一張 Hub succeeded 工作單、且版號不同的最新 deployment(`deployment_id`、`version`、`artifact_sha256`、`artifact_available`);沒有就是 `null`。回到上一版就是用這三個值走一般的 create preview,同樣經過 canary 與驗證。targets、material summary、batch/revision 與三個 action eligibility;revision 耗盡會明列 blocker。每個已開單 target 帶 `independent`(八種 verdict 之一、rows、live_producers),其中 `live_producers` 對該 target 的工作單按 distinct verifier 身分計數,不按規則列或重派次數;沒有開單的 target 為 `null`——沒有工作單就沒有東西可驗,與「有工作單但沒人驗」是兩件事,後者是 `absent`。另有 deployment 層的 `independent` rollup:`opened_targets`、`passed_targets`、逐 target 的 `live_producers` 加總與固定列出全部八種 verdict 的 target 計數,全部由 targets 推導,strict client 對不上就拒收整個回應。這個 rollup 只描述該 deployment;stable promotion 另依 latest canary lineage、派工、完整規則組與 exact release version 計算 gate。不回 raw spec/created_by |
| `POST` | `/v1/operator/deployments/preview` | 新增部署 settings → review | `deployment preview` 與 create 前自動 preview | `schema_version=5`;重新驗 artifact bytes,固定 target snapshot、promotion decision 與 `preview_digest`。每台 target 帶 `current_version`(最新觀測到正在跑的 OpenClaw 版號;沒有觀測為 `null`),並計入 `preview_digest`:預覽後任一台版本變了,套用回 `412 DEPLOYMENT_PREVIEW_STALE`,要重新預覽。Stable promotion 逐台回 `independent_targets`(machine/job、十一種 state、typed next step)及通過數;任一 effective successful canary target 未通過便 fail closed |
| `POST` | `/v1/operator/deployments` | typed channel/version confirm | `deployment create` preview→apply | `admin`;fresh `201`、成功 replay `200`;拒絕 replay 保留原錯誤 status;artifact/policy stale 與 idempotency conflict 明確分開 |
| `POST` | `/v1/operator/deployments/{id}/continuation-preview` | detail → Continue review | continue 前自動 preview | `operate`;`schema_version=4`;精確下一批或 finish outcome,回 control/opened-batch precondition;若含 stable promotion,使用與 create preview 相同的 typed 獨立證據 gate |
Expand Down Expand Up @@ -466,7 +466,7 @@ machine `/v1/` plane discriminator 必須是 literal,避免 wildcard 在 root
| deployment continue | ✅ | ✅ | ✅ HTTP | control revision + opened-batch CAS、idempotency、atomic audit;stable promotion 沿用同一份獨立證據 gate |
| deployment retry | ✅ | ✅ | ✅ HTTP | 只預選 exact terminal-failure targets;新 attempt 有 lineage |
| deployment abandon | ✅ | ✅ | ✅ HTTP | full-ID confirmation + terminal-job gate + unopened impact |
| deployment list / detail | ✅ | ✅ | ✅ HTTP | safe DTO 供 CLI/UI 共用;detail 是 `schema_version=3`,每個已開單 target 帶八種獨立 verdict 之一,另有由 targets 推導的 rollup;不曝 raw spec/created_by |
| deployment list / detail | ✅ | ✅ | ✅ HTTP | safe DTO 供 CLI/UI 共用;detail 是 `schema_version=4`,每個已開單 target 帶八種獨立 verdict 之一,另有由 targets 推導的 rollup 與 `previous_release`;不曝 raw spec/created_by |
| noop protocol drill | ✅ Diagnostics submenu+preview/confirm | ✅ preview/apply | ✅ HTTP/break-glass | 固定 noop spec、不改機器設定;atomic desired/job/receipt/audit,建立後進入 job detail |
| global job list / detail / evidence | ✅ | ✅ safe projection+typed evidence | ✅ `job list/show/evidence` HTTP | creation-ceiling pagination 仍是 live keyset;raw evidence 已改為 typed bounded disclosure(`schema_version=6`,agent/Hub event producer、role/authority、row provenance、兩個 clocks 與 independence 明標,另有八種 verdict、expected/observed version 的獨立證據段與派工段);sampleagent3 的 fleet-peer verifier 已用獨立 bearer 與 failure domain 寫入正式帳本 |
| audit ledger | ✅ | ✅ safe projection | ✅ `audit [list]` HTTP | 完整 exact filters、creation-ceiling cursor 與 bounded denial sampling 已交付 |
Expand Down
4 changes: 2 additions & 2 deletions docs/FEATURE-INVENTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ resolver 在 `cmd/clawctl-hub/verifier_api.go`。
| 42 | `GET /apps/artifacts/{id}` | HTML | 讀取/完整驗證 | Artifact safe detail;完整重算 SHA-256 後才可顯示 `ready` |
| 43 | `GET /apps/artifact-fetches/{id}` | HTML | 讀取 | Durable fetch operation safe detail |
| 44 | `GET /deployments` | HTML | 讀取 | Deployment list |
| 45 | `GET /deployments/{id}` | HTML | 讀取 | Deployment detail;targets 表加一欄跨故障域證據(每個已開單 target 的 verdict、rows、distinct 可用 producer),表頭一行數出「已開單的 N 台中有幾台被第二個 producer 回報通過」。沒開單的 target 留空,不給 verdict |
| 45 | `GET /deployments/{id}` | HTML | 讀取 | Deployment detail;Previous release 區塊把上一版帶進 create preview(admin);targets 表加一欄跨故障域證據(每個已開單 target 的 verdict、rows、distinct 可用 producer),表頭一行數出「已開單的 N 台中有幾台被第二個 producer 回報通過」。沒開單的 target 留空,不給 verdict |
| 46 | `GET /updates` | HTML | 讀取/preview | 共用 native Updates model 的 artifacts、channel 成員、最近部署與 rollout gate |
| 47 | `GET /reports/tickets` | HTML | 讀取 | Ticket ledger |
| 48 | `GET /reports/tickets.csv` | CSV | 讀取/下載 | Browser export,不是 stable JSON API |
Expand Down Expand Up @@ -161,7 +161,7 @@ resolver 在 `cmd/clawctl-hub/verifier_api.go`。
| 84 | `GET /v1/operator/artifact-fetches/{id}` | JSON | 讀取 | Operation phase/progress/result 或 bounded failure code/detail |
| 85 | `GET /v1/operator/updates` | JSON | 讀取/preview | `schema_version=5`;Artifacts、channel members、latest deployment、rollout plan,以及逐 canary target 顯示十一種獨立證據狀態與下一步的 stable promotion gate |
| 86 | `GET /v1/operator/deployments` | JSON | 讀取 | canonical safe list;channel/state/stuck filters、live keyset cursor |
| 87 | `GET /v1/operator/deployments/{id}` | JSON | 讀取 | canonical safe detail(`schema_version=3`);targets、material summary、action eligibility;每個已開單 target 帶 `independent`(八種 verdict 之一/rows/distinct live_producers),未開單 target 為 `null`;另有 deployment 層 rollup(opened/passed targets、逐 target live producers 加總、八種 verdict 的 target 計數),由 targets 推導而非另一份真相;不回 raw spec/created_by |
| 87 | `GET /v1/operator/deployments/{id}` | JSON | 讀取 | canonical safe detail(`schema_version=4`);另帶 `previous_release`:同 channel、同資源、比這張早、至少一張 Hub succeeded 工作單、且版號不同的最新 deployment(`deployment_id`、`version`、`artifact_sha256`、`artifact_available`);沒有就是 `null`。回到上一版就是用這三個值走一般的 create preview,同樣經過 canary 與驗證。targets、material summary、action eligibility;每個已開單 target 帶 `independent`(八種 verdict 之一/rows/distinct live_producers),未開單 target 為 `null`;另有 deployment 層 rollup(opened/passed targets、逐 target live producers 加總、八種 verdict 的 target 計數),由 targets 推導而非另一份真相;不回 raw spec/created_by |
| 88 | `POST /v1/operator/deployments/preview` | JSON | 是,preview | `schema_version=5`;create preview;重新驗 artifact bytes,固定 targets(含每台 `current_version`,計入 digest)與 promote verdict;stable 逐台要求 active fleet peer 在最新派工後送齊三條必要規則,且 `current_release` 的結構化版號等於 canary exact version |
| 89 | `POST /v1/operator/deployments` | JSON | 是 | create apply;fresh `201`、成功 replay `200`;拒絕 replay 保留原錯誤 status/code |
| 90 | `POST /v1/operator/deployments/{id}/continuation-preview` | JSON | 是,preview | continue/finish preview |
Expand Down
74 changes: 67 additions & 7 deletions internal/operator/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TerminalJobOutcome(state deploy.JobState) string {
}

const (
DeploymentReadSchemaVersion = 3
DeploymentReadSchemaVersion = 4
DeploymentPreviewSchemaVersion = 5
DefaultDeploymentReadLimit = 50
MaxDeploymentReadLimit = 100
Expand Down Expand Up @@ -294,6 +294,19 @@ type DeploymentDetailResult struct {
Targets []DeploymentTargetSummary `json:"targets"`
Independent DeploymentIndependentSummary `json:"independent"`
Actions DeploymentActionEligibilitySet `json:"actions"`
// PreviousRelease is the release this deployment replaced on its channel.
// Nil means the channel has no earlier succeeded release of another version.
PreviousRelease *DeploymentPreviousRelease `json:"previous_release"`
}

// DeploymentPreviousRelease names the latest earlier deployment on the same
// channel and resource that has a Hub-succeeded job and a different version.
// Deploying it again is an ordinary create preview with these inputs.
type DeploymentPreviousRelease struct {
DeploymentID string `json:"deployment_id"`
Version string `json:"version"`
ArtifactSHA256 string `json:"artifact_sha256"`
ArtifactAvailable bool `json:"artifact_available"`
}

type DeploymentCreatePreviewRequest struct {
Expand Down Expand Up @@ -472,7 +485,11 @@ func (s *Service) DeploymentDetail(deploymentID string, evaluatedAt time.Time) (
if err != nil {
return DeploymentDetailResult{}, err
}
actions, err := s.deploymentActionEligibility(view, summary.Material, evaluatedAt)
views, err := s.store.ListDeployments(evaluatedAt)
if err != nil {
return DeploymentDetailResult{}, err
}
actions, err := s.deploymentActionEligibility(view, summary.Material, views, evaluatedAt)
if err != nil {
return DeploymentDetailResult{}, err
}
Expand All @@ -484,9 +501,54 @@ func (s *Service) DeploymentDetail(deploymentID string, evaluatedAt time.Time) (
return DeploymentDetailResult{
SchemaVersion: DeploymentReadSchemaVersion, Consistency: DeploymentReadConsistencyLive, EvaluatedAt: evaluatedAt,
Item: summary, Targets: targets, Independent: independent, Actions: actions,
PreviousRelease: s.deploymentPreviousRelease(view, summary.Material, views),
}, nil
}

func (s *Service) deploymentPreviousRelease(view store.DeploymentView, material DeploymentMaterialSummary,
views []store.DeploymentView,
) *DeploymentPreviousRelease {
if material.Status != DeploymentMaterialRecorded || material.Version == nil {
return nil
}
var found *store.DeploymentView
var foundMaterial DeploymentMaterialSummary
for i := range views {
candidate := &views[i]
if candidate.DeploymentID == view.DeploymentID || candidate.Channel != view.Channel ||
candidate.ResourceKind != view.ResourceKind || candidate.ResourceID != view.ResourceID ||
candidate.Counts[deploy.Succeeded] == 0 || !deploymentCreatedBefore(*candidate, view) ||
(found != nil && !deploymentCreatedBefore(*found, *candidate)) {
continue
}
candidateMaterial := projectDeploymentMaterial(candidate.ResourceKind, candidate.ResourceID, candidate.Spec)
if candidateMaterial.Status != DeploymentMaterialRecorded || candidateMaterial.Version == nil ||
candidateMaterial.ArtifactDigest == nil || *candidateMaterial.Version == *material.Version {
continue
}
found, foundMaterial = candidate, candidateMaterial
}
if found == nil {
return nil
}
release := &DeploymentPreviousRelease{
DeploymentID: found.DeploymentID, Version: *foundMaterial.Version,
ArtifactSHA256: strings.TrimPrefix(*foundMaterial.ArtifactDigest, "sha256:"),
}
if strings.TrimSpace(s.artifactsDir) != "" {
_, err := artifact.SelectOpenClawArtifact(s.artifactsDir, release.Version, release.ArtifactSHA256)
release.ArtifactAvailable = err == nil
}
return release
}

func deploymentCreatedBefore(a, b store.DeploymentView) bool {
if !a.CreatedAt.Equal(b.CreatedAt) {
return a.CreatedAt.Before(b.CreatedAt)
}
return a.DeploymentID < b.DeploymentID
}

// attachDeploymentIndependentVerdicts gives every opened target a verdict and
// counts them. A target whose job has no independent row gets absent rather
// than nil: the job exists, the ledger was read, and nothing was found. Only a
Expand Down Expand Up @@ -867,7 +929,9 @@ func projectDeploymentTargets(view store.DeploymentView) ([]DeploymentTargetSumm
return result, nil
}

func (s *Service) deploymentActionEligibility(view store.DeploymentView, material DeploymentMaterialSummary, now time.Time) (DeploymentActionEligibilitySet, error) {
func (s *Service) deploymentActionEligibility(view store.DeploymentView, material DeploymentMaterialSummary,
views []store.DeploymentView, now time.Time,
) (DeploymentActionEligibilitySet, error) {
set := DeploymentActionEligibilitySet{
Continue: DeploymentActionEligibility{Outcome: "open_next_batch", Blockers: []string{}},
SkipFailedBatch: DeploymentActionEligibility{Outcome: "open_next_batch", Blockers: []string{}},
Expand Down Expand Up @@ -951,10 +1015,6 @@ func (s *Service) deploymentActionEligibility(view store.DeploymentView, materia
set.Retry.Blockers = append(set.Retry.Blockers, "stable_promotion_locked")
}
}
views, err := s.store.ListDeployments(now)
if err != nil {
return DeploymentActionEligibilitySet{}, err
}
for _, candidate := range views {
if candidate.DeploymentID != view.DeploymentID &&
(candidate.State == store.DeploymentRunning || candidate.State == store.DeploymentPaused) &&
Expand Down
6 changes: 5 additions & 1 deletion internal/operator/deployment_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ func (s *Service) deploymentActionSnapshot(ctx context.Context, action, deployme
if err != nil {
return deploymentActionSnapshot{}, err
}
actions, err := s.deploymentActionEligibility(view, summary.Material, evaluatedAt)
views, err := s.store.ListDeployments(evaluatedAt)
if err != nil {
return deploymentActionSnapshot{}, err
}
actions, err := s.deploymentActionEligibility(view, summary.Material, views, evaluatedAt)
if err != nil {
return deploymentActionSnapshot{}, err
}
Expand Down
Loading
Loading