@@ -27,15 +27,17 @@ import assert from 'node:assert/strict';
2727
2828import { runTorture , type ClientOp , type TortureRunResult } from './concurrency-torture/harness.ts' ;
2929import { DEVICE_POOL } from './concurrency-torture/bindings.ts' ;
30+ import { measureRealScopeMaxOverlap } from './concurrency-torture/real-scope-serialization.ts' ;
3031import { buildEnvelope , writeEnvelopeIfRequested } from './concurrency-torture/envelope.ts' ;
3132
3233// The #1430 envelope must report the outcome of the WHOLE lane, not just the
3334// sweep test. Every test records its result here and the envelope is written
3435// once, after all tests settle, so a later failing guardrail can never be
3536// published as a passing envelope.
36- type EnvelopeRun = { seedStart : number ; runs : number ; durationMs : number } ;
37+ type SweepRange = { seedStart : number ; runs : number } ;
38+ const laneStartedMs = Date . now ( ) ;
3739let laneFailed = false ;
38- let sweepRun : EnvelopeRun | undefined ;
40+ let sweepRange : SweepRange | undefined ;
3941
4042async function guard ( body : ( ) => Promise < void > ) : Promise < void > {
4143 try {
@@ -47,8 +49,14 @@ async function guard(body: () => Promise<void>): Promise<void> {
4749}
4850
4951after ( ( ) => {
50- if ( ! sweepRun ) return ; // only the sweep lane (nightly) publishes an envelope
51- const envelope = buildEnvelope ( { ...sweepRun , result : laneFailed ? 'fail' : 'pass' } ) ;
52+ if ( ! sweepRange ) return ; // only the sweep lane (nightly) publishes an envelope
53+ // Duration spans the WHOLE lane (sweep + replay + both serialization guards),
54+ // measured to this hook, so it can't understate work by excluding later tests.
55+ const envelope = buildEnvelope ( {
56+ ...sweepRange ,
57+ durationMs : Date . now ( ) - laneStartedMs ,
58+ result : laneFailed ? 'fail' : 'pass' ,
59+ } ) ;
5260 const written = writeEnvelopeIfRequested ( envelope ) ;
5361 if ( written ) console . log ( `torture envelope → ${ written } \n${ JSON . stringify ( envelope ) } ` ) ;
5462} ) ;
@@ -114,6 +122,22 @@ const explicitSeed = optionalIntFromEnv('TORTURE_SEED');
114122const clients = optionalIntFromEnv ( 'TORTURE_CLIENTS' ) ;
115123const opsPerClient = optionalIntFromEnv ( 'TORTURE_OPS' ) ;
116124
125+ // Guard the PRODUCTION lock APPLICATION path, not just the modeled sweep: drive
126+ // concurrent same-device opens through the real `createRequestExecutionScope()
127+ // .runLocked()` (→ `withRequestExecutionLocks` → `withKeyedLock`) and assert
128+ // they never overlap. Regressing production serialization trips this even
129+ // though the seeded sweep models the grant. Runs in every mode.
130+ test ( 'concurrency torture — real-scope same-device serialization' , ( ) =>
131+ guard ( async ( ) => {
132+ const maxOverlap = await measureRealScopeMaxOverlap ( 4 ) ;
133+ assert . equal (
134+ maxOverlap ,
135+ 1 ,
136+ `real createRequestExecutionScope().runLocked() let ${ maxOverlap } same-device critical ` +
137+ 'sections overlap — production execution locking is not serializing' ,
138+ ) ;
139+ } ) ) ;
140+
117141if ( explicitSeed !== undefined ) {
118142 test ( `concurrency torture — replay seed ${ explicitSeed } ` , ( ) =>
119143 guard ( async ( ) => {
@@ -128,28 +152,24 @@ if (explicitSeed !== undefined) {
128152
129153 test ( `concurrency torture — ${ runs } seeded interleavings from ${ seedStart } ` , ( ) =>
130154 guard ( async ( ) => {
131- const started = Date . now ( ) ;
155+ sweepRange = { seedStart , runs } ;
132156 let totalContention = 0 ;
133- try {
134- for ( let i = 0 ; i < runs ; i += 1 ) {
135- const seed = seedStart + i ;
136- const result = await runTorture ( { seed, clients, opsPerClient } ) ;
137- totalContention += result . deviceContention ;
138- // Prove exact replay on the NORMAL sweep path (not just TORTURE_SEED):
139- // re-run the seed and assert the whole trace + outcome + contention match.
140- assertDeterministicReplay ( result , await runTorture ( { seed, clients, opsPerClient } ) ) ;
141- assertClean ( result ) ;
142- }
143- // The sweep must actually PRODUCE same-device contention — two clients
144- // parked on one device lock — or the lane is not exercising serialization
145- // and a broken lock could pass unnoticed.
146- assert . ok (
147- totalContention > 0 ,
148- 'no same-device lock contention occurred across the sweep — the lane is not testing serialization' ,
149- ) ;
150- } finally {
151- sweepRun = { seedStart, runs, durationMs : Date . now ( ) - started } ;
157+ for ( let i = 0 ; i < runs ; i += 1 ) {
158+ const seed = seedStart + i ;
159+ const result = await runTorture ( { seed, clients, opsPerClient } ) ;
160+ totalContention += result . deviceContention ;
161+ // Prove exact replay on the NORMAL sweep path (not just TORTURE_SEED):
162+ // re-run the seed and assert the whole trace + outcome + contention match.
163+ assertDeterministicReplay ( result , await runTorture ( { seed, clients, opsPerClient } ) ) ;
164+ assertClean ( result ) ;
152165 }
166+ // The sweep must actually PRODUCE same-device contention — two clients
167+ // parked on one device lock — or the lane is not exercising serialization
168+ // and a broken lock could pass unnoticed.
169+ assert . ok (
170+ totalContention > 0 ,
171+ 'no same-device lock contention occurred across the sweep — the lane is not testing serialization' ,
172+ ) ;
153173 } ) ) ;
154174
155175 // Forced same-device contention: two clients repeatedly open THE SAME pinned
0 commit comments