Skip to content

Commit be4d35b

Browse files
committed
fix(metadata-protocol,runtime): a seed load that throws part-way still reports landed ids for the datasets that finished
SeedLoadPartialWrites carries the finished datasets' landedIds/insertedIds, and both receipt producers (applySeedBodies' catch and the runtime fallback) fold them through seedAppliedLanded. The dataset that threw stays out of landed: its ids are only partly known when it throws. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzht5n1PKh96TqTfrvV
1 parent f506b79 commit be4d35b

10 files changed

Lines changed: 232 additions & 20 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/metadata-protocol': minor
4+
'@objectstack/runtime': patch
5+
---
6+
7+
fix(metadata-protocol,runtime): a seed load that throws part-way still reports `seedApplied.landed` for the datasets that finished before the throw
8+
9+
Clause-②: yes (widening: a thrown load's receipt carries `landed` for the datasets that finished, where it carried none)
10+
Metadata-protocol: semantic
11+
12+
- **`@objectstack/spec`: `seedApplied.landed`** (both publish responses) now says what it covers on a load that threw part-way (`success: false` with `error`): only the datasets that FINISHED before the throw. The dataset that threw is not listed (its rows are in `inserted` / `updated`, its object in `error`). Absent `landed` now means the apply failed before any load ran, or the producer reports no ids; a throw before any dataset finished reports `landed: []`.
13+
- **`@objectstack/metadata-protocol`**: `SeedLoadPartialWrites` gains `finished`, the finished datasets' `object` / `landedIds` / `insertedIds` in load order, and `applySeedBodies`' catch folds it through the same `seedAppliedLanded` projection (same two lists, same 200 cap) the returned path uses. `seedLoadPartialWrites` and `SeedLoadPartialWrites` are exported from the package root.
14+
- **`@objectstack/runtime`**: the package-publish door's fallback seed apply reads the same `seedLoadPartialWrites` off a thrown load and reports the same `landed`.
15+
- Why the dataset that threw is left out: its ids are only partly known when it throws. A batched insert whose response was lost may have committed rows whose ids never came back, so a list of the ids the loader did see would read as complete while missing rows.

‎content/docs/references/api/protocol.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,7 @@ The authoring surface of a metadata write. Closed: `copilot` is an AI assistant'
25462546
| **updated** | `integer` | ✅ | Rows updated by the externalId-keyed upsert. |
25472547
| **error** | `string` | optional | Single failure message, present when the seed apply threw before the loader ran (including "no readable seed bodies"). |
25482548
| **errors** | `any[]` | optional | Per-record failures reported by the seed loader. Present only when the loader ran and returned a non-empty error list. |
2549-
| **landed** | `{ object: string; inserted: object; matched: object }[]` | optional | Per object, the stored rows the seed landed on: `inserted` (created by this publish) and `matched` (pre-existing rows a seed key matched), each capped at `SEED_APPLIED_LANDED_IDS_CAP` (200) ids with `total` and `truncated` stating any cut. One entry per object the loader ran, empty lists included. ABSENT means "not reported" — the apply failed before or while loading (see `error`), or the producer reports no ids — never "no rows landed". |
2549+
| **landed** | `{ object: string; inserted: object; matched: object }[]` | optional | Per object, the stored rows the seed landed on: `inserted` (created by this publish) and `matched` (pre-existing rows a seed key matched), each capped at `SEED_APPLIED_LANDED_IDS_CAP` (200) ids with `total` and `truncated` stating any cut. One entry per object the loader ran, empty lists included. When the load threw part-way (`success: false` with `error`), it lists only the datasets that FINISHED before the throw; the dataset that threw is not listed (its rows are in the counts, its object in `error`). ABSENT means "not reported" — the apply failed before any load ran (see `error`), or the producer reports no ids — never "no rows landed". |
25502550

25512551
### Nested Shape: `PublishMetaItemResponse.materializeApplied`
25522552

@@ -2647,7 +2647,7 @@ The authoring surface of a metadata write. Closed: `copilot` is an AI assistant'
26472647
| **error** | `string` | optional | Single failure message, present when the apply failed before the loader ran (including "no readable seed bodies"). When the failure is the seed bodies' own schema refusal, this is a one-sentence headline and the per-path detail rides `issues[]`. |
26482648
| **errors** | `any[]` | optional | Per-record failures reported by the seed loader, plus any seed-body read failures. May be present and empty on a clean load. |
26492649
| **issues** | `{ path: string; message: string; code?: string }[]` | optional | Structured spec-validation findings behind `error`, present when the apply was refused by the seed bodies' own schema — the declared 422 `seedRequestValidationError` mints. The per-path detail lives HERE, once; `error` stays a one-sentence headline. Absent on non-validation failures (driver faults, unreadable bodies), whose whole story is `error` / `errors[]`. |
2650-
| **landed** | `{ object: string; inserted: object; matched: object }[]` | optional | Per object, the stored rows the seed landed on: `inserted` (created by this publish) and `matched` (pre-existing rows a seed key matched), each capped at `SEED_APPLIED_LANDED_IDS_CAP` (200) ids with `total` and `truncated` stating any cut. One entry per object the loader ran, empty lists included. ABSENT means "not reported" — the apply failed before or while loading (see `error`), or the producer reports no ids — never "no rows landed". |
2650+
| **landed** | `{ object: string; inserted: object; matched: object }[]` | optional | Per object, the stored rows the seed landed on: `inserted` (created by this publish) and `matched` (pre-existing rows a seed key matched), each capped at `SEED_APPLIED_LANDED_IDS_CAP` (200) ids with `total` and `truncated` stating any cut. One entry per object the loader ran, empty lists included. When the load threw part-way (`success: false` with `error`), it lists only the datasets that FINISHED before the throw; the dataset that threw is not listed (its rows are in the counts, its object in `error`). ABSENT means "not reported" — the apply failed before any load ran (see `error`), or the producer reports no ids — never "no rows landed". |
26512651

26522652
### Nested Shape: `PublishPackageDraftsResponse.materializeApplied`
26532653

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,14 @@ export {
281281
} from './migrations/recorded-by-sentinel.js';
282282
export type { SentinelHistoryRow } from './migrations/recorded-by-sentinel.js';
283283

284-
export { SeedLoaderService, type SeedLoaderServiceOptions } from './seed-loader.js';
284+
export {
285+
SeedLoaderService,
286+
type SeedLoaderServiceOptions,
287+
// [#30429] The runtime's fallback seed apply reads a thrown load's finished
288+
// datasets through it, so its receipt reports `landed` as this package's does.
289+
seedLoadPartialWrites,
290+
type SeedLoadPartialWrites,
291+
} from './seed-loader.js';
285292
export { runBuildProbes } from './build-probes.js';
286293
export type {
287294
RuntimeBuildIssue,

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ export async function applySeedBodies(
134134
// [#30348] Which rows landed, per object: created by this publish
135135
// vs pre-existing rows a seed key matched — the loader's own ids,
136136
// capped and folded by the one projection both receipt producers
137-
// share. Only on this path: a load that THREW (the catch below)
138-
// reports counts but no ids, so `landed` stays absent there —
139-
// "not reported", never "nothing landed".
137+
// share. [#30429] A load that THREW reports the same key from the
138+
// catch below, for the datasets that finished.
140139
landed: seedAppliedLanded(r.results),
141140
};
142141
} catch (e: any) {
@@ -168,6 +167,14 @@ export async function applySeedBodies(
168167
error: written?.failedObject
169168
? `seed apply stopped at the seed for object '${written.failedObject}': ${failure}`
170169
: failure,
170+
// [#30429] The rows of the datasets that FINISHED before the
171+
// throw, through the same projection as the returned path — the
172+
// ids a reader clearing a partial publish's sample data needs. The
173+
// dataset that threw is not listed (its ids are only partly known,
174+
// see `SeedLoadPartialWrites.finished`); its rows are in the
175+
// counts above and its object in `error`. No reading means no
176+
// load ran, so `landed` stays absent: "not reported".
177+
...(written ? { landed: seedAppliedLanded(written.finished) } : {}),
171178
// [#10524] A DECLARED refusal's structured findings ride the
172179
// receipt beside the headline `error` — the message is a
173180
// one-sentence headline now, so this is where the per-key

‎packages/metadata-protocol/src/seed-loader-seed-files.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,15 @@ describe('seedLoadPartialWrites: the rows a thrown load had written', () => {
558558
expect((err as Error).message).toBe('the storage service is down');
559559
expect((store.pw_tag ?? []).map((r) => r.name).sort()).toEqual(['T1', 'T2']);
560560
expect((store.pw_doc ?? []).map((r) => r.code)).toEqual(['D1']);
561-
expect(seedLoadPartialWrites(err)).toEqual({ inserted: 3, updated: 0, failedObject: 'pw_doc' });
561+
// [#30429] The finished dataset (`pw_tag`) carries its landed ids — the
562+
// store's own; the dataset that threw (`pw_doc`) is in the counts but not
563+
// in `finished`, although its row D1 was written before the throw.
564+
const tagIds = (store.pw_tag ?? []).map((r) => String(r.id));
565+
expect(tagIds).toHaveLength(2);
566+
expect(seedLoadPartialWrites(err)).toEqual({
567+
inserted: 3, updated: 0, failedObject: 'pw_doc',
568+
finished: [{ object: 'pw_tag', landedIds: tagIds, insertedIds: tagIds }],
569+
});
562570
});
563571

564572
it('a load that throws before any dataset wrote: zero, and no object named', async () => {
@@ -569,7 +577,7 @@ describe('seedLoadPartialWrites: the rows a thrown load had written', () => {
569577

570578
expect((err as Error).message).toBe('metadata store unavailable');
571579
expect(store).toEqual({});
572-
expect(seedLoadPartialWrites(err)).toEqual({ inserted: 0, updated: 0 });
580+
expect(seedLoadPartialWrites(err)).toEqual({ inserted: 0, updated: 0, finished: [] });
573581
});
574582

575583
it('an error that did not come out of a load carries no reading', () => {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { isMissingTableError } from '@objectstack/metadata/errors';
4848
// [#25779] `seedFile(path)` values: stored, kept across replays, and owned by
4949
// the row that holds them; an id-shaped file value that names no file refused.
5050
import { SeedDatasetFiles, type SeedFileClaims } from './seed-files.js';
51+
import type { SeedLandingResult } from './seed-applied-landed.js';
5152

5253
interface Logger {
5354
info(message: string, meta?: Record<string, any>): void;
@@ -581,6 +582,21 @@ export interface SeedLoadPartialWrites {
581582
readonly updated: number;
582583
/** The object of the dataset that was loading when the load threw; absent when it threw outside any dataset. */
583584
readonly failedObject?: string;
585+
/**
586+
* [#30429] The datasets that FINISHED before the throw, in load order, each
587+
* with the row ids it landed on (`landedIds` / `insertedIds`, exactly as its
588+
* returned result carries them) — what the publish receipt projects into
589+
* `seedApplied.landed` with the same `seedAppliedLanded` a returned load
590+
* uses. Empty when the throw came before any dataset finished.
591+
*
592+
* The dataset that threw is NOT here, although its rows are in the counts
593+
* above: its ids are only partly known when it throws. A batched insert
594+
* whose response was lost may have committed rows whose ids never came back
595+
* (the loader re-reads by key on its retry for exactly that reason), so a
596+
* list of the ids it did see would read as complete while missing rows. A
597+
* finished dataset's list is complete; that is the line this field draws.
598+
*/
599+
readonly finished: readonly SeedLandingResult[];
584600
}
585601

586602
/** The writes a thrown load had made, keyed by the error it threw. */
@@ -815,6 +831,9 @@ export class SeedLoaderService implements ISeedLoaderService {
815831
inserted: finished.reduce((sum, r) => sum + r.inserted, 0) + (loading?.written.inserted ?? 0),
816832
updated: finished.reduce((sum, r) => sum + r.updated, 0) + (loading?.written.updated ?? 0),
817833
...(loading ? { failedObject: loading.object } : {}),
834+
// A snapshot of the ids alone: the results array is the live one pass 2
835+
// writes its counters into.
836+
finished: finished.map((r) => ({ object: r.object, landedIds: r.landedIds, insertedIds: r.insertedIds })),
818837
};
819838
const carrier = err !== null && typeof err === 'object' ? err : new Error(String(err));
820839
partialWritesByError.set(carrier, partial);

‎packages/objectql/src/publish-seed-receipt-landed-ids.test.ts‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,46 @@ describe('seedApplied.landed — the rows a published seed landed on (#30348)',
284284
expect('seedApplied' in res).toBe(false);
285285
});
286286

287-
it('a load that threw reports no ids: `landed` absent means "not reported", never "nothing landed"', async () => {
287+
// [#30429] A load that THREW part-way reports `landed` for the datasets
288+
// that FINISHED before the throw — the same projection, the same two
289+
// lists — and leaves the dataset that threw out: its ids are only partly
290+
// known when it throws (`SeedLoadPartialWrites.finished`), while its rows
291+
// stay in the counts and its object in `error`.
292+
it('a load that threw: `landed` lists the seeds that finished, created vs matched, and not the one that threw', async () => {
288293
const { p, engine } = await makeProtocol();
294+
// A customer's own row sharing a seed key, so both lists are exercised.
295+
const customer: any = await engine.insert(ITEM, { name: 'R1' }, { context: { isSystem: true } } as any);
289296
await stage(p, [
290-
{ type: 'seed', name: 'a_good', item: seed(['R1']) },
297+
{ type: 'seed', name: 'a_good', item: seed(['R1', 'R2', 'R3']) },
291298
{ type: 'seed', name: 'z_missing', item: { object: MISSING, mode: 'ignore', records: [{ name: 'Z' }] } },
292299
]);
293300

294301
const res: any = await p.publishPackageDrafts({ packageId: PKG });
295302

296-
// Positive control: the good seed's row DID land; only the ids are unreported.
297-
expect((await rowsOf(engine)).map((r) => r.name)).toEqual(['R1']);
303+
const rows = await rowsOf(engine);
304+
// Positive control: the good seed's rows DID land before the throw.
305+
expect(rows.map((r) => r.name)).toEqual(['R1', 'R2', 'R3']);
298306
expect(res.seedApplied.success).toBe(false);
299-
expect(res.seedApplied.inserted).toBe(1);
300-
expect('landed' in res.seedApplied).toBe(false);
307+
expect(res.seedApplied.error).toContain(`'${MISSING}'`);
308+
expect(res.seedApplied.inserted).toBe(2);
309+
const created = rows.filter((r) => r.name !== 'R1').map((r) => r.id);
310+
// One entry, for the seed that finished; none for the object that threw.
311+
expect(res.seedApplied.landed).toEqual([{ object: ITEM, inserted: list(created), matched: list([customer.id]) }]);
312+
// The wire contract keeps it on a failed apply too.
313+
expect(PublishPackageDraftsResponseSchema.parse(res).seedApplied?.landed).toEqual(res.seedApplied.landed);
314+
});
315+
316+
it('a load that threw before any seed finished: `landed` is reported and empty, not absent', async () => {
317+
const { p, engine } = await makeProtocol();
318+
await stage(p, [{ type: 'seed', name: 'z_missing', item: { object: MISSING, mode: 'ignore', records: [{ name: 'Z' }] } }]);
319+
320+
const res: any = await p.publishPackageDrafts({ packageId: PKG });
321+
322+
expect(await rowsOf(engine)).toEqual([]);
323+
expect(res.seedApplied.success).toBe(false);
324+
expect(res.seedApplied.inserted).toBe(0);
325+
expect(res.seedApplied.error).toContain(`'${MISSING}'`);
326+
expect(res.seedApplied.landed).toEqual([]);
301327
});
302328

303329
it('the single-item door (`publishMetaItem`) carries the same `landed`, and its schema keeps it', async () => {

0 commit comments

Comments
 (0)