Skip to content

Commit a1741e9

Browse files
committed
🌱 Hold a generated admission to a retained root basis, not the run's frozen past (#589)
A continuation now asks for the admission's Workspace roots by membership — every admission root and its selected root still retained, the current root retained — while classes, pinned identities, forms and request ceilings keep comparing whole and exactly. The run's own root publications and an advanced current root no longer refuse the resume the run itself recorded. GX18a/b replay under an added, newly current root; GX22/GX22b prove the progression resumes and reaches the generated component; GX22c/GX22d prove root loss refuses before it runs. WGAC16 goes green through real start, answer and resume, holding journal counts, the ordered durable subsequence, the root-publication count and the current root identical across all three — an API.Files call is deliberately not once-only evidence, since re-expansion enters that boundary before the durable effect restores. architecture.md, workflow-workspace-spec §§8.4/9, executable-mdx-spec and DEC-015 record the basis semantics and the non-causal DEC-034 conformance of the Operation evaluator.
1 parent 7f8ac03 commit a1741e9

10 files changed

Lines changed: 353 additions & 120 deletions

File tree

‎architecture.md‎

Lines changed: 41 additions & 16 deletions
Large diffs are not rendered by default.

‎packages/cli/tests/workflow-suspension.test.ts‎

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { until } from "effection";
3535
import { join } from "node:path";
3636
import { tmpdir } from "node:os";
3737
import { DatabaseSync } from "node:sqlite";
38-
import { API } from "@executablemd/runtime";
3938
import { collect, execute, inlineSource, registerComponents } from "@executablemd/core";
4039
import { executeInstalled } from "@executablemd/core/host";
4140
import { durableCall, InMemoryStream } from "@executablemd/durable-streams";
@@ -837,12 +836,7 @@ function* useStubAgent(calls: AgentCalls): Operation<void> {
837836
* cases depend on is installed by the code that installs it in production
838837
* rather than by this suite.
839838
*/
840-
function productionHost(
841-
root: string,
842-
calls: AgentCalls,
843-
events: string[] = [],
844-
performed?: string[],
845-
): WorkflowHost {
839+
function productionHost(root: string, calls: AgentCalls, events: string[] = []): WorkflowHost {
846840
return {
847841
useRunHost(): Operation<WorkflowExecutionTransitions> {
848842
return useWorkflowRunHost({ root });
@@ -859,21 +853,6 @@ function productionHost(
859853
yield* ensure(function* () {
860854
events.push("released");
861855
});
862-
if (performed !== undefined) {
863-
// A pass-through observer around the ordinary Files boundary, so a
864-
// case can count what a document execution actually performed there
865-
// rather than inferring it from the rows a replay restored.
866-
yield* API.Files.around({
867-
*readTextFile([input], next) {
868-
performed.push(`read:${input.path}`);
869-
return yield* next(input);
870-
},
871-
*writeTextFile([input], next) {
872-
performed.push(`write:${input.path}`);
873-
return yield* next(input);
874-
},
875-
});
876-
}
877856
return yield* withWorkflowWorkspace(database, operation, {
878857
agent: () => useStubAgent(calls),
879858
});
@@ -1054,6 +1033,24 @@ function journalled(path: string, type: string): number {
10541033
}
10551034
}
10561035

1036+
/** The Workspace roots this run has published, and the one it stands on. */
1037+
function workspaceRootState(path: string): { retained: number; current: string } {
1038+
const database = new DatabaseSync(path, { readOnly: true });
1039+
try {
1040+
const retained = Number(
1041+
database.prepare("SELECT COUNT(*) AS count FROM workspace_roots").get()?.["count"],
1042+
);
1043+
const current = String(
1044+
database
1045+
.prepare("SELECT current_root_id FROM workspace_state WHERE singleton_id = 1")
1046+
.get()?.["current_root_id"],
1047+
);
1048+
return { retained, current };
1049+
} finally {
1050+
database.close();
1051+
}
1052+
}
1053+
10571054
/** Every durable yield this run retained, in journal order, as type and name. */
10581055
function orderedEffects(path: string): { type: string; name: string }[] {
10591056
const database = new DatabaseSync(path, { readOnly: true });
@@ -1303,8 +1300,16 @@ describe("Tier CKX — a checkpoint a document asked for", () => {
13031300
* the real workflow `<Elicit>` follow outside it. The admission and every
13041301
* durable effect the admitted fragment performs belong to the owning document
13051302
* expansion's sequence, so a resume offers them in authored order and restores
1306-
* each completed one without entering its provider again — which the existing
1307-
* root-level checkpoint above does not discriminate.
1303+
* each completed one without another live execution or root publication —
1304+
* which the existing root-level checkpoint above does not discriminate.
1305+
*
1306+
* The once-only proof here is stability: the exact journal counts, the ordered
1307+
* durable subsequence, the Workspace root-publication count, and the
1308+
* authoritative current root are captured at suspension and must survive
1309+
* answer delivery and the completed resume unchanged. An `API.Files` call is
1310+
* deliberately not evidence — document re-expansion legitimately enters that
1311+
* boundary again before the durable `workspace_file` effect underneath
1312+
* restores, so a call count there sits above the live/restore decision.
13081313
*/
13091314
describe("Tier WGAC — generated effects in a bundled component resume through a later wait", () => {
13101315
/** One root declaring one bundled component, with the wait after both. */
@@ -1340,8 +1345,6 @@ decision: {decision.proceed}
13401345
the retained note
13411346
</File>
13421347
`,
1343-
// What the fragment performs at the Files boundary, exactly once.
1344-
live: (call: string) => call.startsWith("read:") && call.endsWith("notes.md"),
13451348
nested: [{ operation: "read", target: "notes.md" }],
13461349
files: 3,
13471350
},
@@ -1351,7 +1354,6 @@ the retained note
13511354
component:
13521355
`<Evaluate source={"<File path=\\"proposed.md\\">a generated proposal</File>"} allow={["write"]} as="observed" />\n`,
13531356
setup: "",
1354-
live: (call: string) => call.startsWith("write:") && call.endsWith("proposed.md"),
13551357
nested: [{ operation: "write", target: "proposed.md" }],
13561358
files: 2,
13571359
},
@@ -1367,12 +1369,11 @@ the retained note
13671369
yield* useRepositoryGit(fixture.repository);
13681370

13691371
const calls: AgentCalls = { prompts: [] };
1370-
const performed: string[] = [];
13711372
const rendered: string[] = [];
13721373
const started = yield* invoke(
13731374
{ ...REQUEST, action: "start" },
13741375
yield* startFor(fixture),
1375-
productionHost(store, calls, [], performed),
1376+
productionHost(store, calls),
13761377
pinnedBody(rendered),
13771378
);
13781379
expect(started.exitCode).toBe(2);
@@ -1383,8 +1384,9 @@ the retained note
13831384
const path = workflowRunPath(store, runId);
13841385

13851386
// The start settled suspended, with the nested effect and the later
1386-
// parent effect committed ahead of the wait — and the fragment reached
1387-
// the Files boundary exactly once.
1387+
// parent effect committed ahead of the wait. The journal counts and the
1388+
// Workspace root publications captured here are the once-only baseline
1389+
// everything after the suspension is held to.
13881390
const suspended = retained(path);
13891391
expect(suspended.status).toBe("suspended");
13901392
expect(suspended.requests).toHaveLength(1);
@@ -1395,7 +1397,7 @@ the retained note
13951397
[EVALUATION_EFFECT]: 1,
13961398
[FILE_EFFECT]: bundled.files,
13971399
});
1398-
expect(performed.filter(bundled.live)).toHaveLength(1);
1400+
const rootsAtSuspension = workspaceRootState(path);
13991401

14001402
// The relevant ordered subsequence, exactly: the admission, the nested
14011403
// generated effect in authored order, the later parent effect, then the
@@ -1424,27 +1426,28 @@ the retained note
14241426
const suspensionId = suspended.requests[0] ?? "";
14251427
const delivered = yield* manage(
14261428
{ action: "answer", runId, suspensionId, value: { proceed: true }, secretDetection: true },
1427-
productionHost(store, calls, [], performed),
1429+
productionHost(store, calls),
14281430
);
14291431
expect(delivered.exitCode).toBe(0);
14301432
expect(retained(path)).toEqual(suspended);
1431-
expect(performed.filter(bundled.live)).toHaveLength(1);
1433+
expect(counts(path)).toEqual(atSuspension);
1434+
expect(workspaceRootState(path)).toEqual(rootsAtSuspension);
14321435

1433-
// The resume completes, restores every committed effect, and performs
1434-
// the fragment's work no second time: one live call at the Files
1435-
// boundary across both document executions.
1436+
// The resume completes and restores every committed effect: the same
1437+
// journal counts, the same ordered durable subsequence, the same root
1438+
// publications, and the same authoritative current root.
14361439
const resumed = yield* invoke(
14371440
{ ...REQUEST, action: "resume", target: runId },
14381441
undefined,
1439-
productionHost(store, calls, [], performed),
1442+
productionHost(store, calls),
14401443
pinnedBody(rendered),
14411444
);
14421445
expect(resumed.exitCode).toBe(0);
14431446

14441447
const completed = retained(path);
14451448
expect(completed.status).toBe("completed");
14461449
expect(counts(path)).toEqual(atSuspension);
1447-
expect(performed.filter(bundled.live)).toHaveLength(1);
1450+
expect(workspaceRootState(path)).toEqual(rootsAtSuspension);
14481451
expect(
14491452
orderedEffects(path)
14501453
.filter((effect) => relevant.has(effect.type))

‎packages/core/src/generated-xmd.ts‎

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@
7070
* Durable replay matches an effect by its type and name; what a description
7171
* carries is stored, never compared. So the retained admission carries the
7272
* normalized policy in its **result** as well as in the event input, and a
73-
* continuation compares that retained policy to the one this run states — whole
74-
* and exactly — before a single generated component is invoked or a single
75-
* effect is performed. A changed class selection, changed roots, a changed
76-
* pinned identity behind the same name, a changed admitted form, and a widened
77-
* request ceiling are each refused there. Only the tables the selection reached
78-
* take part, so a write table a read-only admission never drew on may move
79-
* without invalidating it.
73+
* continuation checks that retained policy against the one this run states
74+
* before a single generated component is invoked or a single effect is
75+
* performed. The Workspace roots are as-of-admission provenance and are asked
76+
* for by membership: the run's own progress legitimately retains further
77+
* roots and advances the authoritative current root, while a run that no
78+
* longer retains an admission root — or its selected root — is refused. Every
79+
* other term compares whole and exactly: a changed class selection, a changed
80+
* pinned identity behind the same name, a changed admitted form, and a
81+
* widened request ceiling are each refused there. Only the tables the
82+
* selection reached take part, so a write table a read-only admission never
83+
* drew on may move without invalidating it.
8084
*
8185
* That is also why the walk lives inside the admission's live executor. A
8286
* continuation restores what was admitted without consulting the current source
@@ -1048,23 +1052,37 @@ function readNamed(value: readonly Json[]): RetainedInvocation[] | undefined {
10481052
}
10491053

10501054
/**
1051-
* Whether a resumed run states exactly the ceilings the retained admission was
1052-
* granted under.
1055+
* Whether a resumed run still holds the grant the retained admission was made
1056+
* under.
10531057
*
1054-
* Whole and exact, in order: a root added, a root reordered, one identity
1055-
* behind a name replaced, or one request added to the allowed set each make
1056-
* this false. Widening is the case that matters most — a ceiling that still
1057-
* contains the original request is precisely the one that comparing the
1058-
* *fragment* against the *current* policy would wave through.
1058+
* Two kinds of term, compared differently on purpose.
1059+
*
1060+
* The Workspace roots are as-of-admission provenance over a set the run's own
1061+
* progress legitimately grows: every committed mutation retains another
1062+
* immutable root and advances the authoritative current root. So the retained
1063+
* basis is asked for by membership — every admission root and the admission's
1064+
* selected root must still be retained, and the root the run now stands on
1065+
* must be a retained one — while additional roots and an advanced current
1066+
* root change nothing this admission was granted under. A run that lost an
1067+
* admission root no longer holds the history the grant was made over, and is
1068+
* refused before any generated work.
1069+
*
1070+
* Every other term is a host-stated ceiling and compares whole and exactly,
1071+
* in order: a widened class selection, one identity behind a name replaced, a
1072+
* form added, or one request added to the allowed set each make this false.
1073+
* Widening is the case that matters most — a ceiling that still contains the
1074+
* original request is precisely the one that comparing the *fragment* against
1075+
* the *current* policy would wave through.
10591076
*/
1060-
function samePolicy(retained: Policy, current: Policy): boolean {
1061-
if (retained.selectedRoot !== current.selectedRoot) {
1077+
function policyHolds(retained: Policy, current: Policy): boolean {
1078+
const held = new Set(current.roots);
1079+
if (!retained.roots.every((root) => held.has(root))) {
10621080
return false;
10631081
}
1064-
if (!sameStrings(retained.allow, current.allow)) {
1082+
if (!held.has(retained.selectedRoot) || !held.has(current.selectedRoot)) {
10651083
return false;
10661084
}
1067-
if (!sameStrings(retained.roots, current.roots)) {
1085+
if (!sameStrings(retained.allow, current.allow)) {
10681086
return false;
10691087
}
10701088
if (retained.allowed.length !== current.allowed.length) {
@@ -1374,9 +1392,12 @@ export function* evaluateGeneratedXmd(
13741392
throw new GeneratedXmdError(CONSTRUCT[decided.construct]);
13751393
}
13761394
// Before a single component is invoked or a single request is performed: a
1377-
// retained admission is a grant under the ceilings it was granted with, and a
1378-
// run that states different ones is asking for a different grant.
1379-
if (!samePolicy(decided.policy, policy)) {
1395+
// retained admission is a grant whose non-root ceilings must be stated
1396+
// exactly again, and whose Workspace basis must still be retained. The run's
1397+
// own progress may have retained further roots and advanced the current one;
1398+
// a run that lost an admission root, or moved any exact term, is asking for
1399+
// a different grant.
1400+
if (!policyHolds(decided.policy, policy)) {
13801401
throw new GeneratedXmdError(CEILING);
13811402
}
13821403

0 commit comments

Comments
 (0)