Skip to content

Commit 62505d4

Browse files
committed
chore(gates): enforce captured session state ownership
1 parent a8430eb commit 62505d4

3 files changed

Lines changed: 936 additions & 93 deletions

File tree

‎scripts/layering/check.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// - Over the RANKED SPINE only: rejection of every spine back-edge (R5), i.e.
2323
// an import whose source zone outranks its target zone, plus a ratchet on the
2424
// same inversion measured over TYPE-ONLY edges (R6).
25-
// - Over the DAEMON only: SessionState field ownership (R7), because the session
25+
// - Over the DAEMON and its capture-admission adapters: SessionState field ownership (R7), because the session
2626
// record is store-owned mutable state that any daemon module can write; and the terminal
2727
// concrete-platform boundary (R65), which rejects every import form into the retired
2828
// src/platforms path or a platform package.
@@ -315,6 +315,24 @@ function checkSessionStateOwnership(sources: ReadonlyMap<string, string>): Layer
315315
});
316316
continue;
317317
}
318+
const syntaxFailures: Readonly<Record<string, string>> = {
319+
'[patch-shape]':
320+
'Session updates require an explicit patch literal or inline synchronous callback returning named keys. Computed keys, spreads, getters, async callbacks and opaque patches cannot establish field ownership.',
321+
'[reentrant-patch]':
322+
'A session patch callback must not call back into the store. Read the supplied current record and return named fields synchronously.',
323+
'[whole-record-spread]':
324+
'Whole SessionState copies are allowed only inside the store or declared draft constructors. Update an existing lifetime through its field owner with a named patch.',
325+
};
326+
const syntaxFailure = syntaxFailures[write.field];
327+
if (syntaxFailure) {
328+
violations.push({
329+
rule: 'R7 session-state-ownership',
330+
file: write.file,
331+
line: write.line,
332+
message: syntaxFailure,
333+
});
334+
continue;
335+
}
318336
if (owners === undefined) {
319337
const storeOwned = STORE_OWNED_SESSION_STATE_FIELDS.has(write.field);
320338
violations.push({
@@ -324,7 +342,7 @@ function checkSessionStateOwnership(sources: ReadonlyMap<string, string>): Layer
324342
message: storeOwned
325343
? `session.${write.field} is classified store-established ` +
326344
`(STORE_OWNED_SESSION_STATE_FIELDS), meaning nothing mutates it after construction — ` +
327-
`but this is a direct write. Route it through the store, or move the field into ` +
345+
`but this is a write. Route it through the store, or move the field into ` +
328346
`SESSION_STATE_FIELD_OWNERS with this module as its owner.`
329347
: `session.${write.field} has no declared owner. SessionStore hands out the live ` +
330348
`record, so this write is durable: name the owning module in ` +

0 commit comments

Comments
 (0)