Repository navigation
Commit b198f91
fix(cli): os dev's in-place organization-ownership upgrade names what stopped it, and the command that carries on (#26785)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XQ5pdkuCpFo7HHTQm6TUo9U)_
Fixes #26615
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:`os dev` 遇到旧开发库被启动保护拒绝、就地升级又没跑完时,不再只说「The upgrade did not run
to a
report」。它会打印仪式自己的拒绝原文(终端强制彩色时也读得到),或者仪式是怎么结束的(退出码、信号)加日志末尾;最后给出一条能直接接着跑的完整命令(带数据库和它写好的计划文件)。
- **为什么改**:卡片里开发者拉了一周 main 后启动失败,只拿到一句没有原因的话。这里在五种旧库形态上都复现不出那次具体的停止(包括
10 月 16 日的 HotCRM 真实旧库 + 已发布的 18.2.0,都升级成功),但找到了三处会把原因吞掉的代码路径,现在都会说出原因。
- **风险与回滚**:只动 `os dev` 的就地升级读结果和打印的那一层;生产 `os migrate … --apply`
仪式本身一行没改,升级前的备份照旧保留。回滚即还原
`packages/cli/src/utils/dev-organization-ownership-upgrade.ts`。
-
**先看**:`packages/cli/src/utils/dev-organization-ownership-upgrade.ts`(`stopCause`
与
`readApplyOutcome`)、`packages/cli/test/dev-organization-ownership-stale-column.integration.test.ts`、`scripts/check-cli-test-child-env.mjs`(名单加一行)。
- **两分钟验证**:`pnpm --filter @objectstack/cli exec vitest run
src/utils/dev-organization-ownership-upgrade.test.ts`,应见 13 条全绿,其中「a
refusal printed in colour is read in the ceremony's own words」。
- **需要你做的**:无,席位落地。
## What changes
`os dev`'s in-place upgrade of a development database the
organization-ownership boot guard refused (`upgradeDevelopmentDatabase`,
ADR-0131 D10 development exception) now never ends without its cause:
- **The ceremony's refusal, in its own words, also in colour.** The
refusal lines are read from the ceremony log with colour stripped
(`stripVTControlCharacters`). Before, a terminal that forces colour
(`FORCE_COLOR`) made chalk write `ESC[31m ✗ Refused: …` into the log,
the reader's `startsWith('✗')` matched nothing, and the stop printed no
cause. Measured: `FORCE_COLOR=1 os migrate organization-ownership --dev
--apply …` writes exactly that byte shape to a file. The `✗` glyph is
now the printer's alone, no longer doubled (`✗ ✗ Refused`).
- **A stop with no refusal of its own names how it ended.** The apply's
exit used to be ignored. An uncaught error (printed by oclif as `Error:
…`), a crash or a signal printed no `✗` line, so nothing was shown. Now
the upgrade prints `` `os migrate organization-ownership --dev --apply`
exited with code N `` (or `was ended by SIGNAL`, or `could not be
started`), then the end of that run's own part of the log, without the
kernel's timestamped INFO/DEBUG narration and without the plan run's
output.
- **A report file that is not a report is read as none.** The apply
reserves its `--out` file before it boots, holding a reservation text. A
run that stopped between the reservation and the report left that text,
which the upgrade parsed as a report with no verdict and printed 「The
upgrade stopped at a blocker (above)」 with nothing above. A file that
did not parse threw out of `os dev`. Both are now "no report", with the
cause. A blocked report that names no blocker prints the log's cause
too.
- **No silent drop (seat ruling C, 6446501014).** A stale
`organization_id` the plan gives the column-drop fate is a column the
plan accounts for, so the upgrade proceeds, but before the apply runs
`os dev` prints one line per column-drop table whose retired column held
non-null stamps: the table, how many stamped values the drop discards
(the plan's `fateCounts.rowsLosingTheirStamp`), and that the copy keeps
them. A table with no stamps is not named. A column the plan gives no
fate still refuses the plan.
- **The exact command that carries on.** Every failed upgrade ends on
`os migrate organization-ownership --dev --database-url URL --apply
--plan-file PLAN --backup-taken`, with the database the boot opened and
the plan the upgrade wrote. The apply resumes from its checkpoint and
prints the stop on the developer's terminal.
The copy taken before the upgrade is kept exactly as before. The
production ceremony (`os migrate organization-ownership --apply` without
`--dev`) is unchanged: no file under
`packages/cli/src/commands/migrate/` or `packages/runtime` is touched.
## Tests
- `packages/cli/src/utils/dev-organization-ownership-upgrade.test.ts`:
six new cases (a coloured refusal, an uncaught error with kernel
narration around it, a signal, the reservation text left behind, an
unparseable report file, a blocked report with no blocker), and the
existing cases read the un-doubled refusal and the exact command; a
seventh (ruling C) pins that a `sys_secret` column drop discarding 3
stamps is announced exactly once before the apply, a drop with 0 stamps
is not, and the upgrade completes. 13/13 (ablating the `rows > 0` filter
turns the C pin red: 1 failed | 12 passed).
-
`packages/cli/test/dev-organization-ownership-stale-column.integration.test.ts`
(new, integration tier, the card's third target): a fresh `os dev`
creates the database, the staging step gives `sys_flow_credential` and
`sys_secret` the injected `organization_id` column and its
`idx_TABLE_organization_id` index with unstamped rows, and deletes the
marker (the 18.0 pre-release shape). A plain `os dev` on it is refused,
upgraded in place and starts (「server started on the upgraded
database」). Both columns are gone, the marker is verified, the rows are
kept, and the copy still has both columns. The `sys_secret` row is
stamped with a real `sys_organization` id, and `os dev` prints its
stamped-count line before "Upgraded the development database" and does
not name the unstamped `sys_flow_credential`. 5/5. It joins the
built-entrypoint census of `scripts/check-cli-test-child-env.mjs`
(seventeen → eighteen, with its reason).
<details><summary>Red first: the new cases against the base
source</summary>
The base `dev-organization-ownership-upgrade.ts` (`5cc31c7885`),
restored from `HEAD` afterwards (`git diff HEAD` empty), driven by a
copy of the test whose fake answers the base seam's `number`:
```
× a refused plan changes nothing and boots nothing: its refusal is printed, with the copy's location
× a blocked step boots nothing: each blocker is printed, and how to resume
× ⭐ a refusal printed in colour is read in the ceremony's own words
× an apply that stopped with no refusal of its own (an uncaught error) names how it ended and the end of its log
× an apply ended by a signal says so
× a report file still holding the apply's reservation text is no report: the cause is printed, not "a blocker (above)"
× a report file that does not parse is named, never thrown
× a blocked report that names no blocker prints the log's cause instead of an empty "above"
Tests 8 failed | 4 passed (12)
```
The first two are the un-doubled glyph and the exact command; the other
six are the swallowed causes.
</details>
## Acceptance notes
- **The reported stop did not reproduce in this container.** The
reporter's database
(`.objectstack/data/backups/organization-ownership-2026-10-27T10-08-08-349Z`)
is on the reporter's machine. Five shapes were measured, and each
completed the upgrade and started: (1) a one-object fixture on `main`,
both columns added, no marker; (2) the same with a shape-generation-0
birth marker; (3) HotCRM `afdf9a0` on `main` with the columns, the
indexes, and stamped rows in both tables; (4) the same on the
**published 18.2.0** install; (5) an **authentic** HotCRM database
written by HotCRM `4f82b81` (2026-10-16, platform `18.0.0-next.2`), then
started by HotCRM on the published 18.2.0. Its plan carried exactly
`sys_flow_credential` and `sys_secret` as column-drop tables with the
column, `column-drops done {"dropped":2}`. The test fixture stands in
for the reporter's backup. With this change, running `os dev` on that
backup prints the cause the ceremony hit. The `ceremony.log` beside the
backup already holds it.
- **Target 2 measured: already handled.** `sys_flow_credential` and
`sys_secret` carry inventory fate `column-drop`
(`organization-ownership-inventory.ts`), and the dev-mode ceremony drops
both columns through the drift door, index included. The new test pins
it. No ceremony change was needed.
- **The ruling's data line** was decided by the seat (ruling C,
6446501014): proceed, and print what each column drop discards. A
blanket refusal would refuse every 17.x dev database, because
`sys_audit_log` and the `sys_metadata` family are column-drop tables and
always stamped.
- Open PRs on the file surface, read at start and before this PR: only
#26337 touches `organization-ownership-inventory.ts` (not touched here).
Card #26687 has no PR yet.
## Verification
<details><summary>Local subset at the head named in the report</summary>
- `pnpm --filter @objectstack/cli exec vitest run --project unit`: Test
Files 339 passed (339), Tests 4932 passed (4932), at `74e75e381c`.
- `pnpm --filter @objectstack/cli typecheck`: exit 0
(`check:test-typecheck: OK`).
- `vitest run --project integration
test/dev-organization-ownership-stale-column.integration.test.ts`: 5
passed.
- The derived gate list (`dispatch-gates.mjs --commands`) was re-run at
`74e75e381c` after a full `pnpm build` and reconciled with `--ran`: 80
derived, 80 run, 0 NOT-MEASURED. `check:dual-build-cjs-loads` and
`check:i18n-coverage` both exit 0. The full table is in the
os-dev-report on the card (round 2: 6447810905).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; scoped eslint passes on the touched files.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: not touched.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the maintainer summary
is in Chinese by the fleet's rule).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5pVM4YkXVkL6VgUUhP)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent cee4b16 commit b198f91
6 files changed
Lines changed: 576 additions & 34 deletions
File tree
- .changeset
- packages/cli
- src
- commands
- utils
- test
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
941 | 941 | | |
942 | 942 | | |
943 | 943 | | |
| 944 | + | |
944 | 945 | | |
945 | 946 | | |
946 | 947 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
33 | 45 | | |
34 | 46 | | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
38 | | - | |
39 | | - | |
| 50 | + | |
| 51 | + | |
40 | 52 | | |
| 53 | + | |
41 | 54 | | |
42 | | - | |
| 55 | + | |
| 56 | + | |
43 | 57 | | |
44 | 58 | | |
45 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
46 | 64 | | |
47 | 65 | | |
48 | 66 | | |
| |||
83 | 101 | | |
84 | 102 | | |
85 | 103 | | |
86 | | - | |
| 104 | + | |
| 105 | + | |
87 | 106 | | |
88 | 107 | | |
89 | 108 | | |
| |||
97 | 116 | | |
98 | 117 | | |
99 | 118 | | |
100 | | - | |
| 119 | + | |
101 | 120 | | |
102 | 121 | | |
103 | 122 | | |
| |||
130 | 149 | | |
131 | 150 | | |
132 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
133 | 242 | | |
134 | 243 | | |
135 | 244 | | |
| |||
0 commit comments