@defrex/autobuild 1.11.1 → 1.12.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 +177 -54
- package/docs/answering-blocked-builds.md +10 -2
- package/docs/architecture.md +66 -6
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +13 -11
- package/docs/dispatcher.md +1 -1
- package/docs/integration-tree.md +28 -16
- package/docs/operator-api.md +4 -4
- package/docs/operator-surfaces.md +35 -0
- package/docs/optimization-nodes.md +3 -2
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/ambient-errors.ts +17 -0
- package/packages/core/src/cli/bounded-io.ts +174 -0
- package/packages/core/src/cli/dashboard/model.ts +81 -23
- package/packages/core/src/cli/dashboard/poll.ts +20 -31
- package/packages/core/src/cli/dashboard/render.ts +14 -37
- package/packages/core/src/cli/dashboard/row-text.ts +24 -7
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
- package/packages/core/src/cli/dispatch-handoff.ts +41 -10
- package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
- package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
- package/packages/core/src/cli/dispatch-launcher.ts +9 -10
- package/packages/core/src/cli/dispatch-preflight.ts +12 -3
- package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
- package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
- package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
- package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
- package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
- package/packages/core/src/cli/dispatch.ts +68 -5
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +5 -4
- package/packages/core/src/cli/main.ts +4 -2
- package/packages/core/src/cli/production-store.ts +102 -0
- package/packages/core/src/cli/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +28 -22
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +169 -40
- package/packages/core/src/cli/store-opening.ts +15 -58
- package/packages/core/src/cli/store-ref.ts +6 -1
- package/packages/core/src/config/schema.ts +1 -1
- package/packages/core/src/distribution-packaging.ts +156 -18
- package/packages/core/src/events/catalog-identity.ts +28 -0
- package/packages/core/src/events/catalog.ts +3 -9
- package/packages/core/src/events/compatibility.ts +2 -30
- package/packages/core/src/events/payloads.ts +11 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +1 -1
- package/packages/core/src/events/sessions.ts +1 -1
- package/packages/core/src/events/validation-error.ts +12 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +9 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
- package/packages/core/src/kernel/auto-merge-default.ts +2 -1
- package/packages/core/src/kernel/capacity-build.ts +21 -0
- package/packages/core/src/kernel/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
- package/packages/core/src/kernel/engine.ts +2 -8
- package/packages/core/src/kernel/measurement.ts +24 -0
- package/packages/core/src/kernel/read-facts.ts +8 -370
- package/packages/core/src/kernel/reducer-registry.ts +40 -125
- package/packages/core/src/kernel/reducer-revisions.ts +3 -0
- package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
- package/packages/core/src/kernel/reducer-value-index.ts +75 -0
- package/packages/core/src/kernel/reducer.ts +57 -9
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- package/packages/core/src/operator/presentation.ts +13 -0
- package/packages/core/src/operator/query.ts +40 -39
- package/packages/core/src/operator/registry.ts +3 -3
- package/packages/core/src/ports/workspace/fake.ts +15 -3
- package/packages/core/src/processes/dispatcher.ts +232 -75
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- package/packages/core/src/store/local/capabilities.ts +115 -0
- package/packages/core/src/store/local/store.ts +86 -56
- package/packages/core/src/store/reduced-reads.ts +9 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +1437 -1349
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/rollup-lease.ts +41 -0
- package/packages/core/src/store/rollups.ts +7 -38
- package/packages/core/src/store/snapshots.ts +1 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +265 -4
- package/packages/core/src/testing/import-graph.ts +78 -0
- package/packages/core/src/testing/reduced-read-budget.ts +221 -22
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/skills/guide/SKILL.md +115 -44
- package/skills/guide/references/integration-tree.md +28 -16
- package/skills/guide/references/operator-api.md +4 -4
- package/skills/guide/references/optimization-nodes.md +3 -2
- package/skills/operate/SKILL.md +38 -20
- package/templates/hosted-service/package.json +2 -2
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import release0 from './1.10.0.json'
|
|
3
3
|
import release1 from './1.11.0.json'
|
|
4
4
|
import release2 from './1.11.1.json'
|
|
5
|
-
import release3 from './1.
|
|
6
|
-
import release4 from './1.
|
|
7
|
-
import release5 from './1.
|
|
8
|
-
import release6 from './1.
|
|
9
|
-
import release7 from './1.
|
|
10
|
-
import release8 from './1.
|
|
11
|
-
import release9 from './1.
|
|
12
|
-
import release10 from './1.
|
|
5
|
+
import release3 from './1.12.0.json'
|
|
6
|
+
import release4 from './1.2.0.json'
|
|
7
|
+
import release5 from './1.3.0.json'
|
|
8
|
+
import release6 from './1.4.0.json'
|
|
9
|
+
import release7 from './1.5.0.json'
|
|
10
|
+
import release8 from './1.6.0.json'
|
|
11
|
+
import release9 from './1.7.0.json'
|
|
12
|
+
import release10 from './1.8.0.json'
|
|
13
|
+
import release11 from './1.9.0.json'
|
|
13
14
|
import type { ReducerValueCatalog } from '../../reducer-value-validation'
|
|
14
15
|
export interface ReleasedReducerValues extends ReducerValueCatalog {
|
|
15
16
|
versions: Record<string, number>
|
|
@@ -18,12 +19,13 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
|
|
|
18
19
|
'1.10.0.json': release0,
|
|
19
20
|
'1.11.0.json': release1,
|
|
20
21
|
'1.11.1.json': release2,
|
|
21
|
-
'1.
|
|
22
|
-
'1.
|
|
23
|
-
'1.
|
|
24
|
-
'1.
|
|
25
|
-
'1.
|
|
26
|
-
'1.
|
|
27
|
-
'1.
|
|
28
|
-
'1.
|
|
22
|
+
'1.12.0.json': release3,
|
|
23
|
+
'1.2.0.json': release4,
|
|
24
|
+
'1.3.0.json': release5,
|
|
25
|
+
'1.4.0.json': release6,
|
|
26
|
+
'1.5.0.json': release7,
|
|
27
|
+
'1.6.0.json': release8,
|
|
28
|
+
'1.7.0.json': release9,
|
|
29
|
+
'1.8.0.json': release10,
|
|
30
|
+
'1.9.0.json': release11,
|
|
29
31
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Rollup serialization primitives, free of the reducer catalog so stores can
|
|
2
|
+
* construct their locks without initializing it. `./rollups` re-exports them. */
|
|
3
|
+
|
|
4
|
+
/** A promise chain per key: serializes same-key work inside one store
|
|
5
|
+
* instance. */
|
|
6
|
+
export class KeyedMutex {
|
|
7
|
+
private readonly tails = new Map<string, Promise<unknown>>()
|
|
8
|
+
|
|
9
|
+
async run<T>(key: string, body: () => Promise<T>): Promise<T> {
|
|
10
|
+
const previous = this.tails.get(key) ?? Promise.resolve()
|
|
11
|
+
const next = previous.catch(() => {}).then(body)
|
|
12
|
+
this.tails.set(key, next)
|
|
13
|
+
try {
|
|
14
|
+
return await next
|
|
15
|
+
} finally {
|
|
16
|
+
if (this.tails.get(key) === next) this.tails.delete(key)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A store-wide rollup lease (the SQLite adapter's per-key serialization). */
|
|
22
|
+
export const ROLLUP_LEASE_MS = 120_000
|
|
23
|
+
/** How long a reader waits on another holder's lease before giving up. */
|
|
24
|
+
export const ROLLUP_LEASE_WAIT_MS = 600_000
|
|
25
|
+
|
|
26
|
+
/** A reader waited `ROLLUP_LEASE_WAIT_MS` on another holder's lease. */
|
|
27
|
+
export class RollupLeaseTimeoutError extends Error {
|
|
28
|
+
override readonly name = 'RollupLeaseTimeoutError'
|
|
29
|
+
constructor(readonly key: string) {
|
|
30
|
+
super(`timed out waiting for the rollup lease on ${key}`)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** An advance's lease expired and another holder took it over; the advance
|
|
35
|
+
* commits nothing. */
|
|
36
|
+
export class RollupLeaseLostError extends Error {
|
|
37
|
+
override readonly name = 'RollupLeaseLostError'
|
|
38
|
+
constructor(readonly key: string) {
|
|
39
|
+
super(`lost the rollup lease on ${key}`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -297,41 +297,10 @@ export async function readRollupValue(
|
|
|
297
297
|
})
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const next = previous.catch(() => {}).then(body)
|
|
308
|
-
this.tails.set(key, next)
|
|
309
|
-
try {
|
|
310
|
-
return await next
|
|
311
|
-
} finally {
|
|
312
|
-
if (this.tails.get(key) === next) this.tails.delete(key)
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/** A store-wide rollup lease (the SQLite adapter's per-key serialization). */
|
|
318
|
-
export const ROLLUP_LEASE_MS = 120_000
|
|
319
|
-
/** How long a reader waits on another holder's lease before giving up. */
|
|
320
|
-
export const ROLLUP_LEASE_WAIT_MS = 600_000
|
|
321
|
-
|
|
322
|
-
/** A reader waited `ROLLUP_LEASE_WAIT_MS` on another holder's lease. */
|
|
323
|
-
export class RollupLeaseTimeoutError extends Error {
|
|
324
|
-
override readonly name = 'RollupLeaseTimeoutError'
|
|
325
|
-
constructor(readonly key: string) {
|
|
326
|
-
super(`timed out waiting for the rollup lease on ${key}`)
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/** An advance's lease expired and another holder took it over; the advance
|
|
331
|
-
* commits nothing. */
|
|
332
|
-
export class RollupLeaseLostError extends Error {
|
|
333
|
-
override readonly name = 'RollupLeaseLostError'
|
|
334
|
-
constructor(readonly key: string) {
|
|
335
|
-
super(`lost the rollup lease on ${key}`)
|
|
336
|
-
}
|
|
337
|
-
}
|
|
300
|
+
export {
|
|
301
|
+
KeyedMutex,
|
|
302
|
+
ROLLUP_LEASE_MS,
|
|
303
|
+
ROLLUP_LEASE_WAIT_MS,
|
|
304
|
+
RollupLeaseLostError,
|
|
305
|
+
RollupLeaseTimeoutError,
|
|
306
|
+
} from './rollup-lease'
|
|
@@ -1504,7 +1504,9 @@ steps = []
|
|
|
1504
1504
|
|
|
1505
1505
|
/** Script a minute at both launcher cadences using the real runtime reader and
|
|
1506
1506
|
* launcher cache. Each helper gets a fresh facade; private reads use that same
|
|
1507
|
-
* instrumented receiver rather than escaping into an uncounted reducer.
|
|
1507
|
+
* instrumented receiver rather than escaping into an uncounted reducer. The
|
|
1508
|
+
* sibling budgets `upgradeGenerationReadBudget` and `releaseObservationBudget`
|
|
1509
|
+
* cover completed generations and successor release observation. */
|
|
1508
1510
|
export async function upgradeReadBudget(store: BuildStore): Promise<void> {
|
|
1509
1511
|
const { readUpgradeProjection } = await import('../cli/dispatch-handoff')
|
|
1510
1512
|
const { conditionalUpgradeClient } = await import('../cli/dispatch-launch-contract')
|
|
@@ -1621,17 +1623,80 @@ export async function upgradeReadBudget(store: BuildStore): Promise<void> {
|
|
|
1621
1623
|
metrics.reducer = 0
|
|
1622
1624
|
await check()
|
|
1623
1625
|
expect(metrics.reducer).toBeGreaterThan(0)
|
|
1626
|
+
await preparationObservationBudget(store, repo, check, metrics)
|
|
1624
1627
|
}
|
|
1625
|
-
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
/** A durably detected, unresolved preparation earns the launcher's bounded
|
|
1631
|
+
* fast cadence. Each observation stays position-only while nothing changes,
|
|
1632
|
+
* the count is finite, and resolution returns to the idle cadence. */
|
|
1633
|
+
async function preparationObservationBudget(
|
|
1634
|
+
store: BuildStore,
|
|
1635
|
+
repo: string,
|
|
1636
|
+
check: () => Promise<{ preparing?: string }>,
|
|
1637
|
+
metrics: Record<'position' | 'metadata' | 'reducer' | 'events' | 'rows', number>,
|
|
1638
|
+
): Promise<void> {
|
|
1639
|
+
const { supervisionCadence, PREPARATION_OBSERVATION_LIMIT, PREPARATION_OBSERVATION_MS } =
|
|
1640
|
+
await import('../cli/dispatch-launcher-cadence')
|
|
1641
|
+
const { upgradeRuntime, upgradeTarget } = await import('./upgrade-generations')
|
|
1642
|
+
const reset = () => {
|
|
1643
|
+
for (const key of Object.keys(metrics) as (keyof typeof metrics)[]) metrics[key] = 0
|
|
1644
|
+
}
|
|
1645
|
+
const identity = {
|
|
1646
|
+
correlation: `prepare-${repo}`,
|
|
1647
|
+
run: 'budget',
|
|
1648
|
+
lineage: 'budget',
|
|
1649
|
+
from: upgradeRuntime('1.0.0'),
|
|
1650
|
+
target: upgradeTarget('next'),
|
|
1651
|
+
}
|
|
1652
|
+
await store.appendRepo(repo, {
|
|
1653
|
+
actor: DISPATCHER,
|
|
1654
|
+
type: 'dispatcher.upgrade-detected',
|
|
1655
|
+
payload: identity,
|
|
1656
|
+
})
|
|
1657
|
+
reset()
|
|
1658
|
+
const cadence = supervisionCadence()
|
|
1659
|
+
const first = await check()
|
|
1660
|
+
expect(first.preparing).toBe(identity.correlation)
|
|
1661
|
+
expect(metrics.position).toBe(1)
|
|
1662
|
+
expect(metrics.reducer).toBeLessThanOrEqual(1)
|
|
1663
|
+
expect(cadence(first, false)).toBe(PREPARATION_OBSERVATION_MS)
|
|
1664
|
+
reset()
|
|
1665
|
+
const delays: number[] = []
|
|
1666
|
+
for (let i = 0; i < PREPARATION_OBSERVATION_LIMIT; i++) delays.push(cadence(await check(), false))
|
|
1667
|
+
expect(delays.slice(0, -1).every((delay) => delay === PREPARATION_OBSERVATION_MS)).toBe(true)
|
|
1668
|
+
expect(delays.at(-1)).toBe(1_000)
|
|
1669
|
+
expect(metrics).toEqual({
|
|
1670
|
+
position: PREPARATION_OBSERVATION_LIMIT,
|
|
1671
|
+
metadata: 0,
|
|
1672
|
+
reducer: 0,
|
|
1673
|
+
events: 0,
|
|
1674
|
+
rows: 0,
|
|
1675
|
+
})
|
|
1676
|
+
await store.appendRepo(repo, {
|
|
1677
|
+
actor: DISPATCHER,
|
|
1678
|
+
type: 'dispatcher.upgrade-failed',
|
|
1679
|
+
payload: { ...identity, reason: 'budget' },
|
|
1680
|
+
})
|
|
1681
|
+
const failed = await check()
|
|
1682
|
+
expect(failed.preparing).toBeUndefined()
|
|
1683
|
+
expect(cadence(failed, false)).toBe(1_000)
|
|
1684
|
+
reset()
|
|
1685
|
+
for (let i = 0; i < 10; i++) await check()
|
|
1686
|
+
expect(metrics).toEqual({ position: 10, metadata: 0, reducer: 0, events: 0, rows: 0 })
|
|
1626
1687
|
}
|
|
1627
1688
|
|
|
1628
1689
|
/** Completed dispatcher generations must not grow the saved upgrade values or
|
|
1629
1690
|
* the idle cost of any recurring reader: a dispatch tick, a dashboard poll, an
|
|
1630
|
-
* `ab watch` liveness check
|
|
1631
|
-
|
|
1691
|
+
* `ab watch` liveness check, `ab repository status`, one step of the
|
|
1692
|
+
* between-tick yield observation and one step of successor release
|
|
1693
|
+
* observation. */
|
|
1694
|
+
export async function upgradeGenerationReadBudget(): Promise<void> {
|
|
1632
1695
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
1633
1696
|
const { manualClock } = await import('./fixed')
|
|
1634
1697
|
const { readDispatchUpgrade } = await import('../store/reduced-reads')
|
|
1698
|
+
const { observeYield } = await import('../cli/dispatch-yield-observer')
|
|
1699
|
+
const { observeSuccessorRelease } = await import('../cli/dispatch-release-observer')
|
|
1635
1700
|
const { memoryRepositoryReadCounter } = await import('./reduced-read-budget')
|
|
1636
1701
|
const { upgradeGenerationRun, upgradeGenerationWrites, resolutionOnlyWrites } = await import(
|
|
1637
1702
|
'./upgrade-generations'
|
|
@@ -1730,6 +1795,8 @@ async function upgradeGenerationReadBudget(): Promise<void> {
|
|
|
1730
1795
|
dashboard: () => getOperatorDashboard({ store, repo, clock }),
|
|
1731
1796
|
watch,
|
|
1732
1797
|
status,
|
|
1798
|
+
yieldObservation: () => observeYield(store, repo, current, 'budget-correlation', 'launcher'),
|
|
1799
|
+
releaseObservation: () => observeSuccessorRelease(store, repo, current),
|
|
1733
1800
|
}
|
|
1734
1801
|
// The one serialized reduction per key, and each reader's own first
|
|
1735
1802
|
// appends, happen before measurement.
|
|
@@ -1766,6 +1833,79 @@ async function upgradeGenerationReadBudget(): Promise<void> {
|
|
|
1766
1833
|
}
|
|
1767
1834
|
}
|
|
1768
1835
|
|
|
1836
|
+
/** A successor waiting for its predecessor's release observes at the bounded
|
|
1837
|
+
* cadence: a finite fast window, a short backoff, then the idle pause. Every
|
|
1838
|
+
* unchanged observation reads zero event rows and makes the same reduced reads
|
|
1839
|
+
* at any journal length, and the release itself is seen at bounded cost.
|
|
1840
|
+
*
|
|
1841
|
+
* One call observes one `part` of `parts` equal slices of the observation
|
|
1842
|
+
* steps, at both journal lengths; calling every part covers every step. The
|
|
1843
|
+
* cadence schedule and the release itself are asserted in full by every part. */
|
|
1844
|
+
export async function releaseObservationBudget(part: number, parts: number): Promise<void> {
|
|
1845
|
+
if (!Number.isInteger(parts) || parts < 1) throw new Error(`invalid parts ${parts}`)
|
|
1846
|
+
if (!Number.isInteger(part) || part < 0 || part >= parts) throw new Error(`invalid part ${part}`)
|
|
1847
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
1848
|
+
const {
|
|
1849
|
+
observeSuccessorRelease,
|
|
1850
|
+
releaseObservationCadence,
|
|
1851
|
+
RELEASE_OBSERVATION_FAST_LIMIT,
|
|
1852
|
+
RELEASE_OBSERVATION_FAST_MS,
|
|
1853
|
+
RELEASE_OBSERVATION_IDLE_MS,
|
|
1854
|
+
} = await import('../cli/dispatch-release-observer')
|
|
1855
|
+
const { memoryRepositoryReadCounter } = await import('./reduced-read-budget')
|
|
1856
|
+
const { upgradeGenerationRun, upgradeGenerationWrites } = await import('./upgrade-generations')
|
|
1857
|
+
const costs = new Map<string, number>()
|
|
1858
|
+
// About 100 and 10,000 filler events before the waiting predecessor.
|
|
1859
|
+
for (const generations of [10, 1_000]) {
|
|
1860
|
+
const repo = '/release-observation-budget'
|
|
1861
|
+
const store = new MemoryBuildStore()
|
|
1862
|
+
await store.ensureRepo(repo)
|
|
1863
|
+
for (let i = 0; i < generations; i++)
|
|
1864
|
+
for (const write of upgradeGenerationWrites(i)) await store.appendRepo(repo, write)
|
|
1865
|
+
const predecessor = upgradeGenerationRun(generations)
|
|
1866
|
+
const writes = upgradeGenerationWrites(generations)
|
|
1867
|
+
// Start, resolve, prepare and request yield; the release is still pending.
|
|
1868
|
+
for (const write of writes.slice(0, 5)) await store.appendRepo(repo, write)
|
|
1869
|
+
const observe = () => observeSuccessorRelease(store, repo, predecessor)
|
|
1870
|
+
expect((await observe()).current?.request).toBeDefined()
|
|
1871
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
1872
|
+
const cadence = releaseObservationCadence()
|
|
1873
|
+
const delays: number[] = []
|
|
1874
|
+
const steps = RELEASE_OBSERVATION_FAST_LIMIT + 4 + 20
|
|
1875
|
+
let observed = 0
|
|
1876
|
+
for (let step = 0; step < steps; step++) {
|
|
1877
|
+
if (Math.floor((step * parts) / steps) === part) {
|
|
1878
|
+
observed++
|
|
1879
|
+
const { current } = await observe()
|
|
1880
|
+
expect(current?.released).toBeUndefined()
|
|
1881
|
+
}
|
|
1882
|
+
delays.push(cadence(0))
|
|
1883
|
+
}
|
|
1884
|
+
expect(observed).toBeGreaterThan(0)
|
|
1885
|
+
expect(counter.rows).toBe(0)
|
|
1886
|
+
expect(counter.reducedCalls % observed).toBe(0)
|
|
1887
|
+
const perStep = counter.reducedCalls / observed
|
|
1888
|
+
if (generations === 10) costs.set('step', perStep)
|
|
1889
|
+
else expect(perStep).toBe(costs.get('step')!)
|
|
1890
|
+
const steady = delays.indexOf(RELEASE_OBSERVATION_IDLE_MS)
|
|
1891
|
+
expect(steady).toBe(RELEASE_OBSERVATION_FAST_LIMIT + 4)
|
|
1892
|
+
expect(delays.slice(0, RELEASE_OBSERVATION_FAST_LIMIT)).toEqual(
|
|
1893
|
+
Array(RELEASE_OBSERVATION_FAST_LIMIT).fill(RELEASE_OBSERVATION_FAST_MS),
|
|
1894
|
+
)
|
|
1895
|
+
expect(delays.slice(RELEASE_OBSERVATION_FAST_LIMIT, steady)).toEqual([50, 100, 200, 400])
|
|
1896
|
+
expect(delays.slice(steady).every((delay) => delay === RELEASE_OBSERVATION_IDLE_MS)).toBe(true)
|
|
1897
|
+
// handoff-started and terminal-released for the waiting correlation.
|
|
1898
|
+
for (const write of writes.slice(5, 7)) await store.appendRepo(repo, write)
|
|
1899
|
+
counter.reset()
|
|
1900
|
+
const { current } = await observe()
|
|
1901
|
+
expect(current?.handoff?.payload.correlation).toBe(`c-${predecessor}`)
|
|
1902
|
+
expect(current?.released?.payload.correlation).toBe(`c-${predecessor}`)
|
|
1903
|
+
if (generations === 10) costs.set('release', counter.rows)
|
|
1904
|
+
else expect(counter.rows).toBe(costs.get('release')!)
|
|
1905
|
+
await store.close()
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1769
1909
|
/** Measure real ticket-source operations through an injected statement boundary.
|
|
1770
1910
|
* Each fixture is fresh, so a source-local cache cannot conceal target reads.
|
|
1771
1911
|
* Listed rows carry one `closes #1` issue link on even-titled tickets and none
|
|
@@ -2593,3 +2733,124 @@ export async function warmRestoreReadBudget(
|
|
|
2593
2733
|
for (const report of reports.slice(1, 3)) expect(report.missing).toEqual(reports[0]!.missing)
|
|
2594
2734
|
return reports
|
|
2595
2735
|
}
|
|
2736
|
+
|
|
2737
|
+
/**
|
|
2738
|
+
* Store calls of every runtime-owned reader command, at 100 and 10,000
|
|
2739
|
+
* journal events. Each reader runs in a fresh process, so its cost per
|
|
2740
|
+
* occurrence is its whole cost:
|
|
2741
|
+
*
|
|
2742
|
+
* - `--read-journal` (once per cold start, once per handoff target for
|
|
2743
|
+
* `supportsRollback`): `ensureRepo` and `getRepo`; 0 event rows, 0 reducer
|
|
2744
|
+
* reads.
|
|
2745
|
+
* - `--read-handoff` without a run or lineage (the install probe, once per
|
|
2746
|
+
* prepared target): opens no store.
|
|
2747
|
+
* - `--read-handoff` with a run and lineage (once per generation exit):
|
|
2748
|
+
* `getRepo` and one `dispatchUpgrade` value, advanced incrementally; an
|
|
2749
|
+
* unprepared run reads no `dispatcherRunFacts`, and an unchanged journal
|
|
2750
|
+
* reads 0 event rows.
|
|
2751
|
+
*
|
|
2752
|
+
* `--read-upgrade` (every 1 s, 250 ms with a pending successor) is bounded by
|
|
2753
|
+
* `upgradeReadBudget`. Nothing here may grow with the journal.
|
|
2754
|
+
*/
|
|
2755
|
+
export async function readerCommandReadBudget(store: BuildStore): Promise<void> {
|
|
2756
|
+
const { readGenerationJournal, readHandoff } = await import('../cli/dispatch-handoff')
|
|
2757
|
+
const { readDispatchUpgrade } = await import('../store/reduced-reads')
|
|
2758
|
+
for (const length of [100, 10_000]) {
|
|
2759
|
+
const repo = `/reader-budget-${length}`
|
|
2760
|
+
await store.ensureRepo(repo)
|
|
2761
|
+
for (let i = 0; i < length; i++)
|
|
2762
|
+
await store.appendRepo(repo, {
|
|
2763
|
+
actor: humanActor('budget'),
|
|
2764
|
+
type: 'dispatcher.intake-set',
|
|
2765
|
+
payload: { enabled: false },
|
|
2766
|
+
})
|
|
2767
|
+
// The saved value exists, as it does after the first reader of this key.
|
|
2768
|
+
await readDispatchUpgrade(store, repo)
|
|
2769
|
+
const launch = {
|
|
2770
|
+
version: 1 as const,
|
|
2771
|
+
runtimeRoot: '/runtime',
|
|
2772
|
+
checkout: repo,
|
|
2773
|
+
journal: { repo, storeRef: '/memory' },
|
|
2774
|
+
run: 'budget',
|
|
2775
|
+
lineage: 'budget',
|
|
2776
|
+
}
|
|
2777
|
+
const counted = countedStore(store)
|
|
2778
|
+
let opened = 0
|
|
2779
|
+
const openStore = () => {
|
|
2780
|
+
opened++
|
|
2781
|
+
return counted.store
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
const journal = await readGenerationJournal(launch, ['dispatch'], {}, { openStore })
|
|
2785
|
+
expect(journal.journal).toEqual({ storeRef: '/memory', repo })
|
|
2786
|
+
expect(counted.take()).toEqual({ calls: ['ensureRepo', 'getRepo'], reducers: [], rows: 0 })
|
|
2787
|
+
|
|
2788
|
+
const probe = { ...launch, run: undefined, lineage: undefined }
|
|
2789
|
+
expect(await readHandoff(probe, ['dispatch'], {}, false, { openStore })).toBeUndefined()
|
|
2790
|
+
expect(opened).toBe(1)
|
|
2791
|
+
|
|
2792
|
+
expect(await readHandoff(launch, ['dispatch'], {}, true, { openStore })).toBeUndefined()
|
|
2793
|
+
expect(counted.take()).toEqual({
|
|
2794
|
+
calls: ['getRepo', 'getReducerValue'],
|
|
2795
|
+
reducers: ['dispatchUpgrade'],
|
|
2796
|
+
rows: 0,
|
|
2797
|
+
})
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
/** `store` with every method call, requested reducer and event row counted,
|
|
2802
|
+
* including the memory adapter's private reducer-storage slices. */
|
|
2803
|
+
function countedStore(store: BuildStore) {
|
|
2804
|
+
let calls: string[] = []
|
|
2805
|
+
let reducers: string[] = []
|
|
2806
|
+
let rows = 0
|
|
2807
|
+
const counted = new Proxy(store, {
|
|
2808
|
+
get(target, key, receiver) {
|
|
2809
|
+
if (key === 'close') return async () => {}
|
|
2810
|
+
if (key === 'repoState')
|
|
2811
|
+
return (...args: unknown[]) => {
|
|
2812
|
+
const state = Reflect.get(target, key).apply(receiver, args)
|
|
2813
|
+
return new Proxy(state, {
|
|
2814
|
+
get(state, field) {
|
|
2815
|
+
const value = Reflect.get(state, field)
|
|
2816
|
+
if (field !== 'events') return value
|
|
2817
|
+
return new Proxy(value, {
|
|
2818
|
+
get(events, method) {
|
|
2819
|
+
if (method !== 'slice') return Reflect.get(events, method)
|
|
2820
|
+
return (since: number, through: number) => {
|
|
2821
|
+
const sliced = events.slice(since, through)
|
|
2822
|
+
rows += sliced.length
|
|
2823
|
+
return sliced
|
|
2824
|
+
}
|
|
2825
|
+
},
|
|
2826
|
+
})
|
|
2827
|
+
},
|
|
2828
|
+
})
|
|
2829
|
+
}
|
|
2830
|
+
const value = Reflect.get(target, key, receiver)
|
|
2831
|
+
if (typeof value !== 'function' || typeof key !== 'string') return value
|
|
2832
|
+
// Count the store's public reads and writes; the adapter's own private
|
|
2833
|
+
// helpers run unwrapped through the same receiver.
|
|
2834
|
+
if (!/^(get|list|append|put|ensure|create|finish|claim|release)/.test(key))
|
|
2835
|
+
return value.bind(receiver)
|
|
2836
|
+
return async (...args: unknown[]) => {
|
|
2837
|
+
calls.push(key)
|
|
2838
|
+
if (key === 'getReducerValue') reducers.push((args[1] as { reducer: string }).reducer)
|
|
2839
|
+
const result = await value.apply(receiver, args)
|
|
2840
|
+
if ((key === 'getRepoEvents' || key === 'getRepoStateEvents') && Array.isArray(result))
|
|
2841
|
+
rows += result.length
|
|
2842
|
+
return result
|
|
2843
|
+
}
|
|
2844
|
+
},
|
|
2845
|
+
})
|
|
2846
|
+
return {
|
|
2847
|
+
store: counted,
|
|
2848
|
+
take() {
|
|
2849
|
+
const taken = { calls, reducers, rows }
|
|
2850
|
+
calls = []
|
|
2851
|
+
reducers = []
|
|
2852
|
+
rows = 0
|
|
2853
|
+
return taken
|
|
2854
|
+
},
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static value-import graph over `packages/core/src` for import-boundary
|
|
3
|
+
* tests. It reads source files, so only integration tests use it. An edge is
|
|
4
|
+
* a static value import, a side-effect import or a value re-export; type-only
|
|
5
|
+
* imports, dynamic `import()` and `typeof import()` are not edges.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
8
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
9
|
+
|
|
10
|
+
export const SRC = resolve(import.meta.dir, '..')
|
|
11
|
+
|
|
12
|
+
/** `path` relative to `packages/core/src`. */
|
|
13
|
+
export const rel = (path: string): string => relative(SRC, path)
|
|
14
|
+
|
|
15
|
+
function resolveSpecifier(from: string, specifier: string): string | undefined {
|
|
16
|
+
if (!specifier.startsWith('.')) return undefined
|
|
17
|
+
const base = resolve(dirname(from), specifier)
|
|
18
|
+
const candidates = /\.(tsx?|json)$/.test(base)
|
|
19
|
+
? [base]
|
|
20
|
+
: [`${base}.ts`, `${base}.tsx`, join(base, 'index.ts')]
|
|
21
|
+
for (const candidate of candidates) if (existsSync(candidate)) return candidate
|
|
22
|
+
throw new Error(`cannot resolve ${specifier} from ${rel(from)}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const edgeCache = new Map<string, string[]>()
|
|
26
|
+
const transpiler = new Bun.Transpiler({ loader: 'ts' })
|
|
27
|
+
|
|
28
|
+
/** Modules `path` evaluates at load. */
|
|
29
|
+
export function valueEdges(path: string): string[] {
|
|
30
|
+
const cached = edgeCache.get(path)
|
|
31
|
+
if (cached !== undefined) return cached
|
|
32
|
+
if (path.endsWith('.json')) return []
|
|
33
|
+
const edges = new Set<string>()
|
|
34
|
+
for (const entry of transpiler.scanImports(readFileSync(path, 'utf8'))) {
|
|
35
|
+
if (entry.kind !== 'import-statement') continue
|
|
36
|
+
const target = resolveSpecifier(path, entry.path)
|
|
37
|
+
if (target !== undefined) edges.add(target)
|
|
38
|
+
}
|
|
39
|
+
const result = [...edges]
|
|
40
|
+
edgeCache.set(path, result)
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Every module `entry` statically evaluates, each mapped to the module that
|
|
45
|
+
* first reached it (breadth-first; the entry maps to `''`). */
|
|
46
|
+
export function staticGraph(entry: string): Map<string, string> {
|
|
47
|
+
const predecessor = new Map<string, string>([[entry, '']])
|
|
48
|
+
const queue = [entry]
|
|
49
|
+
while (queue.length > 0) {
|
|
50
|
+
const current = queue.shift() as string
|
|
51
|
+
for (const next of valueEdges(current)) {
|
|
52
|
+
if (predecessor.has(next)) continue
|
|
53
|
+
predecessor.set(next, current)
|
|
54
|
+
queue.push(next)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return predecessor
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The import chain from the graph's entry to `target`, for failure messages. */
|
|
61
|
+
export function importChain(graph: Map<string, string>, target: string): string {
|
|
62
|
+
const chain: string[] = []
|
|
63
|
+
for (let at = target; at !== ''; at = graph.get(at) ?? '') chain.unshift(rel(at))
|
|
64
|
+
return chain.join(' → ')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Each excluded module (`src`-relative; a trailing `/` excludes a directory)
|
|
68
|
+
* the entry statically reaches, named by its import chain. */
|
|
69
|
+
export function reachedExclusions(entry: string, excluded: readonly string[]): string[] {
|
|
70
|
+
const graph = staticGraph(join(SRC, entry))
|
|
71
|
+
return [...graph.keys()]
|
|
72
|
+
.filter((path) =>
|
|
73
|
+
excluded.some((name) =>
|
|
74
|
+
name.endsWith('/') ? rel(path).startsWith(name) : rel(path) === name,
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
.map((path) => importChain(graph, path))
|
|
78
|
+
}
|