From cbdbc9fe5c32abed41ffc58c455d21dbb2708092 Mon Sep 17 00:00:00 2001 From: wtclaude Date: Thu, 10 Sep 2026 11:18:02 -0500 Subject: [PATCH] refactor(asset-bridge): write `from` before the page opens, not after it closes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `PageBuilder` keeps 256 bytes back for the envelope it still has to write, so a field appended after `Close()` is spent outside that reserve. It fits today by a wide margin — the largest measured page was 524,086 of a 524,288 budget, and the budget is half the line cap on purpose — but "nothing is written after Close()" is the invariant worth having, because the next family to page will copy this. No behaviour change; the field moves earlier in the same object. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016wDDVXWMDz82WqE1i969r4 --- overlay/Scripts/Custom/Bridge/BridgeCliloc.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/overlay/Scripts/Custom/Bridge/BridgeCliloc.cs b/overlay/Scripts/Custom/Bridge/BridgeCliloc.cs index 1118769..8d53b9b 100644 --- a/overlay/Scripts/Custom/Bridge/BridgeCliloc.cs +++ b/overlay/Scripts/Custom/Bridge/BridgeCliloc.cs @@ -196,9 +196,15 @@ namespace Server.Custom.Bridge .Num("total", table.Count) .Bool("compressed", table.Compressed); + // Before the page opens, not after it closes: PageBuilder reserves room for the + // envelope it still has to write, and a field appended past Close() is spent outside + // that reserve. It fits today by a wide margin, and it is the kind of thing the next + // family copies. + int start = table.IndexAfter(after); + sb.Num("from", start); + var page = new BridgeAssets.PageBuilder(sb, "rows", BridgeConfig.AssetBatchBytes); - int start = table.IndexAfter(after); int i = start; for (; i < table.Count; i++) @@ -219,7 +225,6 @@ namespace Server.Custom.Bridge bool finished = i >= table.Count; - sb.Num("from", start); BridgeLink.Emit(sb.End()); // The last page is also the end of the import, so let the strings go. A retry of that