Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3924eb6
fix(oracle-gaps): retire a batch's copies from Vitest's state
KyleAMathews Nov 13, 2026
46dfd3e
test(oracle-gaps): bounded-retention law after each batch
KyleAMathews Nov 13, 2026
84a1085
fix(oracle-gaps): retire a copy's Vitest and Vite state, not only its…
KyleAMathews Nov 13, 2026
ce46f4b
test(oracle-gaps): the incremental violation names a cold run's error…
KyleAMathews Nov 13, 2026
2de2b9e
test(oracle-gaps): the incremental observation carries a cold run's e…
KyleAMathews Nov 13, 2026
ca327dc
fix(oracle-gaps): a replaced context leaves its maps; a cut-off run i…
KyleAMathews Nov 13, 2026
ce6c93d
test(oracle-gaps): the retention law compares every structure with it…
KyleAMathews Nov 13, 2026
390025e
test(oracle-gaps): the retention law counts stale replaced contexts; …
KyleAMathews Nov 14, 2026
9b81d6c
Merge origin/main into fix/gap-cli-retention
KyleAMathews Nov 14, 2026
59363c8
fix(oracle-gaps): a cold check keeps no unit for reuse
KyleAMathews Nov 14, 2026
969a7a8
test(oracle-gaps): the retention law counts batches exactly; cut batc…
KyleAMathews Nov 14, 2026
67f057d
test(oracle-gaps): the retention law counts copy-owned Vite nodes, no…
KyleAMathews Nov 14, 2026
2ed6f1e
test(oracle-gaps): the retention law names Vite's totals and bounds n…
KyleAMathews Nov 14, 2026
2b7efe6
test(oracle-gaps): the batch-line check defers a run with no report t…
KyleAMathews Nov 14, 2026
fefc857
test(oracle-gaps): the batch-line violation names the run that mismat…
KyleAMathews Nov 14, 2026
41d47db
test(oracle-gaps): a run's retention lines are its own: one hook file…
KyleAMathews Nov 14, 2026
a21287c
test(oracle-gaps): each retention line names its check's output direc…
KyleAMathews Nov 14, 2026
e223349
test(oracle-gaps): retention lines carry their batch index; a debug t…
KyleAMathews Nov 14, 2026
30e6cad
test(oracle-gaps): each CLI call has its own output directory, so its…
KyleAMathews Nov 14, 2026
6b1aa1d
test(oracle-gaps): the namespace law allows the numbered output direc…
KyleAMathews Nov 14, 2026
11105c5
test(oracle-gaps): the namespace law allows exactly the --out a run w…
KyleAMathews Nov 14, 2026
c4e7bc7
test(oracle-gaps): the observed text names a run's output directory w…
KyleAMathews Nov 14, 2026
9d3d3d2
test(oracle-gaps): output directories are numbered within each histor…
KyleAMathews Nov 14, 2026
270e6f4
test(oracle-gaps): at-once runs carry their retention lines; the rete…
KyleAMathews Nov 14, 2026
7515fd2
test(oracle-gaps): the retention hook names each non-copy file that h…
KyleAMathews Nov 14, 2026
8e6801a
test(oracle-gaps): a source file's plain node and its ?raw node are o…
KyleAMathews Nov 14, 2026
05f00e1
test(oracle-gaps): the daemon, partial, and stability retention sites…
KyleAMathews Nov 14, 2026
2203587
fix(oracle-gaps): a replaced context leaves the registry and joins it…
KyleAMathews Nov 14, 2026
8c48afe
fix(oracle-gaps): closing the contexts for a config change clears the…
KyleAMathews Nov 14, 2026
346c8a8
test(oracle-gaps): the daemon pause watches the state file of its own…
KyleAMathews Nov 14, 2026
79f1dea
fix(oracle-gaps): a crashed batch retires and logs; registry checks c…
KyleAMathews Nov 14, 2026
127a2b7
docs(oracles): the retention test hook is documented in the package R…
KyleAMathews Nov 14, 2026
65880b6
fix(oracle-gaps): the open-context identity counts a slot being replaced
KyleAMathews Nov 15, 2026
1b983e1
test(oracle-gaps): a batch whose run rejects is a constructed history…
KyleAMathews Nov 15, 2026
ecbd9a9
test(oracle-gaps): the rejected-batch state is declared in the requir…
KyleAMathews Nov 15, 2026
4f38731
test(oracle-gaps): the rejected-batch state is in the required list, …
KyleAMathews Nov 15, 2026
668f165
test(oracle-gaps): the rejected-batch history builds from the ordinar…
KyleAMathews Nov 15, 2026
253b861
test(oracle-gaps): rejectBatch is a generated field (0: no fault), ap…
KyleAMathews Nov 15, 2026
e7883f9
test(oracle-gaps): rejectBatch draws 0 or 1, appended last in the dra…
KyleAMathews Nov 15, 2026
e3dc2b0
test(oracle-gaps): the resolved plan carries rejectBatch
KyleAMathews Nov 15, 2026
43a4c7c
test(oracle-gaps): the rejected batch's reach state is marked after i…
KyleAMathews Nov 15, 2026
21cf701
test(oracle-gaps): a rejected batch's run observes its exit, last lin…
KyleAMathews Nov 15, 2026
269f938
test(oracle-gaps): the rejected-batch state is separate, so the all-c…
KyleAMathews Nov 15, 2026
a3c3ffe
docs(oracles): the rejected-batch test hook is documented in the pack…
KyleAMathews Nov 15, 2026
c0e3b0e
test(oracle-gaps): the rejected-batch history's three tests are in sh…
KyleAMathews Nov 15, 2026
d54c437
test(oracle-gaps): the rejected-batch history is in Windows fixed-see…
KyleAMathews Nov 15, 2026
0e580e5
test(oracle-gaps): rejectBatch is a constructed-only field, taken bac…
KyleAMathews Nov 15, 2026
954a5f3
test(oracle-gaps): a constructed history is taken back through its un…
KyleAMathews Nov 15, 2026
cb25107
fix(oracles): the unmapper is passed only when a construction has one…
KyleAMathews Nov 15, 2026
9945dc9
Merge origin/main into fix/gap-cli-retention
KyleAMathews Nov 15, 2026
025c2fe
test(oracle-gaps): the rejected batch skips main's internal-error and…
KyleAMathews Nov 15, 2026
83552e7
test(oracle-gaps): rejectBatch is recorded at the end of the generato…
KyleAMathews Nov 15, 2026
b26d962
test(oracle-gaps): the rejected batch's run is judged by the output n…
KyleAMathews Nov 15, 2026
f60623e
Merge origin/main into fix/gap-cli-retention
KyleAMathews Nov 15, 2026
231a689
test(oracle-gaps): the rejected-batch history pins its config, so a r…
KyleAMathews Nov 15, 2026
92d85ae
test(oracle-gaps): the rejected-batch history pins its native and con…
KyleAMathews Nov 15, 2026
9ab499e
test(oracle-gaps): retention lines are attributed to the process that…
KyleAMathews Nov 15, 2026
099bf0a
test(oracle-gaps): the check writes its pid under the test hook, and …
KyleAMathews Nov 15, 2026
38fb2d6
test(oracle-gaps): rejectBatch is taken back in the model's mapping; …
KyleAMathews Nov 16, 2026
fdb1f5f
test(oracle-gaps): the retention law reads real objects, judges every…
KyleAMathews Nov 16, 2026
34929a9
test(oracle-gaps): law 9's first cold run keeps its retention lines a…
KyleAMathews Nov 16, 2026
85fd038
test(oracle-gaps): the killed daemon's retention lines are a declared…
KyleAMathews Nov 16, 2026
ff5c021
test(oracle-gaps): a stopped run's retention lines are the ones it ap…
KyleAMathews Nov 16, 2026
7d0eccb
Merge origin/main into fix/gap-cli-retention
KyleAMathews Nov 16, 2026
f14b872
Merge origin/main into fix/gap-cli-retention
KyleAMathews Nov 16, 2026
1f67a4b
fix(oracle-gaps): the retention hook ships, so the CLI cites only fil…
KyleAMathews Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/oracles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ Show me what oracle testing with @tanstack/oracles can find in this repository.
3. Read node_modules/@tanstack/oracles/skills/oracles-explore/SKILL.md in full,
and follow it. Use <sha> wherever a skill asks for the commit to pin.
```

## Test hooks

`ORACLE_GAPS_TEST_RETENTION` (a file path, unset in normal use) makes the gap CLI append one JSON line per mutant batch it runs, however the batch ends: settled, cut off, or rejected. It only observes: it never changes an outcome. The e2e oracle reads it to check bounded retention. The hook's code is in `oracle-gaps/retention-hook.mjs`, which the CLI loads only when this variable or `ORACLE_GAPS_TEST_REJECT_BATCH` is set, so a normal run never loads it.

Under the hook, each check also writes `check.pid` (the id of the process that runs the check: the CLI's supervised child, or a daemon) into its `--out` directory, after the CLI creates that directory. Each line has:

- `run`: the check's `--out` path.
- `pid`: the id of the process that wrote the line. The oracle compares it with `check.pid`.
- `batch`: the batch's own index within its check, from 0, taken when the batch starts.
- `before`: Vitest's and Vite's structure sizes before the batch, and the `stale*` counts. `staleIndexed` and `staleSpecs` count registry entries that name no live context. `staleOpen` counts contexts that left the live array and that Vitest has not started to close (its own close state). All three must be 0.
- `held`: how many of the entries the check gave its store are still reachable after a full garbage collection, which the hook runs before it writes the line. A cold check's store keeps none, so this must be 0 there. A daemon's store keeps its entries by design.
- For a settled or rejected batch: `after` (the sizes after its copies are retired), `copyNodes` (Vite module nodes that still name a copy, must be 0), and `nonCopyDup` (non-copy files with more than one module node in an environment, must be 0 beyond the measured plain-plus-`?raw` pair).
- For a cut batch: `cut: true` and no `after`. Its context is replaced, not retired.

`ORACLE_GAPS_TEST_REJECT_BATCH` (a batch number from 1, unset in normal use) makes the gap CLI's n-th batch run reject, as a crash in Vitest would. It is a test-only fault: the batch's run completes, so its copies are in Vitest's and Vite's state, and then the run's promise rejects, which takes the same path a real crash takes. The run then ends as an internal error: exit 3, the done error line, and `error.log` in its output directory. The batch's copies are still retired and its retention line is still written.
246 changes: 194 additions & 52 deletions packages/oracles/oracle-gaps/check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ export default async (env) => {
let seedVariable = `ORACLE_SEED`
const contextSpecs = new Map()
let runCounter = 0
// The retention test hook (retention-hook.mjs, README "Test hooks"): loaded
// only when one of its variables is set, so a normal run never loads it.
const hook =
process.env.ORACLE_GAPS_TEST_RETENTION ||
process.env.ORACLE_GAPS_TEST_REJECT_BATCH
? (await import(`./retention-hook.mjs`)).retentionHook({
live: () => contexts,
indexOf,
contextSpecs,
})
: undefined

// A context loads the package's own config through its wrapper, so an
// error there is the author's: the run refuses, naming the config file
Expand Down Expand Up @@ -783,21 +794,19 @@ export default async (env) => {
`Run the gap report on a package whose Vitest config has no test.projects.`,
)
}
indexOf.set(context, index)
lastServed.delete(index)
return context
}
async function globSpecs(context) {
// A warm context caches the test files it found; a file added since the
// last check, such as a new oracle file, appears only after the cache is
// cleared.
// A warm context caches the test files it found; a file added since the last check, such as a new oracle
// file, appears only after the cache is cleared. Returns the context's specs (registered by the caller).
async function specsOf(context) {
context.clearSpecificationsCache?.()
const map = new Map()
for (const spec of await context.globTestSpecifications()) {
if (isRunnerCopy(spec.moduleId)) continue
map.set(spec.moduleId, [...(map.get(spec.moduleId) ?? []), spec])
}
contextSpecs.set(context, map)
return map
}
async function closeContexts() {
await Promise.all(
Expand All @@ -808,6 +817,12 @@ export default async (env) => {
]),
),
)
// The closed contexts leave the registry with the array: a context closed for a config change is no longer
// reachable through indexOf or contextSpecs (the daemon's edit sequence left them there before).
for (const context of contexts) {
indexOf.delete(context)
contextSpecs.delete(context)
}
contexts = []
lastServed.clear()
}
Expand Down Expand Up @@ -1084,6 +1099,9 @@ export default async (env) => {
let holdCounter = 0
async function runBatch(context, out, items, seed) {
const capture = join(out, `run-${process.pid}-${++runCounter}.jsonl`)
// The retention hook's view of this batch: its own index, and the totals
// before it (retention-hook.mjs).
const observed = hook?.begin(context)
// Each copy is named beside its file, so that its imports resolve as the
// file's do, and the wrapper's plugin serves its text: nothing is
// written there.
Expand Down Expand Up @@ -1148,10 +1166,13 @@ export default async (env) => {
writeFileSync(join(out, `state.json`), JSON.stringify(state))
const project = context.getRootProject()
const started = Date.now()
const running = context.runTestSpecifications(
const run = context.runTestSpecifications(
copies.map((copy) => project.createSpecification(copy)),
false,
)
// Test-only fault (ORACLE_GAPS_TEST_REJECT_BATCH=<n>): the n-th batch's
// run rejects once its copies are in Vitest's state, as a crash would.
const running = hook ? hook.fault(observed, run) : run
// The watchdog: each copy writes a starting row when its setup runs and
// a closing row when it finishes, so the copy that is running is the
// last that started, or the one after it once that one closed. A copy
Expand Down Expand Up @@ -1214,45 +1235,50 @@ export default async (env) => {
}
timer = setTimeout(poll, 50)
})
const result = await Promise.race([running, watchdog])
clearTimeout(timer)
const seconds = (Date.now() - started) / 1000
// Each copy's rows, and the copies that skipped their tests because an
// earlier copy in the batch killed their mutant.
const skipped = new Set()
// Each copy's closing row: the files of the modules it evaluated, and the
// files it read with their hashes.
const closings = new Map()
const rowsOf = (partial) => {
const rows = new Map(copies.map((copy) => [copy, []]))
closings.clear()
if (existsSync(capture))
for (const line of captureLines(capture, { partial })) {
const row = JSON.parse(line)
const copy = copies.find(
(c) =>
posix(row.key ?? ``).startsWith(`${c} > `) ||
posix(row.file ?? ``) === c,
)
if (copy && row.skipped) skipped.add(copy)
if (copy && row.closed) closings.set(copy, row)
if (copy && row.spin) spun.add(copy)
if (copy && !row.closed && !row.idle && !row.spin && !row.started)
rows.get(copy).push(row)
}
return rows
}
const skippedUnit = (item) => ({ file: item.file, skipped: true })
// A copy that ran past its call budget, even one whose throw ended the
// loop and let it finish, is a timeout as it stands (a count, not a
// clock: no confirming run).
const spunUnit = (item) => ({
file: item.file,
timedOut: true,
spin: true,
seconds,
})
// The race sits inside the try below, so a rejected run (a crash, not a cut) still retires its
// copies and writes its retention line. `raced` tells that apart from a cut, which resolves undefined.
let result
let raced = false
try {
result = await Promise.race([running, watchdog])
raced = true
clearTimeout(timer)
const seconds = (Date.now() - started) / 1000
// Each copy's rows, and the copies that skipped their tests because an
// earlier copy in the batch killed their mutant.
const skipped = new Set()
// Each copy's closing row: the files of the modules it evaluated, and the
// files it read with their hashes.
const closings = new Map()
const rowsOf = (partial) => {
const rows = new Map(copies.map((copy) => [copy, []]))
closings.clear()
if (existsSync(capture))
for (const line of captureLines(capture, { partial })) {
const row = JSON.parse(line)
const copy = copies.find(
(c) =>
posix(row.key ?? ``).startsWith(`${c} > `) ||
posix(row.file ?? ``) === c,
)
if (copy && row.skipped) skipped.add(copy)
if (copy && row.closed) closings.set(copy, row)
if (copy && row.spin) spun.add(copy)
if (copy && !row.closed && !row.idle && !row.spin && !row.started)
rows.get(copy).push(row)
}
return rows
}
const skippedUnit = (item) => ({ file: item.file, skipped: true })
// A copy that ran past its call budget, even one whose throw ended the
// loop and let it finish, is a timeout as it stands (a count, not a
// clock: no confirming run).
const spunUnit = (item) => ({
file: item.file,
timedOut: true,
spin: true,
seconds,
})
if (result === undefined) {
// Cancelled without waiting; the caller replaces the context (see
// runUnit).
Expand Down Expand Up @@ -1359,10 +1385,106 @@ export default async (env) => {
}
} finally {
for (const copy of copies) globalThis.__oracleGapsCopies.delete(copy)
// A run cut off by a hang is still running: its worker may still send
// updates, so its state is not touched here. Its context is replaced
// by the caller (replace), which closes it and drops its state.
clearTimeout(timer)
const cut = raced && result === undefined
if (!cut) retireCopies(context, copies)
await hook?.line(context, observed, copies, cut)
rmSync(capture, { force: true })
}
}

/**
* Removes a batch's copies from Vitest's state and from Vite's module
* graphs once their units are plain data (the register's C entry: the gap
* CLI keeps no Vitest or Vite state for a mutant copy after the copy's
* results are plain data). Each copy is a new file. Vitest keeps its path
* in `filesMap` and `pathsSet`, and the file and test tasks it ran in
* `idMap`, and Vite keeps a module node, with its transform, per copy.
* Vitest's `clearFiles` replaces the path's file entry only, and leaves
* `pathsSet` and the test tasks, so it is not used: each entry is removed.
* Every map touched is guarded, and a Vitest or Vite whose shape changes
* throws here rather than leaking quietly. During a run, Vitest holds the
* run's copies until it ends, so the in-run peak scales with the batch's
* share of copies, not with the suite.
*/
function retireCopies(context, copies) {
const { filesMap, idMap, pathsSet } = context.state ?? {}
if (
!(filesMap instanceof Map) ||
!(idMap instanceof Map) ||
!(pathsSet instanceof Set)
)
throw new Error(
`oracle-gaps: this Vitest keeps no filesMap, idMap, or pathsSet in its state, so a check cannot retire its copies`,
)
const gone = new Set(copies)
for (const [id, task] of idMap)
if (gone.has(task.file?.filepath ?? task.filepath)) idMap.delete(id)
for (const copy of copies) {
filesMap.delete(copy)
pathsSet.delete(copy)
}
retireModules(context.getRootProject().vite, gone)
}

/**
* Removes the copies' module nodes from every environment's Vite graph.
* Each node is invalidated through Vite's API (which drops its transform),
* then removed from the graph's id, url, etag, and file maps, and from its
* neighbours' import sets. The graph's map shapes are guarded.
*/
function retireModules(server, gone) {
const environments = viteEnvironments(server)
for (const environment of environments) {
const graph = environment.moduleGraph
const {
urlToModuleMap,
idToModuleMap,
etagToModuleMap,
fileToModulesMap,
} = graph ?? {}
if (
!(urlToModuleMap instanceof Map) ||
!(idToModuleMap instanceof Map) ||
!(etagToModuleMap instanceof Map) ||
!(fileToModulesMap instanceof Map) ||
typeof graph.invalidateModule !== `function`
)
throw new Error(
`oracle-gaps: this Vite's module graph has no id, url, etag, or file maps, so a check cannot retire its copies`,
)
for (const copy of gone) {
for (const mod of fileToModulesMap.get(copy) ?? []) {
graph.invalidateModule(mod)
for (const imported of mod.importedModules)
imported.importers.delete(mod)
for (const importer of mod.importers)
importer.importedModules.delete(mod)
idToModuleMap.delete(mod.id)
urlToModuleMap.delete(mod.url)
// Vite keys the etag map by the etag, whose value is the node.
for (const [etag, node] of etagToModuleMap)
if (node === mod) etagToModuleMap.delete(etag)
}
fileToModulesMap.delete(copy)
}
}
}

// Vite's environments, each with its module graph. A Vite that exposes none
// would make the module step a silent no-op, so it throws here.
function viteEnvironments(server) {
const environments = Object.values(server?.environments ?? {})
if (environments.length === 0 || environments.some((e) => !e?.moduleGraph))
throw new Error(
`oracle-gaps: this Vitest exposes no Vite environments with module graphs, so a check cannot retire its copies' module nodes`,
)
return environments
}

async function check(options, store, log = console.error) {
const authored = options.mutants ? loadAuthored(options.mutants) : []
seedVariable = `${options.envPrefix}_SEED`
Expand All @@ -1375,6 +1497,7 @@ export default async (env) => {
every: Number(process.env.ORACLE_GAPS_HEARTBEAT_MS ?? 30_000),
}
mkdirSync(options.out, { recursive: true })
hook?.check(options.out)
// An earlier run's internal error; a completed check writes the other
// files of an ending over the earlier ones (ending.mjs).
rmSync(join(options.out, `error.log`), { force: true })
Expand Down Expand Up @@ -1421,13 +1544,19 @@ export default async (env) => {
(contexts.length > 0 && configHash() !== contextsConfig)
) {
await closeContexts()
for (let i = 0; i < options.contexts; i += 1)
for (let i = 0; i < options.contexts; i += 1) {
contexts.push(await warmContext(settings, i))
indexOf.set(contexts.at(-1), i)
hook?.joined(contexts.at(-1))
}
contextsKey = JSON.stringify(settings)
contextsConfig = configHash()
}
while (contexts.length < options.contexts)
while (contexts.length < options.contexts) {
contexts.push(await warmContext(settings, contexts.length))
indexOf.set(contexts.at(-1), contexts.length - 1)
hook?.joined(contexts.at(-1))
}
endPhase(`warm contexts`, { contexts: contexts.length })
// The run names the config its contexts loaded, before any refusal that
// the analysis or the baseline makes.
Expand All @@ -1437,7 +1566,8 @@ export default async (env) => {
settings.config ?? `none, Vitest's default discovery`,
),
)
for (const context of contexts) await globSpecs(context)
for (const context of contexts)
contextSpecs.set(context, await specsOf(context))
endPhase(`find test files`)

// 1. The static half (analysis.mjs): instrumented sources, mutants,
Expand Down Expand Up @@ -1555,7 +1685,10 @@ export default async (env) => {
return stable ? inputs : undefined
}
const remember = (id, unit, inputs) => {
if (inputs) store.put(id, { inputs, unit })
if (!inputs) return
const entry = { inputs, unit }
hook?.stored(entry)
store.put(id, entry)
}
// A batch run in a slot's context, with the inputs to store each item
// under: the modules its file's unmutated run read, and those its copy
Expand Down Expand Up @@ -1830,9 +1963,18 @@ export default async (env) => {
closeContext(slot.context).catch(() => undefined),
sleep(10_000),
])
slot.context = await warmContext(settings, slot.index)
await globSpecs(slot.context)
contexts[slot.index] = slot.context
const replaced = slot.context
const next = await warmContext(settings, slot.index)
const specs = await specsOf(next)
// One synchronous step: the replaced context leaves every map keyed by it and the new one joins them,
// with the contexts array, so no reader (and no measurement) sees the registry and the array disagree.
indexOf.delete(replaced)
contextSpecs.delete(replaced)
indexOf.set(next, slot.index)
contextSpecs.set(next, specs)
contexts[slot.index] = next
slot.context = next
hook?.joined(next)
span(`replace context`, started, { slot: slot.index })
}
// `after(index)` is more work for context `index` once its files ran.
Expand Down
15 changes: 8 additions & 7 deletions packages/oracles/oracle-gaps/evidence.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ const withVersion = (row, variant) =>
),
].slice(0, VERSIONS)

/** A store that lives for one check. */
/**
* The store of a cold check. It keeps no unit: a cold run serves no lookup
* (its evidence reports `reused` 0 on every klona run measured), so a unit
* kept for reuse would only be retained, per mutant copy, for the whole run.
* The retention law observes this through the entries' reachability
* (retention-hook.mjs), not through anything the store reports.
*/
export function memoryStore() {
const rows = new Map()
return {
get: (id) => rows.get(id),
put: (id, variant) =>
rows.set(id, { id, variants: withVersion(rows.get(id), variant) }),
}
return { get: () => undefined, put: () => {} }
}

/**
Expand Down
Loading
Loading