Skip to content

Commit 94eb34f

Browse files
authored
fix(skills): require re-review when proposals change (#126156)
* fix(skills): bind workshop decisions to reviewed revisions * chore(i18n): refresh native source inventory * test(skills): align revision proof with inspect projection * test: align skill workshop regression fixtures * fix(ui): align workshop revision admission proof * fix(ui): keep revision errors out of startup
1 parent b514fca commit 94eb34f

63 files changed

Lines changed: 1699 additions & 182 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/.i18n/native-source.json‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/ios/Sources/Design/IPadSkillWorkshopScreen.swift‎

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import OpenClawKit
2+
import OpenClawProtocol
23
import SwiftUI
34

45
struct IPadSkillWorkshopScreen: View {
@@ -857,9 +858,9 @@ struct IPadSkillWorkshopScreen: View {
857858
do {
858859
let data = try await request(
859860
method: "skills.proposals.inspect",
860-
params: IPadSkillProposalInspectParams(
861-
agentId: selectedAgentParam,
862-
proposalId: proposalID),
861+
params: SkillsProposalInspectParams(
862+
agentid: selectedAgentParam,
863+
proposalid: proposalID),
863864
timeoutSeconds: 20)
864865
let response = try JSONDecoder().decode(IPadSkillProposalInspectResponse.self, from: data)
865866
self.merge(IPadSkillProposal(inspect: response, previous: self.proposals.first { $0.id == proposalID }))
@@ -870,25 +871,29 @@ struct IPadSkillWorkshopScreen: View {
870871

871872
private func run(_ action: IPadSkillProposalAction.Kind, proposal: IPadSkillProposal) async {
872873
guard self.canApplyProposalMutations, self.busyAction == nil else { return }
873-
self.busyAction = IPadSkillProposalAction(kind: action, proposalID: proposal.id)
874+
guard let preparedAction = IPadSkillProposalAction(kind: action, proposal: proposal) else {
875+
self.noticeText = nil
876+
self.errorText = String(localized: "Review the proposal draft before applying or rejecting it.")
877+
return
878+
}
879+
self.busyAction = preparedAction
874880
self.errorText = nil
875881
self.noticeText = nil
876882
defer { self.busyAction = nil }
877883

878884
do {
879-
let method = action == .apply ? "skills.proposals.apply" : "skills.proposals.reject"
880885
_ = try await self.request(
881-
method: method,
882-
params: IPadSkillProposalInspectParams(
883-
agentId: self.selectedAgentParam,
884-
proposalId: proposal.id),
886+
method: preparedAction.method,
887+
params: preparedAction.params(agentID: self.selectedAgentParam),
885888
timeoutSeconds: 30)
886-
self.noticeText = action == .apply
889+
self.noticeText = preparedAction.kind == .apply
887890
? String(localized: "Proposal applied.")
888891
: String(localized: "Proposal rejected.")
889892
await self.loadProposals(force: true)
890893
} catch {
891-
self.errorText = Self.message(for: error)
894+
let actionError = Self.message(for: error)
895+
await self.loadProposals(force: true)
896+
self.errorText = actionError
892897
}
893898
}
894899

@@ -1128,6 +1133,25 @@ struct IPadSkillProposalAction: Equatable {
11281133

11291134
let kind: Kind
11301135
let proposalID: String
1136+
let revisionHash: String
1137+
1138+
init?(kind: Kind, proposal: IPadSkillProposal) {
1139+
guard let revisionHash = proposal.revisionHash else { return nil }
1140+
self.kind = kind
1141+
self.proposalID = proposal.id
1142+
self.revisionHash = revisionHash
1143+
}
1144+
1145+
var method: String {
1146+
self.kind == .apply ? "skills.proposals.apply" : "skills.proposals.reject"
1147+
}
1148+
1149+
func params(agentID: String?) -> SkillsProposalDecisionParams {
1150+
SkillsProposalDecisionParams(
1151+
agentid: agentID,
1152+
proposalid: self.proposalID,
1153+
expectedrevisionhash: self.revisionHash)
1154+
}
11311155
}
11321156

11331157
private struct IPadSkillProposalManifest: Decodable {
@@ -1154,13 +1178,9 @@ private struct IPadSkillProposalListParams: Encodable {
11541178
let agentId: String?
11551179
}
11561180

1157-
private struct IPadSkillProposalInspectParams: Encodable {
1158-
let agentId: String?
1159-
let proposalId: String
1160-
}
1161-
11621181
struct IPadSkillProposalInspectResponse: Decodable {
11631182
let record: IPadSkillProposalRecord
1183+
let revisionHash: String?
11641184
let content: String
11651185
let supportFiles: [IPadSkillProposalSupportFile]?
11661186
}
@@ -1192,6 +1212,7 @@ struct IPadSkillProposal: Identifiable {
11921212
let skillName: String
11931213
let skillKey: String
11941214
let updatedAtMs: Double
1215+
let revisionHash: String?
11951216
var content: String?
11961217
var supportFiles: [IPadSkillProposalSupportFile]
11971218

@@ -1203,8 +1224,10 @@ struct IPadSkillProposal: Identifiable {
12031224
self.skillName = entry.skillName
12041225
self.skillKey = entry.skillKey
12051226
self.updatedAtMs = Self.parseDate(entry.updatedAt)
1206-
self.content = previous?.updatedAtMs == self.updatedAtMs ? previous?.content : nil
1207-
self.supportFiles = previous?.updatedAtMs == self.updatedAtMs ? previous?.supportFiles ?? [] : []
1227+
let isSameRevision = previous?.updatedAtMs == self.updatedAtMs
1228+
self.revisionHash = isSameRevision ? previous?.revisionHash : nil
1229+
self.content = isSameRevision ? previous?.content : nil
1230+
self.supportFiles = isSameRevision ? previous?.supportFiles ?? [] : []
12081231
}
12091232

12101233
init(inspect: IPadSkillProposalInspectResponse, previous: IPadSkillProposal?) {
@@ -1216,6 +1239,7 @@ struct IPadSkillProposal: Identifiable {
12161239
self.skillName = record.target.skillName
12171240
self.skillKey = record.target.skillKey
12181241
self.updatedAtMs = Self.parseDate(record.updatedAt)
1242+
self.revisionHash = inspect.revisionHash
12191243
self.content = Self.stripFrontmatter(inspect.content)
12201244
self.supportFiles = inspect.supportFiles ?? previous?.supportFiles ?? []
12211245
}

‎apps/ios/Tests/RootTabsPresentationTests.swift‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,33 @@ struct RootTabsPresentationTests {
252252
#expect(!IPadSkillWorkshopScreen.shouldEnableProposalMutation(canWrite: false, hasOperatorAdminScope: true))
253253
}
254254

255+
@Test func `skill workshop actions carry the reviewed revision hash`() throws {
256+
let revisionHash = String(repeating: "a", count: 64)
257+
let proposal = Self.skillWorkshopProposal(revisionHash: revisionHash)
258+
let apply = try #require(IPadSkillProposalAction(kind: .apply, proposal: proposal))
259+
let reject = try #require(IPadSkillProposalAction(kind: .reject, proposal: proposal))
260+
261+
for (action, method) in [
262+
(apply, "skills.proposals.apply"),
263+
(reject, "skills.proposals.reject"),
264+
] {
265+
let encoded = try #require(
266+
JSONSerialization.jsonObject(
267+
with: JSONEncoder().encode(action.params(agentID: "main"))) as? [String: Any])
268+
269+
#expect(action.method == method)
270+
#expect(encoded["agentId"] as? String == "main")
271+
#expect(encoded["proposalId"] as? String == proposal.id)
272+
#expect(encoded["expectedRevisionHash"] as? String == revisionHash)
273+
}
274+
}
275+
276+
@Test func `skill workshop actions require an inspected revision hash`() {
277+
#expect(IPadSkillProposalAction(
278+
kind: .apply,
279+
proposal: Self.skillWorkshopProposal(revisionHash: nil)) == nil)
280+
}
281+
255282
@Test func `skill workshop held filter includes quarantined and stale`() {
256283
#expect(IPadSkillWorkshopScreen.proposalStatusFilters.contains("held"))
257284
#expect(IPadSkillWorkshopScreen.proposalStatusMatchesFilter(status: "quarantined", filter: "held"))
@@ -1059,4 +1086,22 @@ struct RootTabsPresentationTests {
10591086
state: [:],
10601087
lastrunstatus: AnyCodable(status))
10611088
}
1089+
1090+
private static func skillWorkshopProposal(revisionHash: String?) -> IPadSkillProposal {
1091+
IPadSkillProposal(
1092+
inspect: IPadSkillProposalInspectResponse(
1093+
record: IPadSkillProposalRecord(
1094+
id: "proposal-1",
1095+
status: "pending",
1096+
title: "Reviewed proposal",
1097+
description: "A reviewed Skill Workshop proposal.",
1098+
updatedAt: "2026-08-18T12:00:00Z",
1099+
target: IPadSkillProposalTarget(
1100+
skillName: "reviewed-skill",
1101+
skillKey: "reviewed-skill")),
1102+
revisionHash: revisionHash,
1103+
content: "# Reviewed skill",
1104+
supportFiles: nil),
1105+
previous: nil)
1106+
}
10621107
}

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,28 @@ public struct McpAppViewExpiredErrorDetails: Codable, Sendable {
17851785
}
17861786
}
17871787

1788+
public struct SkillProposalRevisionChangedErrorDetails: Codable, Sendable {
1789+
public let code: String
1790+
public let expectedrevisionhash: String
1791+
public let currentrevisionhash: String
1792+
1793+
public init(
1794+
code: String,
1795+
expectedrevisionhash: String,
1796+
currentrevisionhash: String)
1797+
{
1798+
self.code = code
1799+
self.expectedrevisionhash = expectedrevisionhash
1800+
self.currentrevisionhash = currentrevisionhash
1801+
}
1802+
1803+
private enum CodingKeys: String, CodingKey {
1804+
case code
1805+
case expectedrevisionhash = "expectedRevisionHash"
1806+
case currentrevisionhash = "currentRevisionHash"
1807+
}
1808+
}
1809+
17881810
public struct UnknownAgentIdErrorDetails: Codable, Sendable {
17891811
public let code: String
17901812
public let agentid: String
@@ -15786,7 +15808,7 @@ public struct SkillsProposalRequestRevisionParams: Codable, Sendable {
1578615808
public let agentid: String?
1578715809
public let targetagentid: String?
1578815810
public let proposalid: String
15789-
public let expectedrevisionhash: String?
15811+
public let expectedrevisionhash: String
1579015812
public let instructions: String
1579115813
public let sessionkey: String
1579215814
public let sessionid: String?
@@ -15796,7 +15818,7 @@ public struct SkillsProposalRequestRevisionParams: Codable, Sendable {
1579615818
agentid: String? = nil,
1579715819
targetagentid: String? = nil,
1579815820
proposalid: String,
15799-
expectedrevisionhash: String? = nil,
15821+
expectedrevisionhash: String,
1580015822
instructions: String,
1580115823
sessionkey: String,
1580215824
sessionid: String? = nil,
@@ -15842,6 +15864,36 @@ public struct SkillsProposalRequestRevisionResult: Codable, Sendable {
1584215864
}
1584315865
}
1584415866

15867+
public struct SkillsProposalDecisionParams: Codable, Sendable {
15868+
public let agentid: String?
15869+
public let proposalid: String
15870+
public let expectedrevisionhash: String
15871+
public let correlationid: String?
15872+
public let reason: String?
15873+
15874+
public init(
15875+
agentid: String? = nil,
15876+
proposalid: String,
15877+
expectedrevisionhash: String,
15878+
correlationid: String? = nil,
15879+
reason: String? = nil)
15880+
{
15881+
self.agentid = agentid
15882+
self.proposalid = proposalid
15883+
self.expectedrevisionhash = expectedrevisionhash
15884+
self.correlationid = correlationid
15885+
self.reason = reason
15886+
}
15887+
15888+
private enum CodingKeys: String, CodingKey {
15889+
case agentid = "agentId"
15890+
case proposalid = "proposalId"
15891+
case expectedrevisionhash = "expectedRevisionHash"
15892+
case correlationid = "correlationId"
15893+
case reason
15894+
}
15895+
}
15896+
1584515897
public struct SkillsProposalActionParams: Codable, Sendable {
1584615898
public let agentid: String?
1584715899
public let proposalid: String
@@ -20822,6 +20874,7 @@ public enum GatewayErrorDetails: Codable, Sendable {
2082220874
case missingScope(MissingScopeErrorDetails)
2082320875
case mcpAppViewExpired(McpAppViewExpiredErrorDetails)
2082420876
case userPrefsLimitExceeded(UserPrefsLimitExceededErrorDetails)
20877+
case skillProposalRevisionChanged(SkillProposalRevisionChangedErrorDetails)
2082520878
case projectCloneFailed(ProjectCloneErrorDetails)
2082620879
case unknownAgentId(UnknownAgentIdErrorDetails)
2082720880
case wizardNotFound(WizardNotFoundErrorDetails)
@@ -20842,6 +20895,7 @@ public enum GatewayErrorDetails: Codable, Sendable {
2084220895
case .missingScope(let value): value.code
2084320896
case .mcpAppViewExpired(let value): value.code
2084420897
case .userPrefsLimitExceeded(let value): value.code
20898+
case .skillProposalRevisionChanged(let value): value.code
2084520899
case .projectCloneFailed(let value): value.code
2084620900
case .unknownAgentId(let value): value.code
2084720901
case .wizardNotFound(let value): value.code
@@ -20870,6 +20924,7 @@ public enum GatewayErrorDetails: Codable, Sendable {
2087020924
case "MISSING_SCOPE": self = try .missingScope(MissingScopeErrorDetails(from: decoder))
2087120925
case "MCP_APP_VIEW_EXPIRED": self = try .mcpAppViewExpired(McpAppViewExpiredErrorDetails(from: decoder))
2087220926
case "USER_PREFS_LIMIT_EXCEEDED": self = try .userPrefsLimitExceeded(UserPrefsLimitExceededErrorDetails(from: decoder))
20927+
case "SKILL_PROPOSAL_REVISION_CHANGED": self = try .skillProposalRevisionChanged(SkillProposalRevisionChangedErrorDetails(from: decoder))
2087320928
case "PROJECT_CLONE_FAILED": self = try .projectCloneFailed(ProjectCloneErrorDetails(from: decoder))
2087420929
case "UNKNOWN_AGENT_ID": self = try .unknownAgentId(UnknownAgentIdErrorDetails(from: decoder))
2087520930
case "WIZARD_NOT_FOUND": self = try .wizardNotFound(WizardNotFoundErrorDetails(from: decoder))
@@ -20888,6 +20943,7 @@ public enum GatewayErrorDetails: Codable, Sendable {
2088820943
case .missingScope(let value): try value.encode(to: encoder)
2088920944
case .mcpAppViewExpired(let value): try value.encode(to: encoder)
2089020945
case .userPrefsLimitExceeded(let value): try value.encode(to: encoder)
20946+
case .skillProposalRevisionChanged(let value): try value.encode(to: encoder)
2089120947
case .projectCloneFailed(let value): try value.encode(to: encoder)
2089220948
case .unknownAgentId(let value): try value.encode(to: encoder)
2089320949
case .wizardNotFound(let value): try value.encode(to: encoder)

‎packages/gateway-protocol/src/error-details.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ export * from "./system-agent-error-details.js";
44
export {
55
ErrorCodes,
66
GatewayErrorDetailCodes,
7+
buildSkillProposalRevisionChangedErrorDetails,
78
isMcpAppViewExpiredError,
89
readCronJobNotFoundError,
910
readMissingScopeError,
1011
readMissingScopeErrorDetails,
12+
readSkillProposalRevisionChangedError,
1113
} from "./gateway-error-details.js";
1214
export type {
1315
CronJobNotFoundErrorDetails,
1416
GatewayErrorDetails,
1517
McpAppViewExpiredErrorDetails,
1618
MissingScopeErrorDetails,
19+
SkillProposalRevisionChangedErrorDetails,
1720
UserPrefsLimitExceededErrorDetails,
1821
ProjectCloneErrorDetails,
1922
ProjectCloneFailureCause,
@@ -25,6 +28,7 @@ export {
2528
MissingScopeErrorDetailsSchema,
2629
UserPrefsLimitExceededErrorDetailsSchema,
2730
ProjectCloneErrorDetailsSchema,
31+
SkillProposalRevisionChangedErrorDetailsSchema,
2832
WizardNotFoundErrorDetailsSchema,
2933
buildMissingScopeErrorDetails,
3034
errorShape,

0 commit comments

Comments
 (0)