Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
20 changes: 11 additions & 9 deletions packages/runtime/container-runtime/src/opLifecycle/outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class Outbox {

// If we're configured to flush partial batches, do that now and return (don't throw)
if (this.params.config.flushPartialBatches) {
this.flushAll();
this.flush();
return;
}

Expand Down Expand Up @@ -365,14 +365,6 @@ export class Outbox {
* @param resubmitInfo - Key information when flushing a resubmitted batch. Undefined means this is not resubmit.
*/
public flush(resubmitInfo?: BatchResubmitInfo): void {
assert(
!this.isContextReentrant(),
0xb7b /* Flushing must not happen while incoming changes are being processed */,
);
this.flushAll(resubmitInfo);
}

private flushAll(resubmitInfo?: BatchResubmitInfo): void {
const allBatchesEmpty =
this.idAllocationBatch.empty && this.blobAttachBatch.empty && this.mainBatch.empty;
if (allBatchesEmpty) {
Expand All @@ -387,6 +379,11 @@ export class Outbox {
return;
}

assert(
!this.isContextReentrant(),
0xb7b /* Flushing must not happen while incoming changes are being processed */,
);

// Don't use resubmittingBatchId for idAllocationBatch.
// ID Allocation messages are not directly resubmitted so don't pass the resubmitInfo
this.flushInternal({
Expand All @@ -409,6 +406,11 @@ export class Outbox {
resubmittingBatchId: BatchId,
resubmittingStagedBatch: boolean,
): void {
assert(
!this.isContextReentrant(),
"Flushing must not happen while incoming changes are being processed",
);
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New assert added with string literal message instead of hex code. Per coding guidelines (CodingGuidelineID: 1000000), asserts from @fluidframework/core-utils should use string literals for error messages, not hex codes. This is correctly implemented here.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really need to remove this copilot instruction. it is always wrong


const referenceSequenceNumber =
this.params.getCurrentSequenceNumbers().referenceSequenceNumber;
assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
ISequencedDocumentMessage,
} from "@fluidframework/driver-definitions/internal";
import { MockLogger } from "@fluidframework/telemetry-utils/internal";
import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";

import type { ICompressionRuntimeOptions } from "../../compressionDefinitions.js";
import { CompressionAlgorithms } from "../../compressionDefinitions.js";
Expand Down Expand Up @@ -1092,6 +1093,57 @@ describe("Outbox", () => {
assert.strictEqual(state.opsResubmitted, opsResubmitted, "unexpected opsResubmitted");
}

it("should not assert when flushing while reentrant with empty batches", () => {
const outbox = getOutbox({
context: getMockContext(),
opGroupingConfig: {
groupedBatchingEnabled: true,
},
});

// Mark context as reentrant
state.isReentrant = true;

// Flush with no messages - should not throw
assert.doesNotThrow(() => {
outbox.flush();
}, "Should not assert when flushing empty batches while reentrant");

validateCounts(0, 0, 0);
});

it("should assert when flushing while reentrant with non-empty batches", () => {
const outbox = getOutbox({
context: getMockContext(),
opGroupingConfig: {
groupedBatchingEnabled: true,
},
});

const messages = [createMessage(ContainerMessageType.FluidDataStoreOp, "0")];

// Submit a message (not reentrant)
state.isReentrant = false;
outbox.submit(messages[0]);

// Now mark context as reentrant and try to flush - should throw
state.isReentrant = true;

assert.throws(
() => outbox.flush(),
(error: Error) => {
return validateAssertionError(
error,
"Flushing must not happen while incoming changes are being processed",
);
},
"Should assert when flushing non-empty batches while reentrant",
);

// Verify nothing was submitted
validateCounts(0, 0, 0);
});

it("batch has reentrant ops, but grouped batching is off", () => {
const outbox = getOutbox({
context: getMockContext(),
Expand Down
Loading