Skip to content

Commit ff557c4

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-vj79kz-skill
2 parents dca1c8c + bb86347 commit ff557c4

8 files changed

Lines changed: 534 additions & 39 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/service-knowledge': patch
3+
---
4+
5+
fix(service-knowledge): a backlog reconcile asked for during a bulk import waits until the import's record syncs have drained
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
When the record-sync backlog of a source is no larger than the source's rows (a bulk import or bulk update: about one message per record), the reconcile the batch worker schedules for it now starts only once that backlog has drained, and then writes only the rows no record sync reached. Before, it walked beside the drain, and since a message is covered only when it was published 30 s before the walk began, every imported record was embedded and written twice: about twice the embedding requests and twice the vector writes of a rebuild. A backlog that outnumbers the source's rows (repeated saves, rows deleted or moved out of `where`) is still walked beside the drain, as before. A queue that does not drain within an hour starts the walk anyway. No option, setting or error code changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): a duplicated or namespace-imported package copies its `object_extension` rows without a `name` key, and each copy extends the copied object
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The namespace rename that `duplicatePackage` and `importUnmanagedPackage` (with `targetNamespace`) run on every copied item set `name` on each rewritten body. An `object_extension` body is keyed by `extend`, and the strict extension schema refuses `name`, so every copied extension landed in `failed[]` with "Unrecognized key(s) on this object extension: `name`", a key the author never wrote. The rewrite now leaves `name` off an `object_extension` body.
11+
12+
A copied extension now follows the copied object: when its `extend` names an object the copy renames, the copy extends the copy's object and its row is named by it, for a bare object name too (`ticket` copied as `acme_ticket`), so it never extends the source package's object. An `extend` naming an object the copy does not hold (a platform object, another package's object) keeps its name. Every other type still takes its copy name.

‎AGENTS.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,16 +545,16 @@ Even inside your own worktree, operate defensively:
545545
that one needs a real build.
546546
10. **A clean merge is not a working merge — but scope the re-check to the overlap**
547547
([why](docs/agents/multi-agent-discipline.md#why-a-clean-merge-is-not-a-working-merge)). **Before opening a PR, pull
548-
`main`, refresh build state (§9), and run the full suite once.** After the PR is open, merge `main` only on a
549-
GitHub-reported conflict, a `main`-caused CI red or a queue removal, then only the scoped re-checks; a breaking PR's
550-
dogfood runs on a CI runner once labelled `needs:dogfood-battery`, and the landing door reads that result on its
551-
final head ([detail](docs/agents/multi-agent-discipline.md#where-joint-breakage-surfaces)):
548+
`main`, refresh build state (§9), and run targeted gates; CI runs the full suite.** After the PR is open, merge
549+
`main` only on a GitHub-reported conflict, a `main`-caused CI red or a queue removal, then only the scoped
550+
re-checks; a breaking PR's dogfood runs on a CI runner once labelled `needs:dogfood-battery`, and the landing door
551+
reads that result on its final head ([detail](docs/agents/multi-agent-discipline.md#where-joint-breakage-surfaces)):
552552
- **Always:** rebuild what the merge touched, and if `packages/spec` moved on either side,
553553
`pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated` — only a rebuild of
554554
the merged source validates a generated snapshot (`api-surface`, baselines); never trust git's textual merge of a
555555
generated file. Then assert your branch's *delta vs `main`* is still exactly what your PR intends.
556-
- **Full `pnpm typecheck && pnpm test` again only when** the incoming commits touch the packages or behavior your
557-
diff does, or a conflict occurred outside trivially-mechanical files.
556+
- **Targeted gates again only when** the incoming commits touch the packages or behavior your diff does, or a
557+
conflict occurred outside trivially-mechanical files.
558558
11. **Generated artifacts don't text-merge — a driver defers them and `pre-commit`
559559
collects the debt.** `.gitattributes` routes the generator-owned artifacts to `merge=os-regen`
560560
(`pnpm check:merge-driver` reconciles both directions); the driver does **not** regenerate — it records
@@ -1012,7 +1012,7 @@ Both non-handshake shapes, and how to classify and probe your own:
10121012

10131013
## Post-Task Checklist
10141014

1015-
1. `pnpm test` — verify nothing broke. Touched a type-check-covered package? `pnpm typecheck` too.
1015+
1. Targeted gates (Multi-agent discipline §10): touched packages' `test` and `typecheck`; CI runs the full suite.
10161016
2. **Land it — don't leave passing work in the working tree.** Once tests pass, create
10171017
a feature branch, commit, push, open a PR, and — once remote CI is fully green and
10181018
the PR is accepted — arm auto-merge so the queue lands it (Multi-agent discipline §7). A finished task
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#38709] The rename engine's rewrite of an `object_extension` row writes only
5+
* keys the strict `ObjectExtensionSchema` admits — the body is keyed by
6+
* `extend`, and the engine gives it no `name` — and the copy follows the
7+
* copied object: an `extend` naming an object this copy renames takes that
8+
* object's copy name, prefixed or bare, and the row is named by it.
9+
* `planNamespaceRename` is the one engine both copy doors call —
10+
* `duplicatePackage` per stored row, and `importUnmanagedPackage` with
11+
* `targetNamespace` per planned item — so the pin runs the engine under each
12+
* door's `retryVerb`. The duplicate door's own landing pin is the CONTROL in
13+
* the objectql `protocol-custom-arrangement.test.ts` (an extension of an object
14+
* outside the package) and the bare-object duplicate reading beside it; the unmanaged
15+
* import refuses a manifest's `objectExtensions` at its plan (`uncopyable`),
16+
* pinned in `package-unmanaged-install.test.ts`.
17+
*/
18+
import { describe, expect, it } from 'vitest';
19+
import { ObjectExtensionSchema } from '@objectstack/spec/data';
20+
import { planNamespaceRename } from './package-namespace-rename.js';
21+
22+
const items = [
23+
{ type: 'object', name: 'crm_lead', body: { name: 'crm_lead', fields: {} } },
24+
{ type: 'object', name: 'ticket', body: { name: 'ticket', fields: {} } },
25+
{ type: 'object_extension', name: 'crm_lead', body: { extend: 'crm_lead' } },
26+
{ type: 'object_extension', name: 'ticket', body: { extend: 'ticket' } },
27+
{ type: 'object_extension', name: 'other_account', body: { extend: 'other_account' } },
28+
{ type: 'object_extension', name: 'crm_platform', body: { extend: 'crm_platform' } },
29+
];
30+
31+
const parses = (item: unknown) => {
32+
const parsed = ObjectExtensionSchema.safeParse(item);
33+
expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true);
34+
};
35+
36+
describe('planNamespaceRename — an `object_extension` copy carries no `name` and follows the copied object (#38709)', () => {
37+
for (const retryVerb of ['duplicate', 'install'] as const) {
38+
const rename = () => planNamespaceRename({
39+
sourcePackageId: 'com.example.crm', sourceNamespace: 'crm', targetNamespace: 'acme', items, retryVerb,
40+
});
41+
42+
it(`${retryVerb}: a bare object the copy renames — \`extend\` and the row name follow it to the copy's object`, () => {
43+
const r = rename();
44+
const outcome = r.rewrite('object_extension', 'ticket', { extend: 'ticket', priority: 300 });
45+
expect(outcome).toEqual({ item: { extend: 'acme_ticket', priority: 300 } });
46+
expect(r.copyName('object_extension', 'ticket')).toBe('acme_ticket');
47+
parses((outcome as { item: unknown }).item);
48+
});
49+
50+
it(`${retryVerb}: a prefixed object the copy renames — followed once, never renamed twice`, () => {
51+
const r = rename();
52+
expect(r.rewrite('object_extension', 'crm_lead', { extend: 'crm_lead' })).toEqual({ item: { extend: 'acme_lead' } });
53+
expect(r.copyName('object_extension', 'crm_lead')).toBe('acme_lead');
54+
});
55+
56+
it(`${retryVerb}: CONTROL — an \`extend\` naming an object the copy does not hold keeps its name, row and body alike`, () => {
57+
const r = rename();
58+
const outcome = r.rewrite('object_extension', 'other_account', { extend: 'other_account', priority: 300 });
59+
expect(outcome).toEqual({ item: { extend: 'other_account', priority: 300 } });
60+
expect(r.copyName('object_extension', 'other_account')).toBe('other_account');
61+
parses((outcome as { item: unknown }).item);
62+
// Spelled with the source prefix, yet not an object the package holds: still not renamed.
63+
expect(r.rewrite('object_extension', 'crm_platform', { extend: 'crm_platform' })).toEqual({ item: { extend: 'crm_platform' } });
64+
expect(r.copyName('object_extension', 'crm_platform')).toBe('crm_platform');
65+
// Every other type still takes its copy name.
66+
expect(r.rewrite('object', 'crm_lead', { name: 'crm_lead', fields: {} }))
67+
.toEqual({ item: { name: 'acme_lead', fields: {} } });
68+
});
69+
}
70+
});

‎packages/metadata-protocol/src/package-namespace-rename.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,11 @@ export function planNamespaceRename(input: NamespaceRenameInput): NamespaceRenam
749749
// `object` followed the copy, so the copy's container sat under a name
750750
// the source's container holds — the shadowing the qualified rule above
751751
// closes for `ticket.board`.
752+
// An `object_extension` row is named by its target (`listSlotNameOf`), so
753+
// its copy name is its target's copy name, read off the same map
754+
// `rewrite` maps `extend` through: the row and its `extend` never part.
752755
const copyName = (type: string, name: string): string =>
753-
type === 'object'
756+
type === 'object' || (PLURAL_TO_SINGULAR[String(type)] ?? String(type)) === 'object_extension'
754757
? (renameMap.get(name) ?? name)
755758
: isCapabilityType(type)
756759
? (capabilityRenames.get(name) ?? name)
@@ -830,7 +833,29 @@ export function planNamespaceRename(input: NamespaceRenameInput): NamespaceRenam
830833
};
831834
}
832835
if (rewritten && typeof rewritten === 'object' && !Array.isArray(rewritten)) {
833-
rewritten.name = copyName(type, name);
836+
// [#38709] An `object_extension` body is keyed by `extend` and
837+
// carries no `name`: `ObjectExtensionSchema` is strict and
838+
// refuses one (`listSlotNameOf` in
839+
// `protocol-object-extension-item.ts` reads the row's identity
840+
// off `extend`). Setting it here refused every copied
841+
// extension at the save door, for a key nobody wrote.
842+
if (singular !== 'object_extension') rewritten.name = copyName(type, name);
843+
// ⭐ A COPIED EXTENSION FOLLOWS THE COPIED OBJECT. `extend` names
844+
// the object the extension merges into; when that object is one
845+
// this copy renames, the copy's extension extends the copy's
846+
// object, never the source's. It is read off the SOURCE body and
847+
// mapped through `renameMap` whole, so a prefixed name the
848+
// free-text pass above already renamed is not renamed twice,
849+
// and a bare one (`ticket` → `acme_ticket`), which that pass
850+
// never reaches, follows too. An object the copy does not hold
851+
// (a platform object, another package's) is not in the map and
852+
// keeps its name. The row's name is this same target
853+
// (`copyName` above reads the same map).
854+
const extend = (item as { extend?: unknown } | null | undefined)?.extend;
855+
if (singular === 'object_extension' && typeof extend === 'string') {
856+
const target = renameMap.get(extend);
857+
if (target !== undefined) rewritten.extend = target;
858+
}
834859
if (singular === 'permission' && rewritten.fields
835860
&& typeof rewritten.fields === 'object' && !Array.isArray(rewritten.fields)) {
836861
const result = rewriteFieldRuleKeys(rewritten.fields);

‎packages/objectql/src/protocol-custom-arrangement.test.ts‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ describe('ADR-0146 D10 — a `.custom` package that is not the object\'s pair is
343343
expect(await outcome(() => saveExtension(protocol, ADDON_PAIR, { fields: { addon_score__c: text('addon_score__c', 'Score') } }))).toEqual({ ok: true });
344344
});
345345

346-
it('a package duplicate refuses the copied arrangement in a plain target and in another App\'s pair, per row; CONTROL: the copy of a row without the keys lands', async () => {
346+
it('a package duplicate refuses the copied arrangement in a plain target and in another App\'s pair, per row; CONTROL: the copy of a row without the keys lands in `copied[]` and is stored', async () => {
347347
const { protocol, stores } = await boot();
348348
// No `__c` field in the row: the copy into a plain package is refused for the arrangement alone.
349349
const OWNERS_ONLY = { fieldGroups: [{ key: 'basic', label: 'Basic', fields: ['name', 'company'] }], relatedLists: ARRANGEMENT.relatedLists };
@@ -370,14 +370,49 @@ describe('ADR-0146 D10 — a `.custom` package that is not the object\'s pair is
370370
}
371371

372372
// CONTROL: the same duplicate of a source whose row writes no arrangement
373-
// key is not refused for an arrangement. (Measured on this tree: the copy
374-
// still fails, on the copy's own `name` the duplicate sets on every item,
375-
// which the strict extension schema refuses; that is outside this rule.)
373+
// key lands. The copied body is keyed by `extend` alone: the rename gives
374+
// an `object_extension` no `name`, a key the strict extension schema
375+
// refuses (objectstack#38709).
376376
stores.get('sys_metadata')!.set('r_residue', { ...pairRow!, id: 'r_residue', package_id: SRC, metadata: JSON.stringify({ extend: OBJ }) });
377377
const res = await protocol.duplicatePackage({ sourcePackageId: SRC, targetPackageId: `${SVC}.custom`, targetNamespace: 'svc_custom' });
378378
const errors = (res.failed ?? []).filter((f: any) => f.type === 'object_extension').map((f: any) => String(f.error));
379379
const copied = (res.copied ?? []).filter((c: any) => c.type === 'object_extension');
380-
expect(errors.length + copied.length, 'precondition: the row was copied or tried').toBe(1);
381-
for (const error of errors) expect(error).not.toContain('ADR-0146 D10');
380+
expect(errors, 'no object_extension row failed').toEqual([]);
381+
expect(copied.map((c: any) => c.name), 'the row is copied').toEqual([OBJ]);
382+
const stored = rowsIn(stores, `${SVC}.custom`);
383+
expect(stored.map((r) => r.name), 'the copy is stored under its target').toEqual([OBJ]);
384+
expect(JSON.parse(String(stored[0]!.metadata)), 'the stored body is keyed by `extend`, with no `name`').toEqual({ extend: OBJ });
385+
});
386+
});
387+
388+
/**
389+
* objectstack#38709 — a duplicate's copied `object_extension` follows the
390+
* copied object. The source package holds a bare-named object (`ticket`, a row
391+
* stored before the namespace-prefix rule) and an extension of it; the copy
392+
* into `acme` renames the object to `acme_ticket`, and the copied extension
393+
* must extend that copy, never the source's object.
394+
*/
395+
describe('objectstack#38709 — a duplicated extension of the package\'s own bare object extends the copy', () => {
396+
it('the copy lands in `copied[]` under the copy\'s object name, its stored `extend` is the copy\'s object, and the source\'s extension is untouched', async () => {
397+
const { protocol, stores } = await boot();
398+
const SRC = 'com.example.tickets';
399+
await protocol.installPackage({ manifest: { id: SRC, name: 'tickets', version: '0.1.0', type: 'app', namespace: 'tix' } });
400+
// A stored row through the real door: the shape the two source rows below copy.
401+
expect(await outcome(() => saveExtension(protocol, PAIR, {}))).toEqual({ ok: true });
402+
const sys = stores.get('sys_metadata')!;
403+
const [template] = Array.from(sys.values()).filter((r) => r.type === 'object_extension' && r.package_id === PAIR);
404+
const row = (id: string, type: string, name: string, body: Record<string, unknown>) =>
405+
sys.set(id, { ...(template ?? {}), id, type, name, package_id: SRC, metadata: JSON.stringify(body) });
406+
if (!template) throw new Error('precondition: a stored metadata row to copy the row shape from');
407+
row('r_ticket', 'object', 'ticket', { name: 'ticket', label: 'Ticket', sharingModel: 'private', fields: { title: text('title', 'Title') } });
408+
row('r_ticket_ext', 'object_extension', 'ticket', { extend: 'ticket' });
409+
410+
const res = await protocol.duplicatePackage({ sourcePackageId: SRC, targetPackageId: 'com.example.acme', targetNamespace: 'acme' });
411+
expect((res.failed ?? []).map((f: any) => `${f.type}/${f.name}: ${f.error}`), 'nothing failed').toEqual([]);
412+
expect((res.copied ?? []).filter((c: any) => c.type === 'object_extension').map((c: any) => c.name), 'the extension is copied, under the copy\'s object name').toEqual(['acme_ticket']);
413+
const copies = Array.from(sys.values()).filter((r) => r.type === 'object_extension' && r.package_id === 'com.example.acme');
414+
expect(copies.map((r) => r.name), 'the copy is named by the copy\'s object').toEqual(['acme_ticket']);
415+
expect(JSON.parse(String(copies[0]!.metadata)), 'the copy extends the copy\'s object').toEqual({ extend: 'acme_ticket' });
416+
expect(JSON.parse(String(sys.get('r_ticket_ext')!.metadata)), 'the source row is unchanged').toEqual({ extend: 'ticket' });
382417
});
383418
});

0 commit comments

Comments
 (0)