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
11 changes: 7 additions & 4 deletions cmd/clawctl-hub/deploymentcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func writeDeploymentPreview(out io.Writer, result operator.DeploymentCreatePrevi
return err
}
tw := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0)
if _, err := fmt.Fprintln(tw, "MACHINE\tPLAN\tNODE\tREACHABLE"); err != nil {
if _, err := fmt.Fprintln(tw, "MACHINE\tPLAN\tCURRENT\tNODE\tREACHABLE"); err != nil {
return err
}
for _, target := range result.Targets {
Expand All @@ -556,12 +556,15 @@ func writeDeploymentPreview(out io.Writer, result operator.DeploymentCreatePrevi
} else {
plan = fmt.Sprintf("batch %d", target.BatchNo)
}
node := "unknown"
node, current := "unknown", "unknown"
if target.NodeVersion != nil {
node = *target.NodeVersion
}
if _, err := fmt.Fprintf(tw, "%s\t%s\t%s\t%t\n", terminalSafe(target.DisplayName),
terminalSafe(plan), terminalSafe(node), target.Reachable); err != nil {
if target.CurrentVersion != nil {
current = *target.CurrentVersion
}
if _, err := fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%t\n", terminalSafe(target.DisplayName),
terminalSafe(plan), terminalSafe(current), terminalSafe(node), target.Reachable); err != nil {
return err
}
}
Expand Down
30 changes: 30 additions & 0 deletions cmd/clawctl-hub/deploymentreadcmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,33 @@ func TestDeploymentDetailCLIStatesIndependentEvidenceAsEvidence(t *testing.T) {
t.Errorf("unopened target line carries a verdict: %q", line)
}
}

func TestDeploymentPreviewTextShowsEachTargetsCurrentVersion(t *testing.T) {
current := "2026.9.1"
var out bytes.Buffer
if err := writeDeploymentPreview(&out, operator.DeploymentCreatePreviewResult{
Artifact: operator.DeploymentArtifactPreview{Version: "2026.9.3"},
Targets: []operator.DeploymentPlanTargetPreview{
{MachineID: "machine-a", DisplayName: "alpha", BatchNo: 1, Reachable: true, CurrentVersion: &current},
{MachineID: "machine-b", DisplayName: "beta", BatchNo: 2, Reachable: true},
},
}, false, "Hub"); err != nil {
t.Fatal(err)
}
lines := strings.Split(out.String(), "\n")
var header, alpha, beta string
for _, line := range lines {
switch fields := strings.Fields(line); {
case len(fields) > 0 && fields[0] == "MACHINE":
header = strings.Join(fields, " ")
case len(fields) > 0 && fields[0] == `"alpha"`:
alpha = strings.Join(fields, " ")
case len(fields) > 0 && fields[0] == `"beta"`:
beta = strings.Join(fields, " ")
}
}
if header != "MACHINE PLAN CURRENT NODE REACHABLE" || alpha != `"alpha" "batch 1" "2026.9.1" "unknown" true` ||
beta != `"beta" "batch 2" "unknown" "unknown" true` {
t.Fatalf("preview text:\n%s", out.String())
}
}
4 changes: 2 additions & 2 deletions docs/API-SURFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ verifier 不是第二個判斷,是一條用單一 bearer 控管的遠端執行
| `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 |
| `POST` | `/v1/operator/deployments/preview` | 新增部署 settings → review | `deployment preview` 與 create 前自動 preview | `schema_version=4`;重新驗 artifact bytes,固定 target snapshot、promotion decision 與 `preview_digest`。Stable promotion 逐台回 `independent_targets`(machine/job、十一種 state、typed next step)及通過數;任一 effective successful canary target 未通過便 fail closed |
| `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 |
| `POST` | `/v1/operator/deployments/{id}/continuations` | typed channel confirm | `deployment continue` preview→apply | `operate`;只開下一批或收尾。失敗批次回 `DEPLOYMENT_CONTINUE_REFUSED`,不把失敗 target 當 retry |
Expand Down Expand Up @@ -341,7 +341,7 @@ batch plan,不能把超過 blast-radius 上限的 legacy canary 當作合格
拒絕 replay 則只信 canonical rejection code/detail 與唯一原始 failed audit,不讀今天的 fleet state;
兩者都不能只因 cached JSON 能 decode 就相信。

Stable promotion 的 public contract 由 deployment preview `schema_version=4`、deployment action
Stable promotion 的 public contract 由 deployment preview `schema_version=5`、deployment action
`schema_version=4` 與 updates `schema_version=5` 共用。`promotion.independent_required` 固定明列;
`independent_passed_targets` 必須等於 `independent_targets` 裡的 passed 數。每個 target 都帶 exact
machine、`job_id` 與十一種 state 之一與對應的 typed `next_step`。`job_id` 只有 `canary_not_succeeded` 可以是空的,其餘 state 必須是 exact job;重複的 job ID 只在非空的 ID 之間檢查。strict client 會重新計數並拒收 unknown
Expand Down
2 changes: 1 addition & 1 deletion docs/FEATURE-INVENTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ resolver 在 `cmd/clawctl-hub/verifier_api.go`。
| 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 |
| 88 | `POST /v1/operator/deployments/preview` | JSON | 是,preview | `schema_version=4`;create preview;重新驗 artifact bytes,固定 targets 與 promote verdict;stable 逐台要求 active fleet peer 在最新派工後送齊三條必要規則,且 `current_release` 的結構化版號等於 canary exact version |
| 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 |
| 91 | `POST /v1/operator/deployments/{id}/continuations` | JSON | 是 | optimistic precondition + idempotent apply |
Expand Down
10 changes: 8 additions & 2 deletions internal/operator/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TerminalJobOutcome(state deploy.JobState) string {

const (
DeploymentReadSchemaVersion = 3
DeploymentPreviewSchemaVersion = 4
DeploymentPreviewSchemaVersion = 5
DefaultDeploymentReadLimit = 50
MaxDeploymentReadLimit = 100
// DefaultDeploymentBatchSize is the later-batch size when a caller omits
Expand Down Expand Up @@ -322,6 +322,7 @@ type DeploymentPlanTargetPreview struct {
DisplayName string `json:"display_name"`
Reachable bool `json:"reachable"`
NodeVersion *string `json:"node_version"`
CurrentVersion *string `json:"current_version"`
BatchNo int `json:"batch_no"`
ExcludedReason *string `json:"excluded_reason"`
}
Expand Down Expand Up @@ -1010,7 +1011,8 @@ func projectDeploymentPlan(plan rollout.DeploymentPlan, batchSize int) ([]Deploy
for i, target := range plan.Targets {
if !validDeploymentIdentifier(target.MachineID, 256) ||
!validDeploymentText(target.DisplayName, 256, false) ||
!validDeploymentText(target.NodeVersion, 128, true) || seen[target.MachineID] || target.BatchNo < 0 {
!validDeploymentText(target.NodeVersion, 128, true) ||
!validDeploymentText(target.CurrentVersion, 128, true) || seen[target.MachineID] || target.BatchNo < 0 {
return nil, fmt.Errorf("%w: deployment plan target is invalid", ErrInvalidDeploymentPreview)
}
if i > 0 && (target.DisplayName < previousName ||
Expand All @@ -1027,6 +1029,10 @@ func projectDeploymentPlan(plan rollout.DeploymentPlan, batchSize int) ([]Deploy
value := target.NodeVersion
item.NodeVersion = &value
}
if target.CurrentVersion != "" {
value := target.CurrentVersion
item.CurrentVersion = &value
}
if target.ExcludedReason != "" {
if !isDeploymentExclusion(target.ExcludedReason) || target.BatchNo != 0 {
return nil, fmt.Errorf("%w: deployment exclusion is invalid", ErrInvalidDeploymentPreview)
Expand Down
45 changes: 45 additions & 0 deletions internal/operator/deployment_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,51 @@ func TestApplyDeploymentCreateStaleAndConfirmationRejectionsReplay(t *testing.T)
}
}

// A machine whose running version changes after the preview no longer matches
// what the operator reviewed, so the create must be previewed again.
func TestApplyDeploymentCreateRefusesWhenATargetVersionChangedAfterPreview(t *testing.T) {
st := newDeploymentOperatorStore(t)
now := time.Now().UTC().Truncate(time.Second).Add(-10 * time.Second)
if err := prepareDeploymentObservationPolicy(st, now.Add(-time.Hour)); err != nil {
t.Fatal(err)
}
observeDeploymentMachine(t, st, "machine-a", "alpha", "canary", "24.15.0", "2026.9.1", now)
observeDeploymentMachine(t, st, "machine-b", "beta", "canary", "24.15.0", "", now)
artifactDir := t.TempDir()
record := writeDeploymentArtifact(t, artifactDir, deploymentTestVersion, ">=24.15.0 <25", now.Add(-time.Hour))
svc := NewWithArtifacts(st, artifactDir)
plan := DeploymentCreatePreviewRequest{
Channel: "canary", Version: deploymentTestVersion, ArtifactSHA256: record.SHA256,
BatchSize: 1, ExecutionTimeoutSeconds: 600,
}
preview, err := svc.PreviewDeploymentCreate(plan, now)
if err != nil {
t.Fatal(err)
}
if len(preview.Targets) != 2 || preview.Targets[0].CurrentVersion == nil ||
*preview.Targets[0].CurrentVersion != "2026.9.1" || preview.Targets[1].CurrentVersion != nil {
t.Fatalf("targets=%+v", preview.Targets)
}
observeDeploymentMachine(t, st, "machine-a", "alpha", "canary", "24.15.0", "2026.9.3", now.Add(time.Second))
request := DeploymentCreateApplyRequest{
DeploymentCreatePreviewRequest: plan, PreviewDigest: preview.PreviewDigest,
ConfirmChannel: "canary", ConfirmVersion: deploymentTestVersion,
Reason: "target changed after preview", IdempotencyKey: "deployment-create-target-changed",
Actor: verifiedDeploymentActor(),
}
_, err = svc.ApplyDeploymentCreate(request)
assertDeploymentOperatorCode(t, err, store.OperatorCodeDeploymentPreviewStale, false)

fresh, err := svc.PreviewDeploymentCreate(plan, time.Now().UTC())
if err != nil || fresh.PreviewDigest == preview.PreviewDigest || *fresh.Targets[0].CurrentVersion != "2026.9.3" {
t.Fatalf("fresh preview=%+v err=%v", fresh, err)
}
request.PreviewDigest, request.IdempotencyKey = fresh.PreviewDigest, "deployment-create-after-repreview"
if _, err := svc.ApplyDeploymentCreate(request); err != nil {
t.Fatalf("apply after a fresh preview: %v", err)
}
}

func TestDeploymentContinuePreviewApplyAndReplayDoNotReopenBatch(t *testing.T) {
svc, st, artifactDir, record, parent, jobs := deploymentActionFixture(t, 2, 1)
markDeploymentJobTerminal(t, st, jobs[0].JobID, deploy.Succeeded)
Expand Down
2 changes: 1 addition & 1 deletion internal/operator/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestProjectDeploymentPromotionKeepsCanaryNotSucceededOutOfThePassedCount(t
// action preview that may finish a stable deployment, and Updates. Old strict
// clients reject unknown fields, so all three schema versions move together.
func TestIndependentPromotionFieldsComeWithNewSchemaVersions(t *testing.T) {
if DeploymentReadSchemaVersion != 3 || DeploymentPreviewSchemaVersion != 4 ||
if DeploymentReadSchemaVersion != 3 || DeploymentPreviewSchemaVersion != 5 ||
DeploymentActionSchemaVersion != 4 || UpdateReadSchemaVersion != 5 {
t.Fatalf("schema versions read=%d preview=%d action=%d updates=%d",
DeploymentReadSchemaVersion, DeploymentPreviewSchemaVersion,
Expand Down
6 changes: 6 additions & 0 deletions internal/operatorclient/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ func validateDeploymentCreatePreviewResult(result operator.DeploymentCreatePrevi
return errors.New("operator client: invalid preview node version")
}
}
if target.CurrentVersion != nil {
if *target.CurrentVersion == "" ||
validateDeploymentClientText("preview current_version", *target.CurrentVersion, 128, true) != nil {
return errors.New("operator client: invalid preview current version")
}
}
if target.ExcludedReason != nil {
if target.BatchNo != 0 {
return errors.New("operator client: excluded preview target has a batch")
Expand Down
8 changes: 6 additions & 2 deletions internal/rollout/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ type MachineFacts struct {
DisplayName string
Reachable bool
NodeVersion string
Conflict bool
// CurrentVersion is the OpenClaw version the machine last reported running.
// Empty means the Hub has no such observation.
CurrentVersion string
Conflict bool
// Noncompliant reports that a compliance action is currently withholding
// work from this machine.
Noncompliant bool
Expand All @@ -32,6 +35,7 @@ type Target struct {
DisplayName string
Reachable bool
NodeVersion string
CurrentVersion string
BatchNo int
ExcludedReason string
}
Expand Down Expand Up @@ -61,7 +65,7 @@ func Plan(members []MachineFacts, engines string, batchSize int) DeploymentPlan
})
var p DeploymentPlan
for _, m := range sorted {
t := Target{MachineID: m.MachineID, DisplayName: m.DisplayName, Reachable: m.Reachable, NodeVersion: m.NodeVersion}
t := Target{MachineID: m.MachineID, DisplayName: m.DisplayName, Reachable: m.Reachable, NodeVersion: m.NodeVersion, CurrentVersion: m.CurrentVersion}
switch {
case m.Noncompliant:
// 先問這一條:一台領不到工作單的機器,講成「跟別的單衝突」或
Expand Down
4 changes: 2 additions & 2 deletions internal/rollout/rollout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPlanSeparatesExclusionsAndBatches(t *testing.T) {
members := []MachineFacts{
{MachineID: "u", DisplayName: "unreachable", Reachable: false, NodeVersion: "24.15.0"},
{MachineID: "b", DisplayName: "beta", Reachable: true, NodeVersion: "22.22.2"},
{MachineID: "a", DisplayName: "alpha", Reachable: true, NodeVersion: "24.15.0"},
{MachineID: "a", DisplayName: "alpha", Reachable: true, NodeVersion: "24.15.0", CurrentVersion: "2026.9.1"},
{MachineID: "x", DisplayName: "conflict", Reachable: true, NodeVersion: "24.15.0", Conflict: true},
{MachineID: "n", DisplayName: "node-unknown", Reachable: true},
}
Expand All @@ -50,7 +50,7 @@ func TestPlanSeparatesExclusionsAndBatches(t *testing.T) {
t.Fatalf("預覽句子不符:%q", got.Summary())
}
want := []Target{
{MachineID: "a", DisplayName: "alpha", NodeVersion: "24.15.0", Reachable: true, BatchNo: 1},
{MachineID: "a", DisplayName: "alpha", NodeVersion: "24.15.0", CurrentVersion: "2026.9.1", Reachable: true, BatchNo: 1},
{MachineID: "b", DisplayName: "beta", NodeVersion: "22.22.2", Reachable: true, ExcludedReason: ExcludedMissingPackage},
{MachineID: "x", DisplayName: "conflict", NodeVersion: "24.15.0", Reachable: true, ExcludedReason: ExcludedConflict},
{MachineID: "n", DisplayName: "node-unknown", Reachable: true, ExcludedReason: ExcludedUnknownNode},
Expand Down
5 changes: 3 additions & 2 deletions internal/store/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,17 @@ func (s *Store) DeploymentFacts(members []Machine, now time.Time) ([]rollout.Mac
}
facts := make([]rollout.MachineFacts, 0, len(members))
for _, m := range members {
node := ""
node, current := "", ""
if observation, ok := installs[m.MachineID]; ok && observation.Install != nil {
node = observation.Install.NodeVersion
current = observation.Install.RunningDirVersion
}
// ⚠ 這裡拿的是總覽同一條 state.Derive 的判決,不是另外算「多久沒回報」:
// 兩條算法遲早會對同一台講出不同的話。IdentityConflict 仍算 reachable ——
// 單是以 bearer 對應的 machine_id 開的,名字撞了不影響它領得到哪一張。
judgement := judged[m.MachineID]
facts = append(facts, rollout.MachineFacts{
MachineID: m.MachineID, DisplayName: m.DisplayName, NodeVersion: node,
MachineID: m.MachineID, DisplayName: m.DisplayName, NodeVersion: node, CurrentVersion: current,
Reachable: judgement != state.Unreachable && judgement != state.NeverReported,
Conflict: conflicts[m.MachineID],
Noncompliant: blocked[m.MachineID],
Expand Down
24 changes: 24 additions & 0 deletions internal/web/deployment_actions_web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,27 @@ func TestDeploymentApplyFormFailsClosedWithoutPersistingRawBytes(t *testing.T) {
})
}
}

func TestDeploymentCreateReviewShowsCurrentToTargetVersion(t *testing.T) {
s, _ := newServer(t)
current := "2026.9.1"
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/deployments?view=new", nil)
s.render(rec, req, "deployment_create_review.html", page{
Title: "確認建立 deployment", DeploymentCreateReview: &deploymentCreateReview{
Preview: operator.DeploymentCreatePreviewResult{
Artifact: operator.DeploymentArtifactPreview{Version: "2026.9.3"},
Targets: []operator.DeploymentPlanTargetPreview{
{MachineID: "machine-a", DisplayName: "alpha", BatchNo: 1, CurrentVersion: &current},
{MachineID: "machine-b", DisplayName: "beta", BatchNo: 2},
},
},
},
})
body := rec.Body.String()
for _, want := range []string{"<th>目前版本</th>", "2026.9.1 → 2026.9.3", `<td class="mono">未知</td>`} {
if !strings.Contains(body, want) {
t.Errorf("create review 缺少 %q: %s", want, body)
}
}
}
Loading
Loading