Skip to content

Commit e001542

Browse files
authored
fix(skills): keep workshop revisions atomic (#126485)
* fix(skills): keep workshop revisions atomic * fix(skills): keep proposal artifact paths stable * fix(gateway): preserve proposal inspect schema * fix(gateway): hide proposal generation paths * fix(skills): sync proposal generation files
1 parent 1931666 commit e001542

28 files changed

Lines changed: 889 additions & 293 deletions

‎docs/tools/skill-workshop.md‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ plugin, ClawHub, extra-root, managed, personal-agent, or system skills.
3434
critical findings block apply; warn-level findings remain visible but do not
3535
block it.
3636
- **Recoverable:** apply writes rollback metadata before touching live files.
37+
- **Revision atomic:** create and revise flush a complete immutable proposal
38+
generation, publish it with an atomic rename, then sync its parent directory
39+
where supported before publishing the SQLite record and event together.
40+
Process interruption exposes either the complete previous generation or the
41+
complete new one.
3742
- **Consistent surfaces:** chat, CLI, and Gateway all call the same service.
3843

3944
## Lifecycle
@@ -430,19 +435,34 @@ proposals.
430435
<OPENCLAW_STATE_DIR>/
431436
state/openclaw.sqlite
432437
skill-workshop/proposals/<proposal-id>/
433-
PROPOSAL.md
434-
assets/
435-
examples/
436-
references/
437-
scripts/
438-
templates/
438+
generations/<generation-id>/
439+
PROPOSAL.md
440+
assets/
441+
examples/
442+
references/
443+
scripts/
444+
templates/
439445
```
440446

441447
Default state directory: `~/.openclaw`.
442448

443-
- `state/openclaw.sqlite`: canonical proposal records, lifecycle status, origin attribution, and apply rollback metadata.
444-
- `PROPOSAL.md`: pending skill proposal.
445-
- Support files remain beside `PROPOSAL.md` so operators can review the proposed skill as a normal directory.
449+
- `state/openclaw.sqlite`: canonical proposal records, the active generation
450+
reference, lifecycle status, origin attribution, and apply rollback metadata.
451+
- Each generation contains one `PROPOSAL.md` and all of that revision's support
452+
files. Revision publication never overwrites the active generation in place.
453+
- Generation files are flushed before publication. After the complete bundle is
454+
renamed into place, OpenClaw syncs the `generations/` parent directory where
455+
the platform supports directory flushing, before committing SQLite state.
456+
Platforms that report directory synchronization as unsupported retain atomic
457+
rename and process-interruption safety, but do not claim power-loss durability
458+
for that directory entry.
459+
- Support files remain beside their generation's `PROPOSAL.md` so operators can
460+
review the proposed skill as a normal directory.
461+
462+
Proposals created by older releases can still reference the earlier root-level
463+
`PROPOSAL.md` layout. The stored record identifies that bundle directly; the
464+
next successful revision moves the proposal onto the generation layout and
465+
retires the previous bundle.
446466

447467
`openclaw doctor --fix` imports the previous `proposals.json`, `proposal.json`, and
448468
`rollback.json` metadata into SQLite after verifying each proposal, then removes

‎src/agents/tools/skill-workshop-tool-helpers.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
inspectSkillProposal,
33
resolvePendingSkillProposal,
44
} from "../../skills/workshop/service.js";
5+
import { PROPOSAL_DRAFT_FILE } from "../../skills/workshop/store-record.js";
56
import type {
67
SkillProposalReadResult,
78
SkillProposalRecord,
@@ -115,7 +116,7 @@ export function proposalResult(
115116
kind: proposal.record.kind,
116117
skillName: proposal.record.target.skillName,
117118
skillKey: proposal.record.target.skillKey,
118-
proposalFile: proposal.record.draftFile,
119+
proposalFile: PROPOSAL_DRAFT_FILE,
119120
supportFileCount: proposal.record.supportFiles?.length ?? 0,
120121
targetSkillFile: proposal.record.target.skillFile,
121122
scanState: proposal.record.scan.state,

‎src/agents/tools/skill-workshop-tool-presentation.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { stableStringify } from "@openclaw/normalization-core";
22
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
3+
import { PROPOSAL_DRAFT_FILE } from "../../skills/workshop/store-record.js";
34
import type {
45
SkillProposalEvaluation,
56
SkillProposalManifestEntry,
@@ -125,9 +126,9 @@ export function resolveProposalInspectArtifact(
125126
proposal: SkillProposalReadResult,
126127
artifactPath?: string,
127128
): SkillProposalInspectArtifact | undefined {
128-
if (!artifactPath || artifactPath === proposal.record.draftFile) {
129+
if (!artifactPath || artifactPath === PROPOSAL_DRAFT_FILE) {
129130
return {
130-
path: proposal.record.draftFile,
131+
path: PROPOSAL_DRAFT_FILE,
131132
content: proposal.content,
132133
sizeBytes: Buffer.byteLength(proposal.content),
133134
};
@@ -150,7 +151,7 @@ export function formatProposalInspect(
150151
const evaluation = proposal.record.evaluation;
151152
const evaluationLines = evaluation ? [formatProposalEvaluation(evaluation)] : [];
152153
const artifacts = [
153-
{ path: proposal.record.draftFile, sizeBytes: Buffer.byteLength(proposal.content) },
154+
{ path: PROPOSAL_DRAFT_FILE, sizeBytes: Buffer.byteLength(proposal.content) },
154155
...(proposal.record.supportFiles ?? []).map((file) => ({
155156
path: file.path,
156157
sizeBytes: file.sizeBytes,

‎src/agents/tools/skill-workshop-tool.list.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
22
import path from "node:path";
33
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
44
import { writeWorkspaceSkills } from "../../skills/test-support/e2e-test-helpers.js";
5+
import { readSkillProposalRecord } from "../../skills/workshop/store.js";
56
import {
67
createOpenClawTestState,
78
type OpenClawTestState,
@@ -66,8 +67,12 @@ describe("skill_workshop list", () => {
6667
proposal_content: "# Missing Draft\n",
6768
});
6869
const proposalId = (created.details as { id: string }).id;
70+
const record = await readSkillProposalRecord(proposalId, { env: testState.env });
71+
if (!record) {
72+
throw new Error(`expected stored proposal ${proposalId}`);
73+
}
6974
await fs.rm(
70-
path.join(testState.stateDir, "skill-workshop", "proposals", proposalId, "PROPOSAL.md"),
75+
path.join(testState.stateDir, "skill-workshop", "proposals", proposalId, record.draftFile),
7176
);
7277

7378
const listed = await tool.execute("call-list", { action: "list" });

‎src/agents/tools/skill-workshop-tool.test.ts‎

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ const tempDirs = createTrackedTempDirs();
2727
let testState: OpenClawTestState;
2828
let stateDir = "";
2929

30+
async function proposalArtifactPath(
31+
proposalId: string,
32+
relativePath: string,
33+
options: { stateDir?: string; env?: NodeJS.ProcessEnv } = {},
34+
): Promise<string> {
35+
const record = await readSkillProposalRecord(proposalId, options.env ? { env: options.env } : {});
36+
if (!record) {
37+
throw new Error(`expected stored proposal ${proposalId}`);
38+
}
39+
return path.join(
40+
options.stateDir ?? stateDir,
41+
"skill-workshop",
42+
"proposals",
43+
proposalId,
44+
path.dirname(record.draftFile),
45+
relativePath,
46+
);
47+
}
48+
3049
beforeEach(async () => {
3150
testState = await createOpenClawTestState({
3251
layout: "state-only",
@@ -312,7 +331,10 @@ describe("skill_workshop tool", () => {
312331

313332
await expect(
314333
fs.access(
315-
path.join(isolatedStateDir, "skill-workshop", "proposals", proposalId, "PROPOSAL.md"),
334+
await proposalArtifactPath(proposalId, "PROPOSAL.md", {
335+
stateDir: isolatedStateDir,
336+
env,
337+
}),
316338
),
317339
).resolves.toBeUndefined();
318340
await expect(
@@ -521,6 +543,7 @@ describe("skill_workshop tool", () => {
521543
status: "pending",
522544
kind: "create",
523545
skillKey: "weather-planner",
546+
proposalFile: "PROPOSAL.md",
524547
scanState: "clean",
525548
supportFileCount: 1,
526549
});
@@ -529,27 +552,13 @@ describe("skill_workshop tool", () => {
529552
);
530553
await expect(
531554
fs.readFile(
532-
path.join(
533-
stateDir,
534-
"skill-workshop",
535-
"proposals",
536-
(result.details as { id: string }).id,
537-
"PROPOSAL.md",
538-
),
555+
await proposalArtifactPath((result.details as { id: string }).id, "PROPOSAL.md"),
539556
"utf8",
540557
),
541558
).resolves.toContain("status: proposal");
542559
await expect(
543560
fs
544-
.readFile(
545-
path.join(
546-
stateDir,
547-
"skill-workshop",
548-
"proposals",
549-
(result.details as { id: string }).id,
550-
"PROPOSAL.md",
551-
),
552-
)
561+
.readFile(await proposalArtifactPath((result.details as { id: string }).id, "PROPOSAL.md"))
553562
.then((buffer) => buffer.at(-1)),
554563
).resolves.toBe(0x0a);
555564
await expect(
@@ -563,14 +572,7 @@ describe("skill_workshop tool", () => {
563572
});
564573
await expect(
565574
fs.readFile(
566-
path.join(
567-
stateDir,
568-
"skill-workshop",
569-
"proposals",
570-
(result.details as { id: string }).id,
571-
"references",
572-
"weather.md",
573-
),
575+
await proposalArtifactPath((result.details as { id: string }).id, "references/weather.md"),
574576
"utf8",
575577
),
576578
).resolves.toContain("Use weather API details.");
@@ -615,13 +617,7 @@ describe("skill_workshop tool", () => {
615617
);
616618
await expect(
617619
fs.readFile(
618-
path.join(
619-
stateDir,
620-
"skill-workshop",
621-
"proposals",
622-
(result.details as { id: string }).id,
623-
"PROPOSAL.md",
624-
),
620+
await proposalArtifactPath((result.details as { id: string }).id, "PROPOSAL.md"),
625621
"utf8",
626622
),
627623
).resolves.toContain('version: "v2"');
@@ -733,15 +729,7 @@ describe("skill_workshop tool", () => {
733729

734730
await expect(
735731
fs
736-
.readFile(
737-
path.join(
738-
stateDir,
739-
"skill-workshop",
740-
"proposals",
741-
(result.details as { id: string }).id,
742-
"PROPOSAL.md",
743-
),
744-
)
732+
.readFile(await proposalArtifactPath((result.details as { id: string }).id, "PROPOSAL.md"))
745733
.then((buffer) => buffer.at(-1)),
746734
).resolves.toBe(0x0a);
747735
});

‎src/agents/tools/skill-workshop-tool.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
reviseSkillProposal,
2525
SkillProposalStaleTargetError,
2626
} from "../../skills/workshop/service.js";
27+
import { PROPOSAL_DRAFT_FILE } from "../../skills/workshop/store-record.js";
2728
import type {
2829
SkillProposalOrigin,
2930
SkillProposalReadResult,
@@ -339,7 +340,7 @@ export function createSkillWorkshopTool(options: SkillWorkshopToolOptions): AnyA
339340
const artifact = resolveProposalInspectArtifact(proposal, artifactPath);
340341
if (!artifact) {
341342
const available = [
342-
proposal.record.draftFile,
343+
PROPOSAL_DRAFT_FILE,
343344
...(proposal.record.supportFiles ?? []).map((file) => file.path),
344345
];
345346
throw new ToolInputError(

0 commit comments

Comments
 (0)