Repository navigation
Commit 4895661
fix(metadata-protocol): a package copy under a new namespace calls its own flows (#38642)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9St4eUWHFcCKuRUrCZPperJ)_
Fixes #38595
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
管理员把一个应用包以新的命名空间安装或复制之后,复制出来的流程调用的是复制包自己的子流程,按钮触发的也是复制包自己的流程;以前调用的是原包的流程,或者因为找不到流程而每次运行都失败。复制时如果调用方流程排在被调用流程前面,现在两个流程都会复制成功,不再被保存检查拒掉调用方;如果被调用的流程本身复制失败,调用它的流程也一并列为失败并撤回,不会留下指向不存在流程的调用。
- 属于"软件包安装与复制"这块能力,替用新命名空间安装应用包、或复制一份应用包来改的管理员解决"复制后流程跑不起来或串到原包"的问题。
- 只影响带新命名空间的安装和复制;如果改名规则出错,复制包里的某个流程调用会指向错误的名字,原包不受影响,可以直接撤回这次合并恢复原来的行为。
- 无
## What changes
`planNamespaceRename`
(`packages/metadata-protocol/src/package-namespace-rename.ts`), the one
rename engine behind the unmanaged install's `targetNamespace` and
`duplicatePackage`, renamed a package flow under the prefix swap
(`crm_child` to `crm2_child`) but rewrote no name that calls it. It now
builds a flow rename map from the package's own `flow` items and
rewrites a value that EQUALS a renamed flow name, whole, at:
- the derived index's `flow` sites,
`REFERENCE_SITES.byTarget.get('flow')`, read the same way the object
sites are (by property, wherever it occurs). Dumped at runtime on this
tree it holds `{fromType:'flow', property:'flowName'}` and
`{fromType:'translation', property:'flows'}`, so a `subflow` step's
`config.flowName` and a translation's `flows` keys follow;
- the one hand-written site, commented as such in the code: a `target`
whose sibling executor is `'flow'`. That is `type: 'flow'` on an action
(`ActionSchema`, an object's `actions[]`, an inline action, an
`action:group` member, an API endpoint) and `actionType: 'flow'` on an
`action:button` / `action:icon` page block, where `type` is the
component. The index cannot carry `target`, because on every other
executor it names a URL, script, page, endpoint or form, and a
property-wide site would rewrite those too and list them in the "Used
by" answer.
A flow the package does not hold keeps its name, a flow the prefix swap
keeps keeps its name, and nothing is substring-rewritten. A value that
is not a renamed flow name falls through to the rules every string
already took, so nothing that read the same before reads differently
now. Collisions work as they do for objects: a renamed flow name that
meets a name the item already holds at that site (a translation keyed by
both `crm_child` and `crm2_child`) refuses the item, and the refusal
names the flow. The internal `atReference: boolean` of the walk became
the site's rename map (object or flow), so both kinds share one walk and
one collision rule.
**This round (delta after PR #38594 merged as d33183a).**
`origin/main` was merged into this branch with a merge commit
(3a7134a, no conflicts). With both changes on one tree, a
parent-first `duplicatePackage` was refused by the publish gate
(measurement below). So the `duplicatePackage` leg's `host.saveMetaItem`
call in `protocol-package-commits.ts` now passes `copyPlanFlowNames` on
a flow write, the unmanaged-install leg's way: the copy names
(`rename.copyName`) of every flow row the same duplicate writes. On a
non-flow write nothing is passed. The gate's rule itself is not touched;
the names are additive (`pending.flows`), so they can let a call to a
flow of the same copy through and refuse nothing.
**Third round (L1 REWORK 7267334209, route per claim amendment
7267347516).** `duplicatePackage` is best-effort, so a planned flow can
still land in `failed[]` after the gate passed its caller on the plan's
word. The duplicate leg now closes its flow plan after the copy loop.
Each copied flow whose `subflow` / `map` step calls a planned flow (its
copy name) that was not written is taken back out of the copy, through
the same `undoBatchRowWrite` the object settle uses. It is reported in
`failed[]` with an error that names that callee. This repeats until
nothing changes, so a caller's caller goes too. The loop reads a
caller's address before and after its write for that undo, only when the
caller calls a planned flow. The plan is now one list built before the
loop (`planFlowSources`). The callee walk uses the spec's
`FLOW_REGION_SLOTS_BY_TYPE`, the region table the publish gate walks.
The install leg is not touched.
## Tests
<details><summary>Engine pins, package-namespace-rename.test.ts (7 new
cases)</summary>
`flowName` follows; `other_flow`, an unprefixed `bare_child` and a
superstring `crm_child_v2` keep their names; a flow action's `target`
follows while `modal` / `script` / `api` targets equal to the same
string do not; the object `actions[]`, API endpoint and page
`actionType` spellings; translation `flows` keys; the collision refusal;
and a copy that keeps the source namespace renames nothing.
</details>
<details><summary>Door pins, new
package-namespace-rename-flow-refs-38595.test.ts (6 cases)</summary>
The harness (`makeEngine`, `crmBody`) is copied from
`package-unmanaged-install.test.ts`, which is not edited. Its automation
service answers `listFlows`, so a gate that judges a step's called flow
has a non-empty universe.
- an unmanaged install with `targetNamespace: 'crm2'` installs, and the
stored `crm2_parent` calls `crm2_child`;
- the copied flow action reads `target: 'crm2_child'`, and the `modal`
control keeps `target: 'crm_child'`;
- with the source package installed under its own names beside the copy,
the copy's `crm2_parent` calls `crm2_child`;
- a call to `other_flow` keeps its name;
- `duplicatePackage` into `crm2` gives the same result with the source
installed, and the source still calls `crm_child`;
- parity: the duplicate and the import into `crm2` store identical flow
and action items.
</details>
<details><summary>Stacking measurement (this round), new describe in
package-namespace-rename-flow-refs-38595.test.ts (2 cases)</summary>
The source package is installed with its stored flow rows in the order
`crm_parent` (a `subflow` step calling `crm_child`), then `crm_child`;
the test asserts that order. It is then duplicated into `crm2`. The
automation service holds `other_flow`, `crm_child`, `crm_parent`, never
`crm2_child`.
Measured at 2af21e1 (merge of `main` plus the test, before the fix),
the gate refuses. `duplicated.failed` was, verbatim:
```
[{ type: 'flow', name: 'crm_parent', error: 'flow/crm2_parent failed author-time validation: 1 issue — flows[0].nodes[1].config.flowName [flow-subflow-unknown]' }]
```
and only `crm2_child` was copied (`Tests 2 failed | 6 passed (8)`). With
the fix (300cf74) the case passes: `failed` is empty, both flows are
stored and `crm2_parent` calls `crm2_child`.
CONTROL, the gate is live in this harness: a third flow `crm_caller`
calls `crm_ghost`, which the engine holds at the source install and no
longer at the copy, and the package holds no such flow. The copy keeps
the name `crm_ghost`, and with the fix the duplicate still refuses
exactly `flow/crm_caller` with `flow-subflow-unknown` while both other
flows are copied. So the plan names let through only the copy's own
flows.
</details>
<details><summary>Withdrawal pins (third round), same describe (2
cases)</summary>
- (a) L1's parent-first case. `crm_parent` calls `crm_child`, and
`crm_child` calls `crm_ghost`, which the engine holds at the source
install and drops before the duplicate. `failed` holds `flow/crm_child`
and `flow/crm_parent`, and the parent's error names `'crm2_child'`. No
flow of the copy is stored, no stored copied flow calls a flow the
deployment does not hold, and the copy's object is still copied.
- (b) A two-level chain, `crm_a` to `crm_b` to `crm_c`, with `crm_c`
calling the dropped `crm_ghost`. All three end in `failed[]` (the errors
of `a` and `b` name `'crm2_b'` and `'crm2_c'`). `crm2_solo`, outside the
chain, is the only copied flow, and nothing copied calls a missing flow.
- The success pins and the `crm_ghost` CONTROL pass unchanged: `Tests 10
passed (10)` for the card file at 712fda7.
Ablations, each run after the fix commit 28e4856 with
`scripts/ablation-replace.mjs`:
- Cascade off: `if (withdrawn.length === 0) break;` became `if
(withdrawn.length >= 0) break;` (blob `4ca8e112244c` to `6eec66471fb7`).
Result: `Tests 2 failed | 8 passed (10)`. (a) fails with `expected [
'flow/crm_child' ] to deeply equal [ 'flow/crm_child', 'flow/crm_parent'
]`, which is L1's measured state, and (b) fails with `expected [
'flow/crm_c' ] …`.
- Transitive step off: the line that marks a withdrawn caller as not
written was deleted (blob `4ca8e112244c` to `378006812f35`). Result:
`Tests 1 failed | 9 passed (10)`. Only (b) fails, with `expected [
'flow/crm_b', 'flow/crm_c' ] …`.
- Both times the tool restored the file: blob equal to HEAD, and `git
diff HEAD` empty.
</details>
<details><summary>Ablation of the second round's line</summary>
The fix was committed first (300cf74). `node
scripts/ablation-replace.mjs` replaced the guard `...(singular ===
'flow'` of the new spread with `...(false` (anchor 1 to 0, blob
`d064b03b149a` to `f110fae517f4`). The card test file then failed both
new cases (`Tests 2 failed | 6 passed (8)`): the parent-first case with
the refusal above, the CONTROL because `crm2_parent` was refused beside
`crm_caller`. The tool restored the file: blob equal to HEAD, `git diff
HEAD` empty.
</details>
<details><summary>Package run at 712fda7 (third round)</summary>
`pnpm --filter @objectstack/metadata-protocol typecheck && pnpm --filter
@objectstack/metadata-protocol exec vitest run --maxWorkers=2` under the
verify lock: `VERDICT command-exit 0`, `Test Files 374 passed | 9
skipped (383)`, `Tests 23690 passed | 45 skipped (23735)`. The 69
families `dispatch-gates --commands` derives for this round's four
paths: 67 exit 0. `check:dual-build-cjs-loads` and
`check:lean-entry-closure` exit 3 (PREREQUISITE NOT MET: they read every
package's `dist`), so they are NOT MEASURED here and left to CI.
`overlap-check`: clean.
</details>
<details><summary>Package run at 964a326 (second round)</summary>
`pnpm --filter @objectstack/metadata-protocol typecheck && pnpm --filter
@objectstack/metadata-protocol exec vitest run --maxWorkers=2` under the
verify lock, after building the closure (`pnpm --filter
'@objectstack/metadata-protocol^...' build`): `VERDICT command-exit 0`,
`Test Files 374 passed | 9 skipped (383)`, `Tests 23688 passed | 45
skipped (23733)`. The card pins after the merge
(`package-namespace-rename-flow-refs-38595.test.ts`,
`package-namespace-rename.test.ts`,
`package-unmanaged-install.test.ts`): `Test Files 3 passed (3)`, `Tests
152 passed (152)`.
</details>
<details><summary>Package run at 5ec669b (first round)</summary>
`pnpm --filter @objectstack/metadata-protocol typecheck && … exec vitest
run --maxWorkers=2` under the verify lock: `VERDICT command-exit 0`,
`Test Files 373 passed | 9 skipped (382)`, `Tests 23670 passed | 45
skipped (23715)`. The typecheck program lists the test files.
</details>
<details><summary>Ablation</summary>
The fix commit came first. Then `scripts/ablation-replace.mjs` swapped
the one line that fills the flow rename map for a no-op (anchor 1 to 0,
blob `e90813508b99` to `114356add0b3`). With that in place, 9 of the 13
new cases failed (`Tests 9 failed | 26 passed (35)`): every rewrite pin
on both test files. The four that stayed green were the three controls
and the parity case, which stays equal when both doors are equally
wrong. The tool then restored the file: the blob matched HEAD again and
`git diff HEAD` was empty.
</details>
<details><summary>Under PR #38594's gate (head 93f3643)</summary>
In a throwaway tree at that head, with this branch's two commits
cherry-picked, the closure was built and both test files passed (`Tests
42 passed`). With the same ablation there, the install pins fail with
the gate's own 422: `INVALID_METADATA`, `flow-subflow-unknown` at
`flows[0].nodes[1].config.flowName`, "calls flow 'crm_child' … Did you
mean crm2_child". So the gate is live in this harness and the pins pass
under it, without depending on its code. The tree was removed
afterwards.
</details>
## Acceptance notes
- **The parent-first duplicate is fixed in this PR now.** The first
round reported that with this branch and PR #38594 both applied, a
parent-first `duplicatePackage` fails `flow-subflow-unknown` and writes
only the child. PR #38594 merged without a copy-plan on its duplicate
leg, so the seat routed the fix here (claim amendment 7266007014). It
was re-measured on the merged tree (see Tests) and fixed on the
duplicate leg's `saveMetaItem` call alone.
- The `copyPlanFlowNames` doc comment in `protocol-door-requests.ts`
said "`duplicatePackage` copies stored rows, which the gate's own read
of the stored flows already holds". That stopped being true once the
copy's calls name the copy's flows. Per claim amendment 7266793287,
48420e0 rewords that comment only: both copy doors state the field,
the names the same copy writes under their written names. In the third
round (712fda7), the comment and the changeset sentence say the gate
is told the flows the copy PLANS to write. They also say that on the
duplicate, a caller whose planned callee was not written is withdrawn
with it. No logic changes; metadata-protocol typecheck exits 0, and the
48 families `dispatch-gates --commands` derives for that path ran with
46 at exit 0 and `check:dual-build-cjs-loads` /
`check:lean-entry-closure` at exit 3 (PREREQUISITE NOT MET, left to CI).
- Measured with the same engine probe, outside this card: the names of
other non-object items (dashboard, page, report) are renamed by the
prefix swap, but their references are not. That covers app navigation's
`dashboardName` / `pageName` / `reportName` and a translation's
`dashboards` / `pages` / `reports` keys. A dashboard header action with
`actionType: 'flow'` keeps its `actionUrl`. These are reported to the
seat as one family. They are not fixed here.
- Outside the dispatched file surface, added by the PM's amendment:
`scripts/engine-double-contract.pinned.json` gains 3 rows (15 lines) for
the new test file's copied stub engine, produced by `node
scripts/check-engine-double-contract.mjs --write`. No existing row
changed, and `pnpm check:engine-double-contract` exits 0 at fb44b0f
and again at 964a326.
- Local gates at 964a326: the 77 families `dispatch-gates --commands`
derives for this diff were run; 75 exit 0, and
`check:dual-build-cjs-loads` and `check:lean-entry-closure` exit 3
(`PREREQUISITE NOT MET`: they read every package's built `dist`, which
this worktree built only for the closure), so those two are NOT MEASURED
here and are left to CI. `overlap-check`: clean against `origin/main`,
#38618 and #38497.
- Read, not changed (for the seat): whether `importUnmanagedPackage` has
the same gap on partial failure. It does not, as read at 712fda7. Its
prepare pass refuses the whole install before the base exists if any
item fails to convert or rename (422 or the rename refusal). Its
`copyPlanFlowNames` is built from `prepared`, which is exactly the items
the write loop writes. Any `saveMetaItem` throw in that loop, and any
object the batch settle refuses, goes through `rollBackUnmanagedImport`,
which deletes the whole new base. So on success every planned flow is
written, and on failure nothing remains. The one residue is a rollback
that itself fails. It is not silent: `console.error`, plus an answer
saying the base could NOT be fully removed and must be uninstalled.
## Verification
Read first, by risk:
1. `protocol-package-commits.ts`, the `duplicatePackage` leg's close:
the withdrawal block after the copy loop (the fixpoint, the undo and the
error text), and `plannedCalleesOf` with `planFlowSources` above the
loop. Check that a withdrawn caller is removed from `copied` and pushed
to `failed[]` exactly once.
2. `package-namespace-rename.ts`, the `deepRewrite` object branch: the
child-site expression `referenceSiteOf(k) ?? (site && k === 'name' ?
site : flowTargetSite(v, k))` replaced the old boolean. Object sites
must behave exactly as before.
3. `package-namespace-rename-flow-refs-38595.test.ts`: the parent-first
duplicate and its CONTROL, the source-still-installed case and the
duplicate parity. (`flowTargetSite` and `FLOW_EXECUTOR_KEYS` in
`package-namespace-rename.ts`, the one hand-written site, were read in
the first round's review.)
Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec
vitest run --maxWorkers=2
src/package-namespace-rename-flow-refs-38595.test.ts
src/package-namespace-rename.test.ts` should report 2 files and 39 tests
passing.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmQJUGAAa5rz9Yi2DvW
<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmQJUGAAa5rz9Yi2DvW -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 25ac5df commit 4895661
7 files changed
Lines changed: 764 additions & 19 deletions
File tree
- .changeset
- packages/metadata-protocol/src
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
141 | 157 | | |
142 | 158 | | |
143 | 159 | | |
| |||
463 | 479 | | |
464 | 480 | | |
465 | 481 | | |
466 | | - | |
467 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
468 | 532 | | |
469 | | - | |
| 533 | + | |
470 | 534 | | |
471 | 535 | | |
472 | 536 | | |
| |||
484 | 548 | | |
485 | 549 | | |
486 | 550 | | |
487 | | - | |
488 | | - | |
| 551 | + | |
| 552 | + | |
489 | 553 | | |
490 | 554 | | |
491 | 555 | | |
492 | 556 | | |
493 | 557 | | |
494 | 558 | | |
495 | 559 | | |
496 | | - | |
| 560 | + | |
497 | 561 | | |
498 | 562 | | |
499 | 563 | | |
| |||
503 | 567 | | |
504 | 568 | | |
505 | 569 | | |
506 | | - | |
| 570 | + | |
507 | 571 | | |
508 | 572 | | |
509 | | - | |
| 573 | + | |
510 | 574 | | |
511 | 575 | | |
512 | 576 | | |
| |||
515 | 579 | | |
516 | 580 | | |
517 | 581 | | |
518 | | - | |
| 582 | + | |
519 | 583 | | |
520 | 584 | | |
521 | 585 | | |
| |||
540 | 604 | | |
541 | 605 | | |
542 | 606 | | |
543 | | - | |
| 607 | + | |
544 | 608 | | |
545 | 609 | | |
546 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
| |||
0 commit comments