Skip to content

Commit 76ee199

Browse files
committed
fix(metadata-protocol): a registry listing that throws contributes no shipping packages
The artifact layer's package ids are best-effort context on a metadata-only host whose partial registry cannot list; the package-less lookup still answers, never looser than the gate before this change. Claude-Session: https://claude.ai/code/session_017ErfyP2Rx7XWHJA27QjyUi Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4413da7 commit 76ee199

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

‎packages/metadata-protocol/src/protocol.ts‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16534,31 +16534,37 @@ export class ObjectStackProtocolImplementation implements
1653416534
* the artifact lookup does not (the `_lock` gate bound a disabled
1653516535
* package's artifact before #21803 when it was registered first), so the
1653616536
* installed packages are read too: a disabled package is still installed.
16537-
* A registry double without either listing contributes nothing here, and
16538-
* {@link shippedArtifactsOf} then answers the package-less lookup alone.
16537+
* A registry without either listing, or whose listing throws (a
16538+
* metadata-only host's partial registry: listing there is best-effort
16539+
* context, never the reason a write fails), contributes nothing here, and
16540+
* {@link shippedArtifactsOf} then answers with the package-less lookup and
16541+
* whatever could be listed: never looser than the `_lock` gate before
16542+
* #21803, which asked that lookup alone.
1653916543
*/
1654016544
private artifactPackageIds(type: string): Set<string> {
1654116545
const registry = (this.engine as any)?.registry;
1654216546
const ids = new Set<string>();
1654316547
if (!registry) return ids;
16544-
const addId = (id: unknown): void => {
16545-
if (typeof id === 'string' && id !== '' && id !== 'sys_metadata') ids.add(id);
16548+
const addIds = (read: () => unknown, idOf: (entry: any) => unknown): void => {
16549+
let listed: unknown;
16550+
try {
16551+
listed = read();
16552+
} catch {
16553+
return; // See this method's header: the package-less lookup still answers.
16554+
}
16555+
if (!Array.isArray(listed)) return;
16556+
for (const entry of listed) {
16557+
const id = idOf(entry);
16558+
if (typeof id === 'string' && id !== '' && id !== 'sys_metadata') ids.add(id);
16559+
}
1654616560
};
1654716561
if (typeof registry.listItems === 'function') {
1654816562
for (const spelling of new Set([PLURAL_TO_SINGULAR[type] ?? type, type])) {
16549-
const listed: unknown = registry.listItems(spelling);
16550-
if (!Array.isArray(listed)) continue;
16551-
for (const entry of listed) addId((entry as { _packageId?: unknown } | null | undefined)?._packageId);
16563+
addIds(() => registry.listItems(spelling), (entry) => entry?._packageId);
1655216564
}
1655316565
}
1655416566
if (typeof registry.getAllPackages === 'function') {
16555-
const installed: unknown = registry.getAllPackages();
16556-
if (Array.isArray(installed)) {
16557-
for (const record of installed) {
16558-
const r = record as { manifest?: { id?: unknown }; id?: unknown } | null | undefined;
16559-
addId(r?.manifest?.id ?? r?.id);
16560-
}
16561-
}
16567+
addIds(() => registry.getAllPackages(), (record) => record?.manifest?.id ?? record?.id);
1656216568
}
1656316569
return ids;
1656416570
}

0 commit comments

Comments
 (0)