@defrex/autobuild 1.15.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +110 -10
- package/docs/answering-blocked-builds.md +34 -1
- package/docs/architecture.md +41 -7
- package/docs/configuration.md +41 -7
- package/docs/dispatcher-hosting.md +3 -0
- package/docs/operator-api.md +15 -5
- package/docs/plugin-authoring.md +1 -0
- package/docs/remote-store-protocol.md +13 -3
- package/docs/remote-ticket-protocol.md +3 -1
- package/docs/restacking.md +41 -1
- package/docs/setup.md +15 -6
- package/docs/troubleshooting.md +51 -3
- package/docs/workspaces.md +4 -1
- package/package.json +3 -3
- package/packages/core/src/cli/accounts.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +14 -1
- package/packages/core/src/cli/binary.ts +10 -7
- package/packages/core/src/cli/dispatch.ts +610 -356
- package/packages/core/src/cli/secrets.ts +2 -0
- package/packages/core/src/config/schema.ts +15 -2
- package/packages/core/src/events/payloads.ts +8 -5
- package/packages/core/src/events/repository.ts +12 -6
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e28c68e63cbd265f.json +108 -0
- package/packages/core/src/kernel/engine.ts +118 -0
- package/packages/core/src/kernel/reconcile-restack.ts +72 -9
- package/packages/core/src/kernel/reducer-revisions.ts +1 -0
- package/packages/core/src/kernel/tracked-dirt.ts +173 -0
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/index.ts +10 -0
- package/packages/core/src/operator/merged-builds.ts +51 -0
- package/packages/core/src/operator/registry.ts +190 -101
- package/packages/core/src/operator/repo-argument.ts +43 -0
- package/packages/core/src/ports/tickets/grants.ts +2 -0
- package/packages/core/src/ports/tickets/remote.ts +2 -0
- package/packages/core/src/ports/types.ts +25 -4
- package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +811 -169
- package/packages/core/src/processes/build-child.ts +15 -1
- package/packages/core/src/processes/build-runner.ts +349 -20
- package/packages/core/src/processes/dispatcher.ts +509 -104
- package/packages/core/src/processes/harvest-child.ts +21 -1
- package/packages/core/src/processes/harvest-runner.ts +82 -35
- package/packages/core/src/processes/invocation-budget.ts +6 -0
- package/packages/core/src/processes/launch-cut.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/provisioning-progress.ts +23 -0
- package/packages/core/src/processes/repo-view.ts +25 -4
- package/packages/core/src/processes/workspace-preparation.ts +1 -0
- package/packages/core/src/store/adapter.ts +34 -5
- package/packages/core/src/store/build-feed.ts +148 -22
- package/packages/core/src/store/build-scope.ts +12 -3
- package/packages/core/src/store/caller-attribution.ts +170 -0
- package/packages/core/src/store/contract.ts +1038 -165
- package/packages/core/src/store/local/schema.ts +12 -1
- package/packages/core/src/store/local/store.ts +260 -25
- package/packages/core/src/store/memory.ts +156 -9
- package/packages/core/src/store/phase-session.ts +23 -3
- package/packages/core/src/store/reducer-value-shapes.json +5351 -5338
- package/packages/core/src/store/remote/client.ts +90 -11
- package/packages/core/src/store/remote/credentials.ts +2 -0
- package/packages/core/src/store/remote/index.ts +31 -5
- package/packages/core/src/store/remote/protocol.ts +45 -8
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.16.0.json +36358 -0
- package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/remote/released-value-policy.ts +7 -0
- package/packages/core/src/store/session-handle.ts +12 -3
- package/packages/core/src/store/types.ts +48 -3
- package/packages/core/src/testing/reduced-read-budget.ts +310 -12
- package/skills/guide/SKILL.md +58 -9
- package/skills/guide/references/operator-api.md +15 -5
- package/skills/guide/references/plugin-authoring.md +1 -0
- package/skills/guide/references/remote-store-protocol.md +13 -3
- package/skills/guide/references/remote-ticket-protocol.md +3 -1
- package/skills/guide/references/restacking.md +41 -1
- package/skills/guide/references/setup.md +15 -6
- package/skills/operate/SKILL.md +31 -7
- package/templates/hosted-service/package.json +2 -2
|
@@ -285,7 +285,9 @@ export const buildChangePositions = sqliteTable(
|
|
|
285
285
|
* triggers in the writing transaction (`BUILD_LISTING_DDL`): kind from
|
|
286
286
|
* `build.created`, merged from the latest `build.completed` (cleared by
|
|
287
287
|
* `build.reopened`), and a mirror of `builds.updated_at`. One index per filter
|
|
288
|
-
* class and order makes every filtered page one bounded range scan.
|
|
288
|
+
* class and order makes every filtered page one bounded range scan. The merged
|
|
289
|
+
* listing's facts (`BUILD_LISTING_MERGE_FACTS_DDL`) add the merge time, PR and
|
|
290
|
+
* target, with one partial index in merge-time order. */
|
|
289
291
|
export const buildListingFacts = sqliteTable(
|
|
290
292
|
'build_listing_facts',
|
|
291
293
|
{
|
|
@@ -295,6 +297,12 @@ export const buildListingFacts = sqliteTable(
|
|
|
295
297
|
updatedAt: text('updated_at').notNull(),
|
|
296
298
|
node: integer('node').notNull().default(0),
|
|
297
299
|
merged: integer('merged').notNull().default(0),
|
|
300
|
+
// The merged listing's facts (`BUILD_LISTING_MERGE_FACTS_DDL`), appended
|
|
301
|
+
// by guarded ALTERs: merge time, PR and node target JSON.
|
|
302
|
+
mergedAt: text('merged_at'),
|
|
303
|
+
prNumber: integer('pr_number'),
|
|
304
|
+
prUrl: text('pr_url'),
|
|
305
|
+
target: text('target'),
|
|
298
306
|
},
|
|
299
307
|
(t) => [
|
|
300
308
|
index('build_listing_kind_created').on(t.repo, t.node, t.createdAt, t.slug),
|
|
@@ -312,6 +320,9 @@ export const buildListingFacts = sqliteTable(
|
|
|
312
320
|
index('build_listing_merged_kind_updated')
|
|
313
321
|
.on(t.repo, t.node, t.updatedAt, t.slug)
|
|
314
322
|
.where(sql`${t.merged} = 1`),
|
|
323
|
+
index('build_listing_merged_at')
|
|
324
|
+
.on(t.repo, t.mergedAt, t.slug)
|
|
325
|
+
.where(sql`${t.mergedAt} IS NOT NULL`),
|
|
315
326
|
],
|
|
316
327
|
)
|
|
317
328
|
|
|
@@ -15,14 +15,21 @@ import {
|
|
|
15
15
|
encodeBuildPageCursor,
|
|
16
16
|
hasBuildPageFilters,
|
|
17
17
|
requireBuildPageCursorOrder,
|
|
18
|
+
requireMergedCursor,
|
|
18
19
|
resolveBuildPageFilters,
|
|
19
20
|
parseChangePosition,
|
|
21
|
+
parseListingTarget,
|
|
20
22
|
resolveBuildPageLimit,
|
|
23
|
+
resolveMergedBuildWindow,
|
|
21
24
|
type BuildPage,
|
|
22
25
|
type BuildPageCursor,
|
|
23
26
|
type BuildPageFilters,
|
|
24
27
|
type BuildPageOptions,
|
|
25
28
|
type ChangedBuilds,
|
|
29
|
+
type MergedBuild,
|
|
30
|
+
type MergedBuildPage,
|
|
31
|
+
type MergedBuildPageOptions,
|
|
32
|
+
type MergedBuildWindow,
|
|
26
33
|
} from '../build-feed'
|
|
27
34
|
import type { RepoTickCompletion, RepoTickFinish, RepoTickObservation } from '../types'
|
|
28
35
|
/**
|
|
@@ -362,6 +369,126 @@ export function ensureBuildListingFacts(sqlite: Database): void {
|
|
|
362
369
|
.immediate()
|
|
363
370
|
}
|
|
364
371
|
|
|
372
|
+
/**
|
|
373
|
+
* The merged listing's facts (`listMergedBuildsPage`), added to
|
|
374
|
+
* `build_listing_facts` by guarded `ALTER`s so fresh and migrated databases
|
|
375
|
+
* reach one catalog. Triggers keep them in the writing transaction of every
|
|
376
|
+
* path, including an older runtime on the same file: the latest
|
|
377
|
+
* `build.completed` sets `merged_at` to its `ts` when merged (else NULL),
|
|
378
|
+
* `build.reopened` clears it, the latest `pr.opened` or `finalize.completed`
|
|
379
|
+
* sets the PR, `build.created` sets the target and a node's
|
|
380
|
+
* `node.parent-accepted` replaces it. The trigger names are new, so an older
|
|
381
|
+
* release never drops them. One partial index makes every merged page one
|
|
382
|
+
* backward range scan in merge-time order.
|
|
383
|
+
*/
|
|
384
|
+
export const BUILD_LISTING_MERGE_FACTS_DDL = `
|
|
385
|
+
ALTER TABLE build_listing_facts ADD COLUMN merged_at TEXT;
|
|
386
|
+
ALTER TABLE build_listing_facts ADD COLUMN pr_number INTEGER;
|
|
387
|
+
ALTER TABLE build_listing_facts ADD COLUMN pr_url TEXT;
|
|
388
|
+
ALTER TABLE build_listing_facts ADD COLUMN target TEXT;
|
|
389
|
+
CREATE INDEX IF NOT EXISTS build_listing_merged_at ON build_listing_facts(repo, merged_at, slug) WHERE merged_at IS NOT NULL;
|
|
390
|
+
CREATE TRIGGER IF NOT EXISTS events_listing_merge_facts_completed AFTER INSERT ON events
|
|
391
|
+
WHEN NEW.type = 'build.completed'
|
|
392
|
+
BEGIN UPDATE build_listing_facts SET merged_at = CASE WHEN json_extract(NEW.payload, '$.outcome') = 'merged' THEN NEW.ts END
|
|
393
|
+
WHERE slug = NEW.build; END;
|
|
394
|
+
CREATE TRIGGER IF NOT EXISTS events_listing_merge_facts_reopened AFTER INSERT ON events
|
|
395
|
+
WHEN NEW.type = 'build.reopened'
|
|
396
|
+
BEGIN UPDATE build_listing_facts SET merged_at = NULL WHERE slug = NEW.build; END;
|
|
397
|
+
CREATE TRIGGER IF NOT EXISTS events_listing_merge_facts_pr AFTER INSERT ON events
|
|
398
|
+
WHEN NEW.type IN ('pr.opened', 'finalize.completed')
|
|
399
|
+
BEGIN UPDATE build_listing_facts SET pr_number = json_extract(NEW.payload, '$.pr.number'),
|
|
400
|
+
pr_url = json_extract(NEW.payload, '$.pr.url') WHERE slug = NEW.build; END;
|
|
401
|
+
CREATE TRIGGER IF NOT EXISTS events_listing_merge_facts_created AFTER INSERT ON events
|
|
402
|
+
WHEN NEW.type = 'build.created'
|
|
403
|
+
BEGIN UPDATE build_listing_facts SET target = json_extract(NEW.payload, '$.target')
|
|
404
|
+
WHERE slug = NEW.build; END;
|
|
405
|
+
CREATE TRIGGER IF NOT EXISTS events_listing_merge_facts_parent AFTER INSERT ON events
|
|
406
|
+
WHEN NEW.type = 'node.parent-accepted'
|
|
407
|
+
BEGIN UPDATE build_listing_facts SET target = json_extract(NEW.payload, '$.next.target')
|
|
408
|
+
WHERE slug = NEW.build AND node = 1; END;
|
|
409
|
+
`
|
|
410
|
+
|
|
411
|
+
/** Runs once, when `merged_at` is first added: every existing row's merge
|
|
412
|
+
* facts from that build's latest relevant events, mirroring the triggers. */
|
|
413
|
+
const BUILD_LISTING_MERGE_FACTS_BACKFILL = `
|
|
414
|
+
UPDATE build_listing_facts SET
|
|
415
|
+
merged_at = CASE WHEN merged = 1 THEN (SELECT e.ts FROM events e
|
|
416
|
+
WHERE e.build = build_listing_facts.slug AND e.type = 'build.completed'
|
|
417
|
+
ORDER BY e.seq DESC LIMIT 1) END,
|
|
418
|
+
pr_number = (SELECT json_extract(e.payload, '$.pr.number') FROM events e
|
|
419
|
+
WHERE e.build = build_listing_facts.slug AND e.type IN ('pr.opened', 'finalize.completed')
|
|
420
|
+
ORDER BY e.seq DESC LIMIT 1),
|
|
421
|
+
pr_url = (SELECT json_extract(e.payload, '$.pr.url') FROM events e
|
|
422
|
+
WHERE e.build = build_listing_facts.slug AND e.type IN ('pr.opened', 'finalize.completed')
|
|
423
|
+
ORDER BY e.seq DESC LIMIT 1),
|
|
424
|
+
target = (SELECT CASE WHEN e.type = 'build.created' THEN json_extract(e.payload, '$.target')
|
|
425
|
+
ELSE json_extract(e.payload, '$.next.target') END FROM events e
|
|
426
|
+
WHERE e.build = build_listing_facts.slug AND (e.type = 'build.created'
|
|
427
|
+
OR (e.type = 'node.parent-accepted' AND build_listing_facts.node = 1))
|
|
428
|
+
ORDER BY e.seq DESC LIMIT 1);
|
|
429
|
+
`
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Install the merged listing's facts on `build_listing_facts`. Process start
|
|
433
|
+
* costs one `pragma_table_info` lookup once the column exists; only a database
|
|
434
|
+
* that lacks it takes a write transaction, rechecked under BEGIN IMMEDIATE,
|
|
435
|
+
* and backfills once. Call after `ensureBuildListingFacts`.
|
|
436
|
+
*/
|
|
437
|
+
export function ensureBuildListingMergeFacts(sqlite: Database): void {
|
|
438
|
+
const present = () =>
|
|
439
|
+
sqlite
|
|
440
|
+
.query(
|
|
441
|
+
"SELECT 1 AS present FROM pragma_table_info('build_listing_facts') WHERE name = 'merged_at'",
|
|
442
|
+
)
|
|
443
|
+
.get() !== null
|
|
444
|
+
if (present()) return
|
|
445
|
+
sqlite
|
|
446
|
+
.transaction(() => {
|
|
447
|
+
if (present()) return
|
|
448
|
+
sqlite.exec(BUILD_LISTING_MERGE_FACTS_DDL)
|
|
449
|
+
sqlite.exec(BUILD_LISTING_MERGE_FACTS_BACKFILL)
|
|
450
|
+
})
|
|
451
|
+
.immediate()
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* One merged page: a backward range scan of `build_listing_merged_at` from
|
|
456
|
+
* the cursor key, else `(until, '')`, stopping below `since`; at most
|
|
457
|
+
* `limit + 1` entries joined to `builds` by primary key. No event or reduced
|
|
458
|
+
* value is read.
|
|
459
|
+
*/
|
|
460
|
+
export function mergedBuildPageQuery(
|
|
461
|
+
repo: string,
|
|
462
|
+
limit: number,
|
|
463
|
+
window: MergedBuildWindow,
|
|
464
|
+
cursor?: BuildPageCursor,
|
|
465
|
+
): { sql: string; params: (string | number)[] } {
|
|
466
|
+
const where = ['f.repo = ?', 'f.merged_at IS NOT NULL']
|
|
467
|
+
const params: (string | number)[] = [repo]
|
|
468
|
+
const upper = cursor
|
|
469
|
+
? { at: cursor.at, slug: cursor.slug }
|
|
470
|
+
: window.until !== undefined
|
|
471
|
+
? { at: window.until, slug: '' }
|
|
472
|
+
: undefined
|
|
473
|
+
if (upper) {
|
|
474
|
+
where.push('(f.merged_at, f.slug) < (?, ?)')
|
|
475
|
+
params.push(upper.at, upper.slug)
|
|
476
|
+
}
|
|
477
|
+
if (window.since !== undefined) {
|
|
478
|
+
where.push('f.merged_at >= ?')
|
|
479
|
+
params.push(window.since)
|
|
480
|
+
}
|
|
481
|
+
params.push(limit)
|
|
482
|
+
return {
|
|
483
|
+
sql: `SELECT ${BUILD_PAGE_COLUMNS_B}, f.merged_at AS mergedAt, f.node AS listingNode,
|
|
484
|
+
f.pr_number AS prNumber, f.pr_url AS prUrl, f.target AS listingTarget
|
|
485
|
+
FROM build_listing_facts f INDEXED BY build_listing_merged_at JOIN builds b ON b.slug = f.slug
|
|
486
|
+
WHERE ${where.join(' AND ')}
|
|
487
|
+
ORDER BY f.merged_at DESC, f.slug DESC LIMIT ?`,
|
|
488
|
+
params,
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
365
492
|
/**
|
|
366
493
|
* A filtered build page: one backward range scan of the listing-facts index
|
|
367
494
|
* for the filter class and order, at most `limit + 1` entries, joined to
|
|
@@ -681,6 +808,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
681
808
|
}
|
|
682
809
|
ensureBuildChangePositions(this.sqlite)
|
|
683
810
|
ensureBuildListingFacts(this.sqlite)
|
|
811
|
+
ensureBuildListingMergeFacts(this.sqlite)
|
|
684
812
|
for (const table of ['events', 'repo_events']) {
|
|
685
813
|
const columns = this.sqlite.query(`PRAGMA table_info('${table}')`).all() as {
|
|
686
814
|
name: string
|
|
@@ -764,6 +892,7 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
764
892
|
for (const ddl of BOOTSTRAP_DDL) expected.exec(ddl)
|
|
765
893
|
ensureBuildChangePositions(expected)
|
|
766
894
|
ensureBuildListingFacts(expected)
|
|
895
|
+
ensureBuildListingMergeFacts(expected)
|
|
767
896
|
// ALTER appends columns, and legacy creation-order columns have a DEFAULT
|
|
768
897
|
// used only for backfill. Neither changes the target's runtime requirements.
|
|
769
898
|
const catalog = (database: Database) => {
|
|
@@ -1011,7 +1140,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1011
1140
|
? undefined
|
|
1012
1141
|
: requireBuildPageCursorOrder(decodeBuildPageCursor(opts.cursor), filters)
|
|
1013
1142
|
const order = buildPageOrder(filters)
|
|
1014
|
-
type PageRow = Omit<BuildRecordRow, 'ticket'> & {
|
|
1143
|
+
type PageRow = Omit<BuildRecordRow, 'ticket'> & {
|
|
1144
|
+
ticket: string | null
|
|
1145
|
+
cursorAt?: string
|
|
1146
|
+
}
|
|
1015
1147
|
let rows: PageRow[]
|
|
1016
1148
|
if (hasBuildPageFilters(filters)) {
|
|
1017
1149
|
const query = filteredBuildPageQuery(repo, limit + 1, filters, cursor)
|
|
@@ -1025,14 +1157,68 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1025
1157
|
}
|
|
1026
1158
|
const page = rows.slice(0, limit)
|
|
1027
1159
|
const builds = page.map(({ cursorAt: _, ...row }) =>
|
|
1028
|
-
this.toRecord({
|
|
1160
|
+
this.toRecord({
|
|
1161
|
+
...row,
|
|
1162
|
+
ticket: row.ticket === null ? null : JSON.parse(row.ticket),
|
|
1163
|
+
}),
|
|
1029
1164
|
)
|
|
1030
1165
|
const last = page.at(-1)
|
|
1031
1166
|
return {
|
|
1032
1167
|
builds,
|
|
1033
1168
|
next:
|
|
1034
1169
|
rows.length > limit && last
|
|
1035
|
-
? encodeBuildPageCursor({
|
|
1170
|
+
? encodeBuildPageCursor({
|
|
1171
|
+
order,
|
|
1172
|
+
at: last.cursorAt ?? last.createdAt,
|
|
1173
|
+
slug: last.slug,
|
|
1174
|
+
})
|
|
1175
|
+
: null,
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
async listMergedBuildsPage(
|
|
1180
|
+
repo: string,
|
|
1181
|
+
opts: MergedBuildPageOptions = {},
|
|
1182
|
+
): Promise<MergedBuildPage> {
|
|
1183
|
+
const limit = resolveBuildPageLimit(opts.limit)
|
|
1184
|
+
const window = resolveMergedBuildWindow(opts)
|
|
1185
|
+
const cursor = opts.cursor === undefined ? undefined : requireMergedCursor(opts.cursor)
|
|
1186
|
+
type MergedRow = Omit<BuildRecordRow, 'ticket'> & {
|
|
1187
|
+
ticket: string | null
|
|
1188
|
+
mergedAt: string
|
|
1189
|
+
listingNode: number
|
|
1190
|
+
prNumber: number | null
|
|
1191
|
+
prUrl: string | null
|
|
1192
|
+
listingTarget: string | null
|
|
1193
|
+
}
|
|
1194
|
+
const query = mergedBuildPageQuery(repo, limit + 1, window, cursor)
|
|
1195
|
+
const rows = this.sqlite.query<MergedRow, (string | number)[]>(query.sql).all(...query.params)
|
|
1196
|
+
const page = rows.slice(0, limit)
|
|
1197
|
+
const builds = page.map(
|
|
1198
|
+
({ mergedAt, listingNode, prNumber, prUrl, listingTarget, ...row }): MergedBuild => {
|
|
1199
|
+
const target = parseListingTarget(listingTarget)
|
|
1200
|
+
return {
|
|
1201
|
+
record: this.toRecord({
|
|
1202
|
+
...row,
|
|
1203
|
+
ticket: row.ticket === null ? null : JSON.parse(row.ticket),
|
|
1204
|
+
}),
|
|
1205
|
+
mergedAt,
|
|
1206
|
+
kind: listingNode ? 'node' : 'leaf',
|
|
1207
|
+
...(prNumber !== null && prUrl !== null ? { pr: { number: prNumber, url: prUrl } } : {}),
|
|
1208
|
+
...(target ? { target } : {}),
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
)
|
|
1212
|
+
const last = page.at(-1)
|
|
1213
|
+
return {
|
|
1214
|
+
builds,
|
|
1215
|
+
next:
|
|
1216
|
+
rows.length > limit && last
|
|
1217
|
+
? encodeBuildPageCursor({
|
|
1218
|
+
order: 'merged',
|
|
1219
|
+
at: last.mergedAt,
|
|
1220
|
+
slug: last.slug,
|
|
1221
|
+
})
|
|
1036
1222
|
: null,
|
|
1037
1223
|
}
|
|
1038
1224
|
}
|
|
@@ -1062,22 +1248,28 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1062
1248
|
const row = (
|
|
1063
1249
|
beforePrevious !== undefined
|
|
1064
1250
|
? this.sqlite
|
|
1065
|
-
.query(
|
|
1251
|
+
.query(
|
|
1252
|
+
`SELECT payload FROM events
|
|
1066
1253
|
WHERE type = 'node.rewritten' AND build = ? AND seq < (
|
|
1067
1254
|
SELECT seq FROM events WHERE type = 'node.rewritten' AND build = ?
|
|
1068
1255
|
AND json_extract(payload, '$.previous') = ? ORDER BY seq DESC LIMIT 1
|
|
1069
|
-
) ORDER BY seq DESC LIMIT 1
|
|
1256
|
+
) ORDER BY seq DESC LIMIT 1`,
|
|
1257
|
+
)
|
|
1070
1258
|
.get(slug, slug, beforePrevious)
|
|
1071
1259
|
: previous === undefined
|
|
1072
1260
|
? this.sqlite
|
|
1073
|
-
.query(
|
|
1074
|
-
|
|
1261
|
+
.query(
|
|
1262
|
+
`SELECT payload FROM events
|
|
1263
|
+
WHERE type = 'node.rewritten' AND build = ? ORDER BY seq DESC LIMIT 1`,
|
|
1264
|
+
)
|
|
1075
1265
|
.get(slug)
|
|
1076
1266
|
: this.sqlite
|
|
1077
|
-
.query(
|
|
1267
|
+
.query(
|
|
1268
|
+
`SELECT payload FROM events
|
|
1078
1269
|
WHERE type = 'node.rewritten' AND build = ?
|
|
1079
1270
|
AND json_extract(payload, '$.previous') = ?
|
|
1080
|
-
ORDER BY seq DESC LIMIT 1
|
|
1271
|
+
ORDER BY seq DESC LIMIT 1`,
|
|
1272
|
+
)
|
|
1081
1273
|
.get(slug, previous)
|
|
1082
1274
|
) as { payload: string } | null
|
|
1083
1275
|
return row ? eventPayloadSchemas['node.rewritten'].parse(JSON.parse(row.payload)) : null
|
|
@@ -1094,7 +1286,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1094
1286
|
.all()
|
|
1095
1287
|
.map((row) => this.toRecord(row.build))
|
|
1096
1288
|
const digests = await readPersistedBuildDigests(this, repo, records)
|
|
1097
|
-
return records.map((record) => ({
|
|
1289
|
+
return records.map((record) => ({
|
|
1290
|
+
record,
|
|
1291
|
+
digest: digests.get(record.slug)!,
|
|
1292
|
+
}))
|
|
1098
1293
|
}
|
|
1099
1294
|
|
|
1100
1295
|
async getRepoBuildDigests(repo: string): Promise<Map<string, BuildDigest>> {
|
|
@@ -1605,11 +1800,13 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1605
1800
|
this.writeTx(() => {
|
|
1606
1801
|
this.requireRepo(repo)
|
|
1607
1802
|
this.sqlite
|
|
1608
|
-
.query(
|
|
1803
|
+
.query(
|
|
1804
|
+
`INSERT INTO scan_cadence (repo,value) VALUES (?1,?2)
|
|
1609
1805
|
ON CONFLICT(repo) DO UPDATE SET value=excluded.value
|
|
1610
1806
|
WHERE CASE WHEN json_valid(scan_cadence.value) THEN COALESCE(
|
|
1611
1807
|
json_extract(scan_cadence.value,'$.scanSeq') <> ?3 OR ?4
|
|
1612
|
-
OR json_extract(scan_cadence.value,'$.startedAt') <= ?5, 1) ELSE 1 END
|
|
1808
|
+
OR json_extract(scan_cadence.value,'$.startedAt') <= ?5, 1) ELSE 1 END`,
|
|
1809
|
+
)
|
|
1613
1810
|
.run(
|
|
1614
1811
|
repo,
|
|
1615
1812
|
JSON.stringify(cadence),
|
|
@@ -1629,10 +1826,12 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1629
1826
|
if (!repo) throw new Error('repo is required')
|
|
1630
1827
|
const identity = operatorIdentitySchema.parse(input)
|
|
1631
1828
|
const row = this.sqlite
|
|
1632
|
-
.query(
|
|
1829
|
+
.query(
|
|
1830
|
+
`INSERT INTO operator_presence (repo,id,host,pid,started_at,heartbeat_at)
|
|
1633
1831
|
VALUES (?1,?2,?3,?4,?5,?6) ON CONFLICT(repo,id) DO UPDATE SET
|
|
1634
1832
|
host=excluded.host, pid=excluded.pid, heartbeat_at=MAX(operator_presence.heartbeat_at,excluded.heartbeat_at)
|
|
1635
|
-
RETURNING repo,id,host,pid,started_at AS startedAt,heartbeat_at AS heartbeatAt
|
|
1833
|
+
RETURNING repo,id,host,pid,started_at AS startedAt,heartbeat_at AS heartbeatAt`,
|
|
1834
|
+
)
|
|
1636
1835
|
.get(repo, identity.id, identity.host, identity.pid, identity.startedAt, this.now())
|
|
1637
1836
|
return row as OperatorPresence
|
|
1638
1837
|
}
|
|
@@ -1644,8 +1843,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1644
1843
|
|
|
1645
1844
|
async listOperatorPresence(repo: string): Promise<OperatorPresence[]> {
|
|
1646
1845
|
return this.sqlite
|
|
1647
|
-
.query(
|
|
1648
|
-
|
|
1846
|
+
.query(
|
|
1847
|
+
`SELECT repo,id,host,pid,started_at AS startedAt,heartbeat_at AS heartbeatAt
|
|
1848
|
+
FROM operator_presence WHERE repo=?1 AND heartbeat_at>?2 ORDER BY id`,
|
|
1849
|
+
)
|
|
1649
1850
|
.all(
|
|
1650
1851
|
repo,
|
|
1651
1852
|
new Date(this.clock().getTime() - OPERATOR_PRESENCE_TTL_MS).toISOString(),
|
|
@@ -1973,7 +2174,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
1973
2174
|
} catch {
|
|
1974
2175
|
/* malformed cache */
|
|
1975
2176
|
}
|
|
1976
|
-
return {
|
|
2177
|
+
return {
|
|
2178
|
+
snapshot: { version: row.version, cursor: row.cursor, state },
|
|
2179
|
+
token: row.state,
|
|
2180
|
+
}
|
|
1977
2181
|
},
|
|
1978
2182
|
repair: async (key, observed, snapshot) => {
|
|
1979
2183
|
return this.sqlite.transaction(() => {
|
|
@@ -2043,7 +2247,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2043
2247
|
}
|
|
2044
2248
|
}
|
|
2045
2249
|
const writeLease = (key: string, holder: string, observed: string | null): boolean => {
|
|
2046
|
-
const state = JSON.stringify({
|
|
2250
|
+
const state = JSON.stringify({
|
|
2251
|
+
holder,
|
|
2252
|
+
expiresAt: this.clock().getTime() + ROLLUP_LEASE_MS,
|
|
2253
|
+
})
|
|
2047
2254
|
const now = this.clock().toISOString()
|
|
2048
2255
|
if (observed === null)
|
|
2049
2256
|
return (
|
|
@@ -2195,7 +2402,11 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2195
2402
|
} | null
|
|
2196
2403
|
if (row === null || row.version !== version || row.cursor > tail) return null
|
|
2197
2404
|
try {
|
|
2198
|
-
return {
|
|
2405
|
+
return {
|
|
2406
|
+
version: row.version,
|
|
2407
|
+
cursor: row.cursor,
|
|
2408
|
+
state: JSON.parse(row.state),
|
|
2409
|
+
}
|
|
2199
2410
|
} catch {
|
|
2200
2411
|
return null
|
|
2201
2412
|
}
|
|
@@ -2612,7 +2823,12 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2612
2823
|
) as RepositoryEvent[]
|
|
2613
2824
|
const observation: RepoTickObservation = {
|
|
2614
2825
|
run: holder,
|
|
2615
|
-
finished: {
|
|
2826
|
+
finished: {
|
|
2827
|
+
...completion,
|
|
2828
|
+
run: holder,
|
|
2829
|
+
startedAt: row.tick.open.startedAt,
|
|
2830
|
+
completedAt,
|
|
2831
|
+
},
|
|
2616
2832
|
}
|
|
2617
2833
|
this.db
|
|
2618
2834
|
.update(repoStreams)
|
|
@@ -2913,7 +3129,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
2913
3129
|
id: string,
|
|
2914
3130
|
artifactInputs: ArtifactInput[],
|
|
2915
3131
|
makeEvent: (deposited: SessionArtifactMeta[]) => SessionEventWrite<T>,
|
|
2916
|
-
): Promise<{
|
|
3132
|
+
): Promise<{
|
|
3133
|
+
event: SessionEventEnvelope<T>
|
|
3134
|
+
artifacts: SessionArtifactMeta[]
|
|
3135
|
+
}> {
|
|
2917
3136
|
const { validateSessionEventWrite } = writeValidation.value ?? (await writeValidation.load())
|
|
2918
3137
|
const prepared: PreparedArtifact[] = []
|
|
2919
3138
|
for (const input of artifactInputs) {
|
|
@@ -3129,7 +3348,12 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
3129
3348
|
}
|
|
3130
3349
|
this.db
|
|
3131
3350
|
.insert(streamChunks)
|
|
3132
|
-
.values({
|
|
3351
|
+
.values({
|
|
3352
|
+
stream: streamId,
|
|
3353
|
+
seq: chunk.seq,
|
|
3354
|
+
ts: chunk.ts,
|
|
3355
|
+
parts: chunk.parts,
|
|
3356
|
+
})
|
|
3133
3357
|
.run()
|
|
3134
3358
|
return chunk
|
|
3135
3359
|
}),
|
|
@@ -3161,7 +3385,11 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
3161
3385
|
...(record.artifact !== undefined ? { artifact: record.artifact } : {}),
|
|
3162
3386
|
}
|
|
3163
3387
|
}
|
|
3164
|
-
return readStreamWithWait({
|
|
3388
|
+
return readStreamWithWait({
|
|
3389
|
+
read,
|
|
3390
|
+
waitSeconds: opts?.waitSeconds,
|
|
3391
|
+
signal: opts?.signal,
|
|
3392
|
+
})
|
|
3165
3393
|
}
|
|
3166
3394
|
|
|
3167
3395
|
async closeStream(streamId: string, outcome: StreamOutcome): Promise<StreamRecord> {
|
|
@@ -3241,7 +3469,10 @@ export class SqliteBuildStore implements BuildStore {
|
|
|
3241
3469
|
})
|
|
3242
3470
|
.where(eq(streams.id, streamId))
|
|
3243
3471
|
.run()
|
|
3244
|
-
return {
|
|
3472
|
+
return {
|
|
3473
|
+
stale: false,
|
|
3474
|
+
record: this.toStreamRecord(this.requireStream(streamId)),
|
|
3475
|
+
}
|
|
3245
3476
|
},
|
|
3246
3477
|
)
|
|
3247
3478
|
if (committed.stale === false) return committed.record
|
|
@@ -3361,7 +3592,11 @@ export async function inspectLocalStoreSnapshot(rootDir: string): Promise<LocalS
|
|
|
3361
3592
|
*/
|
|
3362
3593
|
export function openLocalStore(
|
|
3363
3594
|
rootDir: string,
|
|
3364
|
-
opts: {
|
|
3595
|
+
opts: {
|
|
3596
|
+
clock?: Clock
|
|
3597
|
+
retention?: { maxRevisions?: number }
|
|
3598
|
+
bootstrap?: boolean
|
|
3599
|
+
} = {},
|
|
3365
3600
|
): SqliteBuildStore {
|
|
3366
3601
|
if (opts.bootstrap !== false) mkdirSync(rootDir, { recursive: true })
|
|
3367
3602
|
const database = new Database(join(rootDir, 'autobuild.sqlite'), {
|