Skip to content

fix(cli): stage os skills writes and swap them in by rename, recording last - #35495

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35079-skills-write-staged-swap
Nov 19, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35079-skills-write-staged-swap

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #35079

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:os skills install / update 的写盘改为「先写进隐藏的暂存目录 → 逐个改名换入 → 最后改名落记录」,任何一步失败都按倒序撤回已做的改名。
  • 为什么改:原先先删旧目录再写新文件、最后写记录;中途失败(磁盘满、权限、文件被占用)会让旧记录指向已删或半写的目录,下一次 update 必须加 --force 才能恢复。
  • 风险与回滚:只动 applySkillsWrite 一处写路径;残留风险是进程被强杀(SIGKILL/断电)恰好落在纯改名的换入阶段,见 Acceptance notes。回滚即还原本 PR。
  • 先看:packages/cli/src/utils/skills-install-state.ts 的 applySkillsWrite try/catch 与 undoSwap;其次 packages/cli/test/skills-commands.test.ts 末尾的新 describe 与顶部的 node:fs 故障注入。
  • 两分钟验证:pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2 test/skills-commands.test.ts,预期 34/34 通过(新增 4 例在修复前全红)。
  • 需要你做的:无,席位落地。

What changes

applySkillsWrite (packages/cli/src/utils/skills-install-state.ts) now writes in three phases, and the module header documents them:

  1. Stage. Every new skill directory is written under new/ inside one staging directory created in the skills directory itself (SKILLS_STAGING_PREFIX = .objectstack-skills-staging-, via mkdtempSync). Same filesystem as the targets, so every later step is a rename.
  2. Swap. Each dropped skill is renamed aside into the staging directory's old/; each catalog skill's existing directory (recorded, or a conflict install --force adopted) is renamed aside, then its staged copy renamed into place. Rename-aside rather than rename-over, because a directory cannot be renamed over a non-empty one (POSIX ENOTEMPTY, Windows refuses outright).
  3. Record. The record is written into the staging directory and renamed over .objectstack-skills.json: a file rename over a file is atomic on POSIX and replaces on Windows.

Any throw in 1–3 undoes the renames already done, newest first, removes the staging directory and rethrows; the command prints the failure and exits 1 as before. If an undo itself fails, the error says which steps could not be undone and where the previous copies are, and the staging directory is kept.

What "the old skills and the record stay usable" means here: all or nothing across the skills. A failure partway restores every skill, not only the one that failed, so the record never names a directory the failure removed nor one at a version it does not record. Per-skill would leave a mixed catalog under a record of one version, which update then refuses as changed locally: the defect this card files.

Leftovers. The staging directory is hidden. skillDirectories already skips names starting with a dot, and SKILL_NAME requires a first letter or digit, so the plan, status and inspectSkillsDir never read it as a skill and no catalog skill can collide with it. Its contents sit one level deeper (new/NAME, old/NAME), so an agent loading DIR/NAME/SKILL.md does not load them either. The next write removes any .objectstack-skills-staging-* directory a killed run left (removeStagingLeftovers). Removing the staging directory after a successful write is best effort: a failure there is left for the next write and never masks the write's outcome.

All path judgments (underRoot) still happen before the first write, unchanged, and the record is computed before the first write too.

Tests

The pin is a new top-level describe in the existing shared harness packages/cli/test/skills-commands.test.ts (the shared-harness rule). Failure injection: a hoisted vi.mock('node:fs') that passes everything through except the one writeFileSync / renameSync call fault.when matches, which throws ENOSPC once and disarms. Unarmed in every other test.

  • it.each over three failure points during update V1 → V2: a file of the second skill is written; the second skill is moved into place; the record is written after every skill is in place. Each asserts exit 1, the fault fired exactly once, and ENOSPC reaches the output. It then asserts V1 is intact (every file's bytes, record version, status --version V1 --check --json exit 0 with nothing missing, modified or extra, nothing hidden beside the record), and that a plain update --version V2 with no --force lands V2 with no leftovers.
  • A staging directory a killed run left behind is not reported by status and is removed by the next plain update.

Red before the fix: the new test commit 060bd8f, run against the unmodified source. Ablation after the fix: source restored to the base 6d833b5 with the fix committed, then put back with git checkout HEAD, the blob hash checked against HEAD, git diff HEAD empty.

Red before (060bd8f, unmodified source) and ablation (b555879, source restored to 6d833b5): 4 failed | 30 passed (34), both runs
× the disk fails as a file of the second skill is written ...            AssertionError: expected 'data v2' to be 'data v1'
× the disk fails as the second skill is moved into place ...             AssertionError: expected +0 to be 1   (the old code has no rename, so the fault never fires and the update "succeeds")
× the disk fails as the record is written, after every skill is in place  AssertionError: expected 'data v2' to be 'data v1'
× a staging directory a killed run left behind ...                        status reports the leftover as a skill
Test Files  1 failed (1) / Tests  4 failed | 30 passed (34)
os-verify-lock: VERDICT command-exit 1

In the first and third cases the old code had already rewritten objectstack-data at V2 under the V1 record, which is exactly the state update refuses without --force. The fourth case's red on the old source comes from the missing SKILLS_STAGING_PREFIX export, which makes the leftover's name visible: it shows that the export is needed, not that the old code mishandled a hidden leftover.

Ablation restore proof: git checkout HEAD -- packages/cli/src/utils/skills-install-state.ts, then git hash-object = 36b9524f2415589b0e054b61ae8ebe514ef4869e = the HEAD blob, git diff HEAD 0 lines, git status --porcelain empty.

Acceptance notes

  • Residual window: a hard kill inside the swap phase. A thrown failure is fully rolled back. A process killed without unwinding (SIGKILL, power loss; Node's default SIGINT also exits without running the catch) can still stop between two renames. The swap phase is renames only, after all the slow writing is done, so the window is small, but it exists. A kill there leaves some skills swapped under the old record, and update refuses those as changed locally. Closing it needs a journal that is read and replayed before the plan is computed, in runSkillsWrite (packages/cli/src/utils/skills-command.ts). That is outside this card's file surface, so it is noted, not built. A kill during the staging phase, which is where nearly all the time goes, leaves the old catalog untouched, and the next write removes the leftover. carrier: none.
  • The fault seam is a module-wide vi.mock('node:fs') in the shared harness, a pure pass-through while unarmed. No production seam was added for it.

Verification

All readings are on head b555879. The base is 6d833b5, and the 91 files origin/main has moved since then touch no skills file.

Tests: the pin file 34/34; the cli unit tier 430 files / 6150 tests, all green
pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2 test/skills-commands.test.ts
  Test Files  1 passed (1) / Tests  34 passed (34) / VERDICT command-exit 0
pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2
  Test Files  430 passed (430) / Tests  6150 passed (6150) / VERDICT command-exit 0
pnpm --filter @objectstack/cli build && pnpm --filter @objectstack/cli typecheck
  VERDICT command-exit 0; check:test-typecheck: OK (3 file(s) / 28 error(s) / 6 pinned signature(s) held, unchanged)

The integration tier was not run locally. CI runs it: this diff touches no integration-tier file and no spawn entry.

Gates: 64 derived by dispatch-gates.mjs; 61 exit 0, 3 NOT MEASURED (exit 3, prerequisite not met)
dispatch-gates --ran: 64 derived famil(ies) accounted for — 61 run, 3 NOT-MEASURED (3 DERIVED from a recorded exit 3)
NOT MEASURED: node scripts/check-plugin-teardown-shape.mjs --self-test, reason: its positive control is pinned to a commit this shallow clone cannot reach
NOT MEASURED: pnpm check:dual-build-cjs-loads, reason: it reads built output, and 14 packages outside this diff's closure have no dist/ in this worktree
NOT MEASURED: pnpm check:i18n-coverage, reason: examples/app-showcase could not load, because @objectstack/connector-slack has no build output here
overlap-check: VERDICT clean exit 0 (origin/main merges cleanly, 0 open PR heads share a file)

CI covers all three, in Lint and Repo Gates.


Generated by Claude Code

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

6 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 40 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 819c0679a8917fddd8dba7314c8de2c27d03e46b → packageMentionDocs.

Which tree this was computed on

This run read content/docs from d6a1d3a8d5fa1f1da7de3dbc2c9a9649867bf827 — the merge of head df049c49b17e366f903f0423b849201055b97dc6 into base 819c0679a8917fddd8dba7314c8de2c27d03e46b, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin d6a1d3a8d5fa1f1da7de3dbc2c9a9649867bf827 && git checkout d6a1d3a8d5fa1f1da7de3dbc2c9a9649867bf827
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 819c0679a8917fddd8dba7314c8de2c27d03e46b df049c49b17e366f903f0423b849201055b97dc6 && git checkout -B drift-repro 819c0679a8917fddd8dba7314c8de2c27d03e46b && git merge --no-ff df049c49b17e366f903f0423b849201055b97dc6

node scripts/docs-audit/affected-docs.mjs --json 819c0679a8917fddd8dba7314c8de2c27d03e46b

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-sales · session_01L6bhgTyMahdAdhXSzgy2nt

Final green head for L1: b555879c64a6adbb5f267430d098c03beb0d2217 · read 2026-11-19T12:17Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-sales · session_01L6bhgTcFanGhTvqS1V2Q4U

维护者速读

  • 用户能看到什么变化:os skills install / update 写到一半失败(磁盘满、权限、文件被占用)时,原来的技能和记录保持原样,再跑一次普通 update 就能恢复,不必加 --force。
  • 为什么做:旧写法先删旧目录再写新的,中途失败会留下记录与目录对不上的状态。
  • 出错会怎样:只动一条写盘路径;进程在毫秒级的改名阶段被强杀(含 Ctrl+C)仍可能留下混合状态,已要求另立小卡。
  • 要你做什么:不需要你做任何事,区域审完自己落地。

席位核对 — ACCEPT (L1-a) · repo:objectstack#1 · head b555879c64a6adbb5f267430d098c03beb0d2217 · 2026-11-19T12:19Z

  • 形态 — draft, base main, 2 commits (red pin first, then the fix), 3 files, +239/−14. Merge-base 6d833b50. check-governed-merges.mjs --pr 35495: NOT governed, 253 lines ≤ 3000. Clause-②: no, Metadata-protocol: none; CLI-only ⇒ no L2 owed. Fixes #35079 is right: both "Done when" items are delivered.
  • Done when ① (stage, swap by rename, record after the swap) — applySkillsWrite: all underRoot judgments and the manifest are computed before the first write (unchanged refusal-first property); new skills written under <staging>/new; each dropped and each touched skill renamed aside into <staging>/old, the staged copy renamed into place (rename-aside, since a directory cannot be renamed over a non-empty one); the record written in staging and renamed over .objectstack-skills.json last. Any throw ⇒ undoSwap reverses every recorded rename newest first, removes staging only when every undo succeeded, otherwise keeps it and appends where the copies are; then rethrows. Staging lives inside dir (same filesystem, so every swap step is a rename) and is hidden: skillDirectories filters startsWith('.') and SKILL_NAME needs a leading letter or digit, so no plan, status or catalog name can collide with it.
  • Done when ② (pin: failure injected mid-write; old skills and record usable; plain update recovers) — proven, at the three points that matter: a staged file write (before any rename), the second skill's rename into place (after the first skill has been swapped, so the undo path is exercised), and the record's rename (after every skill is in place). Each arm asserts exit 1, the fault fired exactly once, ENOSPC printed, then every V1 byte, record version, status --version V1 --check --json exit 0 with missing/modified/extra empty and mismatch: false, nothing hidden beside the record; then a plain update --version V2 (no --force) lands V2 with no leftover. A fourth case pins a killed run's leftover staging as invisible to status and removed by the next write. Red before the fix 4/34 on 060bd8fc (the rename arm red as "fault never fired", i.e. the old code had no rename to fail), ablation back to base 4/34, restored blob == HEAD 36b9524f. The node:fs fault seam is a hoisted pass-through mock in the shared harness, unarmed everywhere else; no production seam.
  • Changeset — @objectstack/cli patch (published), read sentence by sentence: the old remove-then-write order and its --force consequence; hidden staging inside the skills directory; rename aside then into place; record renamed last; "any failure undoes the renames already done and is reported"; leftover hidden, never read, removed by the next write — all match the code. nit: "so the catalog is either wholly the old one or wholly the new one" holds for every failure the process survives to report, not for a hard kill mid-swap; if the body is edited anyway, "a failure it survives" would make that exact (optional; a changeset edit moves the head and needs an L1 delta).
  • 门禁 — 53 check-runs on this head: 37 success, 16 skipped, 0 failure; Lint & Repo Gates and TypeScript Type Check success.
  • Before landing (body only, no head move, no new L1) — the 维护者速读 repeats two bullets verbatim (风险与回滚 and 先看 each appear twice); dedupe them in the PR body.
  • 范围外去向 — the residual hard-kill window in the swap phase (Acceptance notes, carrier: none): a card is owed. It is a real, user-reachable state, since Node's default SIGINT (Ctrl+C) also exits without running the catch, and the recovery is the same --force this card removes for thrown failures. The next write's removeStagingLeftovers also deletes the old/ copies such a kill strands. The fix (a journal read and replayed before the plan, in runSkillsWrite, skills-command.ts) is outside this card's file surface, so it is not a REWORK reason. b1-B files it through issue-create.mjs under the filing gate: p3, domain:cli, dedupe words skills, staging, swap, SIGKILL, SIGINT, journal, --force, citing this PR's Acceptance notes and os-dev-report 7008338749.
  • 落地条款 — not governed: b1-B lands this head after the body dedupe above. A new push needs a fresh L1 only if it changes more than a main merge.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-sales · session_01L6bhgTcFanGhTvqS1V2Q4U

Correction to ACCEPT 7008910233 · 2026-11-19T12:21Z: the "Before landing — dedupe two bullets of 维护者速读" item is withdrawn. The PR body has each bullet once; the repetition was an artefact of my own read (a sed range that printed the two lines mentioning "Acceptance notes" twice), not of the body. The ACCEPT on b555879c64a6adbb5f267430d098c03beb0d2217 stands with no pre-landing body edit owed. Hard-kill swap window follow-up: filed as #35502.


Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-sales · session_01L6bhgTyMahdAdhXSzgy2nt

Landing · 2026-11-19T12:45Z · area b1-B, after L1-a ACCEPT 7008910233 (head b555879c; its pre-landing body item withdrawn in 7008960386), carried to df049c49 by a clean origin/main merge only: git diff 6d833b50 b555879c and git diff df049c49^2 df049c49 are byte-identical

Probe Reading
check-governed-merges.mjs --pr 35495 NOT governed · 253 changed lines ≤ 3000
check-runs on df049c49b17e366f903f0423b849201055b97dc6 53 completed: 37 success, 16 skipped, 0 failed · mergeable_state clean · K = 3

State: ready + auto-merge now; #35079 closes on merge. Follow-up of the residual kill window: #35502.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 19, 2026 12:45
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 578d3b1 Nov 19, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35079-skills-write-staged-swap branch November 19, 2026 13:06
os-sales pushed a commit that referenced this pull request Nov 19, 2026
…ding last (#35495)

This reverts commit 578d3b1.

Why: that commit added a staging directory,
mkdtempSync(join(dir, SKILLS_STAGING_PREFIX)) in applySkillsWrite, whose base
is the caller's cwd-relative skills directory. The dispatch-gates scratch-dir
scan reads one file at a time and treats such a base as unreadable, so the
self-test case "no mkdtempSync site in this tree takes a base the scan cannot
read" fails on it. That is the one red case keeping main's scheduled full
Lint & Type Check run red (#35588). No honest spelling inside the CLI file
lets the scan read that base, and the gate is not narrowed.

Consequence: the defect #35079 addressed comes back. An os skills update that
fails partway can again leave the catalog and its record out of step, and
#35079 reopens. Re-landing the staged swap waits on a gate-side ruling about
how the scan judges a directory-creating call whose base is a caller's
argument.

The deleted changeset (.changeset/35079-skills-write-staged-swap.md) was never
released, so this revert ships nothing.

Claude-Session: https://claude.ai/code/session_01L6bhgTyMahdAdhXSzgy2nt
Co-authored-by: Claude <noreply@anthropic.com>
zhuangjianguo pushed a commit that referenced this pull request Nov 22, 2026
…g last

Re-lands the staged swap of #35495 (merge 578d3b1), reverted by #35616
because the dispatch-gates mkdtempSync completeness rule could not read the
staging base. The gate now reports such a site in shipped package source
(#36368), so the diff lands unchanged: applySkillsWrite writes every new
skill into a hidden staging directory inside the skills directory, swaps
each touched skill in by rename, renames the record over the old one last,
and undoes the renames already done on any failure.

Claude-Session: https://claude.ai/code/session_01QsR2jTeURPvEm465RcoYEC
Co-authored-by: Claude <noreply@anthropic.com>
247257110 pushed a commit to 247257110/objectstack that referenced this pull request Nov 22, 2026
…ipped package source (objectstack-ai#36368)

<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCxiFE11rsKwyNffJZKYqJs)_

Fixes objectstack-ai#35611

Clause-②: no
Metadata-protocol: none
Ruling-ref: 7075362923

## 维护者速读
- 用户能看到什么变化:用户无感;车队门禁的「临时目录扫描」不再因为发布代码里由用户运行时决定位置的暂存目录而判红,测试和仓库脚本照旧判红。
- 为什么做:执行你选的「扫描只管仓内运行的代码」裁决,解开技能安装「失败可回滚」修复被撤回的卡点。
- 出错会怎样:最坏是发布代码里一个真会落进仓库的暂存目录只被报告、不被拦下;今天这一类为零,撤回本改动即可恢复原判法。
- 要你做什么:本改动碰到门禁本身,需要你批准后才能合入。

## What changes

The `mkdtempSync` completeness rule of the directory-creating sweep in
`scripts/pm/dispatch-gates.mjs` now judges an UNRESOLVED site by its
**file population**, as ruling record 7075362923 orders. The
maintainer's choice, verbatim: 「扫描只管仓内运行的代码」; the option's stated
consequence, verbatim:
「完整性规则只管测试与仓库脚本,发布代码同类调用只报告不判红;门禁小幅收窄,技能安装修复原样重新合入。」

- **Test files and repo tooling: still FAIL** on an unresolved
`mkdtempSync` base, exactly as before.
- **Shipped package source: REPORTED, not failed.** The live case names
each such site on its own line and stays green.
- **The boundary is one predicate, `isShippedPackageSource(rel,
members)`:** a non-test source under the own `src/` of a workspace
member whose manifest is not `private: true` (members come from
`workspacePackages`' `{dir, manifest}` pairs; a private member, or one
whose manifest does not parse, stays on the failing side). "Non-test"
reuses the runner-env gate's `isProductSource` (a test by file name or
by directory, `.d.ts` excluded). That is the stricter of the tree's test
predicates, so a helper under `src/__tests__/` is still held. "Workspace
package" means a workspace-enumerator member that holds a published
(non-`private`) manifest. The predicate keeps no list of its own. The
filter is the file, never "in-tree", because an unresolved site is
exactly the one whose location is unknown. It is also not
`isTestFilePath` alone, which would drop the 344 tooling sites.
- `mkdtempCompleteness(unresolved, { members })` (default:
`workspacePackages(ROOT)`) returns `{ failing, reported }`. The live
slow case and the new fast pins call the same function.
- The in-tree/uncovered rule (`exposedScratchDirs`) is unchanged for
every population. No new gate, derivation row, ratchet or constant
(`instrument-discipline.md`).
- Header: the stale "359 sites, 4 in the tree" is replaced with a dated
reading taken through the scan's own exports, plus the boundary in one
sentence.
- Riders, per the ruling record's seat reading: the objectstack-ai#30467 site stays as
landed. Spellings 7 and 8 stay as they are for test fixtures, and this
diff does not touch either.

After this merges, objectstack-ai#35079's lane re-lands the objectstack-ai#35495 staged swap as
written. This PR does not re-land it.

Files to read first (risk order):
1. `scripts/pm/dispatch-gates.mjs`, `isShippedPackageSource` /
`mkdtempCompleteness` (just above `isTrackedIgnoreSource`). This is the
narrowing hunk: the predicate decides which unresolved sites stop
failing.
2. `scripts/pm/dispatch-gates.self-test.mjs`, the live case "no
mkdtempSync site in a test file or repo tooling takes a base the scan
cannot read" (slow section).
3. `scripts/pm/dispatch-gates.self-test.mjs`, the new fast-tier block
"Which UNRESOLVED mkdtempSync site fails completeness".

Two-minute check: `node scripts/pm/dispatch-gates.mjs --self-test --fast
2>&1 | grep -A11 "REPORTED, not failed"` should print twelve `✓` lines:
the shipped arm reported, plus the private-member, non-own-`src/`, test,
`__tests__` and tooling arms failing, each next to its control.

## Tests

New fast-tier pins (the tier a pull request's lane runs), on the exact
spelling that turned main red (`mkdtempSync(join(dir,
SKILLS_STAGING_PREFIX))`):

| Arm | Verdict | Control one step away |
|:--|:--|:--|
| `packages/cli/src/utils/skills-install-state.ts` | reported, not
failed | same file, `packages/cli` not a workspace package: FAILS; same
package, outside `src/`: FAILS |
| the same site in a `private: true` member's `src/` | FAILS | the
published member: reported |
| `packages/cli/scripts/src/staging.ts` (a `src/` that is not the
member's own) | FAILS | the member's own `src/`: reported |
| `…/skills-install-state.test.ts` (by name), `src/__tests__/…` (by
directory) | FAILS | the test file on a `tmpdir()` base: in neither list
|
| `scripts/pm/stage-skills.mjs` (repo tooling) | FAILS | the tooling
file on a `tmpdir()` base: in neither list |
| unresolved `mkdirSync` | in neither list | (that half was never held
to completeness) |
| this tree's own workspace (default `members`) | shipped arm reported,
tooling arm FAILS | n/a |

Runs at `f7e942e8` (before the rework; this branch merged with
`origin/main` `d8599c2c`). At the rework head `3ec2a452` the dev reran
both tiers, exit 0: fast 2264 case(s) · slow 315 case(s), 2579 cases
pass, including the 12 boundary pins (os-dev-report 7077315476).

<details><summary>Both tiers, the slow section that holds the live case
included: <code>node scripts/pm/dispatch-gates.mjs --self-test</code>,
exit 0</summary>

```text
  ✓ a caller's-directory mkdtempSync base in shipped package source is REPORTED, not failed
  ✓ CONTROL: the same file in a directory that holds no workspace package still FAILS
  ✓ CONTROL: and in the package but outside its own src/ (one directory up), it still FAILS
  ✓ the same site in a test file FAILS — beside the shipped file, by name
  ✓ and in a test helper under src/__tests__/, by directory — the stricter test predicate holds it
  ✓ CONTROL: the test file with a base the scan CAN read (the system temp directory) is in neither list
  ✓ the same site in repo tooling FAILS — the tooling population is not dropped with the test predicate
  ✓ CONTROL: the tooling file with a base the scan CAN read is in neither list
  ✓ and an unresolved mkdirSync site is in neither list — that half was never held to completeness
  ✓ on this tree's own workspace, the shipped arm is REPORTED and the tooling arm FAILS
  ...
  ✓ the sweep really read this tree (3145 directory-creating site(s) across 23403 tracked source(s))
  ✓ and it really found in-tree fixture roots (93), so the coverage case below judges something
  ✓ no mkdtempSync site in a test file or repo tooling takes a base the scan cannot read
  ...
dispatch-gates self-test tiers: fast 2262 case(s) in 1009.1s · slow 315 case(s) in 1825.0s.
✓ dispatch-gates self-test: 2577 cases pass.
```
</details>

<details><summary>Fast tier as CI runs it: <code>pnpm
check:pm-dispatch-gates</code>, exit 0</summary>

```text
✓ dispatch-gates self-test (fast tier): 2262 cases pass; 9 slow section(s) deferred.
check:pm-dispatch-gates: the battery (the fast tier) took 562.7s on this box.
```
</details>

## Acceptance notes

- **The objectstack-ai#35495 spelling passes the slow case now (scratch copy, not
re-landed here).** I checked out a scratch worktree at this branch's
head and applied objectstack-ai#35495's merge diff (`578d3b1d66`: the
skills-install-state source, its test, its changeset). I then ran the
slow case's own logic on that tree through the scan's exports
(`exposedScratchDirs` + `mkdtempCompleteness`). Result: origin/main's
rule FAILS, `UNRESOLVED:
packages/cli/src/utils/skills-install-state.ts:246 (dir is not bound in
this file)`; this branch's rule has failing 0 and reported 1 (the same
site), so the case passes. Exposed: 0.
- **Boundary reading, resolved by the seat (reading B, rework
3ec2a45).** The maintainer's words 「扫描只管仓内运行的代码」 and 「发布代码同类调用只报告不判红」:
a `private: true` member (`examples/*`, `apps/docs`, QA harnesses, the
eslint plugin…) is not published code, so its `src/` keeps failing. L2
7076625985 graded the literal-rider reading M1; L1-d had preferred the
literal reading (7076590966) and accepted the seat's ruling. Pins: a
private member's `src/` site FAILS with the published arm as control,
and `packages/cli/scripts/src/staging.ts` FAILS as the control for "the
member's own `src/`" (L2 S1). The header's measurement is dated by base
tree `d8599c2c`: 1823 sites, 1465 test (47 in-tree), 344 other, 14
shipped (tmpdir), 0 unresolved.
- **Ablation not run.** The diff is a repo script, and the dispatch
contract does not ablate scripts. The fast pins carry their own
controls, and each control flips the verdict.
- The live case's title changed from "no mkdtempSync site in this tree…"
to "no mkdtempSync site in a test file or repo tooling…". No other file
names the old text (`git grep` 0 hits).

## Verification

<details><summary>Derived gate families: 63 derived, 62 run, 1 NOT
MEASURED, 0 unrun (at f7e942e)</summary>

- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 63 families. Each was run with its
exit code captured before any pipe, then reconciled: `node
scripts/pm/dispatch-gates.mjs --ran ran.list --repo
objectstack-ai/objectstack` → `✓ dispatch-gates --ran: 63 derived
famil(ies) accounted for — 62 run, 1 NOT-MEASURED (1 DERIVED from a
recorded exit 3).`
- 62 exit 0, including `pnpm check:pm-dispatch-gates`, `pnpm
check:nul-bytes`, `pnpm check:pm-governed-prose`, `pnpm
check:pm-governed-merges`, `node
scripts/pm/check-governed-queue-guard.mjs --self-test`, `node
scripts/check-closing-keyword-parity.mjs` (+ `--self-test`) and `node
scripts/check-self-test-wired.mjs` (+ `--self-test`).
- NOT MEASURED: `pnpm check:i18n-coverage`, exit 3 (PREREQUISITE NOT
MET: the package `dist/` builds it lints against are not built in this
worktree, and this diff touches no package). CI runs it.
- `node scripts/check-self-test-workflow-commands.mjs` first refused
with `spawnSync node ETIMEDOUT` (load average 11 on a shared box, so no
verdict). It was rerun at load 7.4 on the same head: exit 0.
- `node scripts/pm/overlap-check.mjs
--branch=claude/issue-35611-mkdtemp-shipped-report` → `VERDICT clean
exit 0` before each push.
- Body gate: `node scripts/check-closing-keyword-parity.mjs --body`
binds exactly one declaration, this card's, on the line under the
header.
</details>

Tier H: `scripts/pm/dispatch-gates.mjs` is a governed guard instrument,
so this lands only on the maintainer's approval. `skip-changeset`:
`scripts/pm/**` publishes nothing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- signed: repo:objectstack#7 · zhuangjianguo ·
session_01QsR2jTeURPvEm465RcoYEC -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
247257110 pushed a commit to 247257110/objectstack that referenced this pull request Nov 23, 2026
…g last (re-land) (objectstack-ai#36465)

<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCxiFE11rsKwyNffJZKYqJs)_

Fixes objectstack-ai#35079

Clause-②: no
Metadata-protocol: none

## 维护者速读
-
用户能看到什么变化:命令行用户运行「安装技能」或「更新技能」时,若中途写盘失败(磁盘满、无权限、被中断),原有技能和安装记录保持原样,下次直接再运行更新即可,不再需要加强制参数。
-
为什么做:这是技能安装可靠性修复的重新合入;上次合入后因车队门禁读不懂暂存目录而被撤回,门禁那一侧已按你「扫描只管仓内运行的代码」的裁决改好。
- 出错会怎样:最坏是安装或更新在失败时留下一个隐藏的暂存目录,它不会被当成技能读取,下次写入时自动删除;可直接撤回本改动。
- 要你做什么:无。

## What changes

This re-lands the staged swap of PR objectstack-ai#35495 (merge commit `578d3b1d66`),
byte for byte. PR objectstack-ai#35616 reverted it because the dispatch-gates
`mkdtempSync` completeness rule could not read the staging base. That
base is computed from the caller's `dir`, and the scan reads one file at
a time. PR objectstack-ai#36368 (merged `fb6eb801b2c`) carries out ruling record
7075362923: an unresolved site in shipped package source is now
reported, not failed. So the diff lands as written.

- `packages/cli/src/utils/skills-install-state.ts`, `applySkillsWrite`:
every new skill directory is written into one hidden staging directory
inside the skills directory (`.objectstack-skills-staging-*`, from
`mkdtempSync`, so it sits on the same filesystem). Each touched skill is
renamed aside into it, and its staged copy is renamed into place. The
record is written into the staging directory and renamed over the old
one, after every swap. Any throw undoes the renames already done, newest
first. The next write removes any leftover staging directories. They are
hidden, so `status`, the plan and `inspectSkillsDir` never read them as
skills.
- `packages/cli/test/skills-commands.test.ts`: a new top-level
`describe` in the shared harness. It injects `ENOSPC` at three points (a
staged file write, moving the second skill into place, the record
rename) and has one leftover-staging case. The fault seam is a hoisted
pass-through `vi.mock('node:fs')`. The test's own scratch base is
`tmpdir()`, which the scan can read.
- `.changeset/35079-skills-write-staged-swap.md`: objectstack-ai#35495's patch
changeset for `@objectstack/cli`, unchanged.

Proof of identity with objectstack-ai#35495: `git diff --cached` after `git
cherry-pick -n 578d3b1` equals `git diff 578d3b1~1 578d3b1` (a
`diff` of the two outputs printed nothing). Both target files on
`origin/main` `ff601499008` are byte-equal to the merge's parent
`eb1f85d7f4`: `git diff eb1f85d HEAD` on those two paths was empty
before the pick. So nothing on main needed adapting.

Files to read first (risk order):
1. `packages/cli/src/utils/skills-install-state.ts`,
`applySkillsWrite`'s `try`/`catch` and `undoSwap`. This is the swap and
its rollback.
2. `packages/cli/test/skills-commands.test.ts`, the `vi.mock('node:fs')`
fault seam at the top of the file. It is a pass-through unless a test
arms it.
3. `packages/cli/test/skills-commands.test.ts`, the describe `an
interrupted write leaves the installed catalog usable`.

Two-minute check: `node scripts/pm/dispatch-gates.mjs --self-test 2>&1 |
grep "no mkdtempSync site in a test file"` should print one passing
line. It reports `packages/cli/src/utils/skills-install-state.ts:246`
under "reported, not failed".

## Tests

All readings at head `009ca680a2f` (base `origin/main` `ff601499008`).

- `packages/cli/test/skills-commands.test.ts`, run under the verify lock
after the `@objectstack/cli^...` closure build: `Test Files 1 passed
(1)`, `Tests 34 passed (34)`, `VERDICT command-exit 0`. That is the 30
existing cases plus the 4 new interrupted-write pins.
- `pnpm --filter @objectstack/cli build`: exit 0 in the same locked run.
- `node scripts/pm/dispatch-gates.mjs --self-test`, both tiers: `fast
2264 case(s) · slow 315 case(s)`, `✓ dispatch-gates self-test: 2579
cases pass.`, exit 0. It includes the slow case this re-land was blocked
on, which now passes.
- Declared narrowing: the full cli `unit` tier and `pnpm --filter
@objectstack/cli typecheck` did not get a lock turn before this PR
opened. Two long batteries owned by other seats held the shared lock for
more than an hour. Both are declared to CI (`Test Core`, `TypeScript
Type Check`). The `integration` tier is declared to CI: the diff touches
no integration-tier file and no spawn entry.

<details><summary>The live slow case, from the full self-test
log</summary>

```text
  ✓ the sweep really read this tree (3154 directory-creating site(s) across 23442 tracked source(s))
  ✓ and it really found in-tree fixture roots (93), so the coverage case below judges something
  ✓ every in-tree directory this tree's sources create is covered by a tracked ignore rule, or is tracked itself
  ✓ no mkdtempSync site in a test file or repo tooling takes a base the scan cannot read — reported, not failed (shipped package source, base chosen at run time): packages/cli/src/utils/skills-install-state.ts:246 (dir is not bound in this file)
dispatch-gates self-test tiers: fast 2264 case(s) in 576.2s · slow 315 case(s) in 1879.5s.
✓ dispatch-gates self-test: 2579 cases pass.
```
</details>

## Acceptance notes

- Gate-side unblock: the slow case's own logic also passed when called
through the scan's exports at head `009ca680a2f`
(`exposedScratchDirs({})` + `mkdtempCompleteness`): 3154 sites across
23442 tracked sources, 93 in-tree, exposed 0, unresolved 508, failing 0,
reported 1 (`packages/cli/src/utils/skills-install-state.ts:246 (dir is
not bound in this file)`). No `scripts/pm/**` file is touched.
- Residual, unchanged from objectstack-ai#35495: a hard kill (SIGKILL, power loss, an
unhandled SIGINT) inside the rename-only swap window can still leave
mixed state. The failure path the card names, a throw the process
survives, is handled. The hard-kill window is tracked as objectstack-ai#35502.
- Ablation not re-run: the source and test are byte-identical to objectstack-ai#35495,
whose red-before and ablation runs are on record in its os-dev-report
(7008338749): 4 failed / 30 passed on the old source, 34 / 34 on the
fix.

## Verification

<details><summary>Derived gate families: 64 derived, 61 run, 3 NOT
MEASURED, 0 unrun (head 009ca68)</summary>

- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 64 families. Each one ran with its
exit code captured before any pipe. Then `--ran` reconciled them: `✓
dispatch-gates --ran: 64 derived famil(ies) accounted for — 61 run, 3
NOT-MEASURED (3 DERIVED from a recorded exit 3).`
- 61 exited 0. Among them: `check:nul-bytes`,
`check:cross-package-test-inputs`, `check:test-source-alias`,
`check:cli-test-child-env`, `check:published-files`,
`check:dts-closure`, `check:i18n`, `check:lean-entry-closure`,
`check-changeset-no-major`, `check-empty-changeset`,
`check-adr-0087-registration` and `check-closing-keyword-parity` (each
with `--self-test` where it is derived). Eight gates first answered exit
3 before the build. They were re-run after the closure build, and five
of them went to exit 0.
- NOT MEASURED, exit 3 (PREREQUISITE NOT MET), all three left to CI:
`pnpm check:dual-build-cjs-loads` (packages outside the cli closure have
no `dist/`), `pnpm check:i18n-coverage` (example configs outside the
closure are not built), and `pnpm check:type-check-debt` (its re-measure
build did not get a turn on the shared lock).
- `node scripts/pm/dispatch-gates.mjs --tier`: no path-derived mandate.
Changed lines: 253 (+239 / -14), under the 3000 threshold.
- `node scripts/pm/overlap-check.mjs
--branch=claude/issue-35079-skills-staged-swap-reland`: `VERDICT clean
exit 0`, run before the push.
- Body gate: `node scripts/check-closing-keyword-parity.mjs --body`
binds exactly one declaration, this card's, on the line under the
header.
</details>

`@objectstack/cli` publishes, so the patch changeset from objectstack-ai#35495 comes
along unchanged. No `skip-changeset`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- signed: repo:objectstack#7 · zhuangjianguo ·
session_01QsR2jTeURPvEm465RcoYEC -->

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants