refactor(asset-bridge): write from before the page opens, not after it closes

`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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wDDVXWMDz82WqE1i969r4
This commit is contained in:
2026-09-10 11:18:02 -05:00
parent 73b07eed22
commit cbdbc9fe5c

View File

@@ -196,9 +196,15 @@ namespace Server.Custom.Bridge
.Num("total", table.Count) .Num("total", table.Count)
.Bool("compressed", table.Compressed); .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); var page = new BridgeAssets.PageBuilder(sb, "rows", BridgeConfig.AssetBatchBytes);
int start = table.IndexAfter(after);
int i = start; int i = start;
for (; i < table.Count; i++) for (; i < table.Count; i++)
@@ -219,7 +225,6 @@ namespace Server.Custom.Bridge
bool finished = i >= table.Count; bool finished = i >= table.Count;
sb.Num("from", start);
BridgeLink.Emit(sb.End()); BridgeLink.Emit(sb.End());
// The last page is also the end of the import, so let the strings go. A retry of that // The last page is also the end of the import, so let the strings go. A retry of that