Skip to content

Commit 4b6f07e

Browse files
anthony-murphy-agentclaudeanthony-murphy
authored
Fix exitStagingMode for rehydrated containers (#16)
* Fix exitStagingMode for rehydrated containers When a container is rehydrated from pending state while in staging mode, the DataObject doesn't have stageControls (only set when enterStagingMode is called). Handle this gracefully by returning early instead of asserting. Co-Authored-By: Claude Opus 4.5 <[email protected]> Co-Authored-By: anthony-murphy <[email protected]> * Fix exitStagingMode for rehydrated containers by using loadContainerRuntimeAlpha - Use loadContainerRuntimeAlpha which returns stageControls when loading from pending state - Pass stageControls to DefaultStressDataObject via setStageControls method - Restore the assert in exitStagingMode since we now have proper stage controls - Ensures rehydrated containers can properly exit staging mode Co-Authored-By: anthony-murphy <[email protected]> Co-Authored-By: Claude Opus 4.5 <[email protected]> --------- Co-authored-by: anthony-murphy-agent <[email protected]> Co-authored-by: Claude Opus 4.5 <[email protected]> Co-authored-by: anthony-murphy <[email protected]>
1 parent 2e83ddd commit 4b6f07e

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

packages/test/local-server-stress-tests/src/stressDataObject.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "@fluidframework/container-definitions/internal";
1212
import {
1313
ContainerRuntime,
14-
loadContainerRuntime,
14+
loadContainerRuntimeAlpha,
1515
type IContainerRuntimeOptionsInternal,
1616
} from "@fluidframework/container-runtime/internal";
1717
// eslint-disable-next-line import-x/no-deprecated
@@ -301,6 +301,15 @@ export class DefaultStressDataObject extends StressDataObject {
301301

302302
private stageControls: StageControlsAlpha | undefined;
303303
private readonly containerRuntimeExp = asLegacyAlpha(this.context.containerRuntime);
304+
305+
/**
306+
* Sets the stage controls. This is called by the runtime factory when loading
307+
* from pending state that was in staging mode.
308+
*/
309+
public setStageControls(controls: StageControlsAlpha | undefined): void {
310+
this.stageControls = controls;
311+
}
312+
304313
public enterStagingMode(): void {
305314
assert(
306315
this.containerRuntimeExp.enterStagingMode !== undefined,
@@ -350,7 +359,11 @@ export const createRuntimeFactory = (): IRuntimeFactory => {
350359
return this;
351360
},
352361
instantiateRuntime: async (context, existing) => {
353-
const runtime = await loadContainerRuntime({
362+
// Capture stageControls to pass to the entrypoint after loading.
363+
// This must be inside instantiateRuntime so each container instance has its own variable.
364+
let pendingStageControls: StageControlsAlpha | undefined;
365+
366+
const { runtime, stageControls } = await loadContainerRuntimeAlpha({
354367
context,
355368
existing,
356369
runtimeOptions,
@@ -367,9 +380,22 @@ export const createRuntimeFactory = (): IRuntimeFactory => {
367380
);
368381
assert(aliasedDefault !== undefined, "default must exist");
369382

370-
return aliasedDefault.get();
383+
const entryPoint = await aliasedDefault.get();
384+
385+
// Pass the stageControls (if any) to the DefaultStressDataObject
386+
// so it can properly exit staging mode when rehydrated from pending state
387+
const maybe: FluidObject<DefaultStressDataObject> | undefined = entryPoint;
388+
if (maybe?.DefaultStressDataObject !== undefined && pendingStageControls !== undefined) {
389+
maybe.DefaultStressDataObject.setStageControls(pendingStageControls);
390+
}
391+
392+
return entryPoint;
371393
},
372394
});
395+
396+
// Store stageControls so it can be passed to entrypoint when getEntryPoint() is called
397+
pendingStageControls = stageControls;
398+
373399
// id compressor isn't made available via the interface right now.
374400
// We could revisit exposing the safe part of its API (IIdCompressor, not IIdCompressorCore) in a way
375401
// that would avoid this instanceof check, but most customers shouldn't really have a need for it.

0 commit comments

Comments
 (0)