Skip to content

feat(#5902): flag-gated bounded-memory SegmentedWriter (dark)#5916

Merged
cajasmota merged 3 commits into
mainfrom
worktree-agent-a8b760dac42c3644a
Jul 22, 2026
Merged

feat(#5902): flag-gated bounded-memory SegmentedWriter (dark)#5916
cajasmota merged 3 commits into
mainfrom
worktree-agent-a8b760dac42c3644a

Conversation

@cajasmota

Copy link
Copy Markdown
Owner

Part (c) of #5890. Streaming SegmentedWriter that produces the segmented format the #5901 reader already routes. FLAG-GATED via GRAFEL_STREAM_SEGMENTS (OFF by default → byte-identical to today); NO fbversion bump. Closes #5902.

  • Bounded builder: entities stream into a flatbuffers.Builder; at GRAFEL_SEGMENT_BYTES (default 100 MB) it flushes to graph.<gen>/seg-NNNN.fb, frees the builder, repeats — peak builder stays ~one threshold, fixing the bug(fbwriter): daemon hard-crashes ('panic: cannot grow buffer beyond 2 gigabytes') marshaling large graphs → severs all MCP bridges #5726 2 GiB serialize cliff (a >2 GiB graph splits instead of panicking). Relationships flush on their own cadence (decision 5).
  • Routing bounds = reader routing (no false-skip): entities sorted byte-wise (Go < == FB (key) memcmp == reader KeyRange.contains), streamed globally-sorted, cut at threshold → segments tile the id space contiguous + non-overlapping; MinKey/MaxKey = first/last id per segment. Multi-segment write→read round-trip proves every entity resolves through the routed reader.
  • Single-file fast path (decision 1): a bounded fit-probe (early-exits at threshold) → small graphs write a plain graph.<gen>.fb, byte-identical to today.
  • NextGen now scans gen dirs + files (union) so segmented writes don't collide with a prior gen dir.

Independently reviewed, mutation-proven: routing-bounds-match-reader (descending-sort / shrunk-MaxKey / overlap mutations caught), bounded-builder (retention mutation caught), single-file + flag-off byte-parity, NextGen monotonicity, edge cases (empty/single/rel-only/prefix-ids/dup-straddle). 308 + 3965 + 282 tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_017quGgaqK7NRoxGT6BTqV2o

jcajasmc added 3 commits July 22, 2026 22:50
… gate (#5902)

Bounded-builder segmented graph writer: flush a finished seg-NNNN.fb and start a fresh flatbuffers.Builder whenever the builder crosses GRAFEL_SEGMENT_BYTES (default 100MB), so peak builder memory stays ~one threshold instead of O(graph) (fixes the #5726 2GiB serialize cliff). Entity and relationship segments flush on independent cadences into separate files. Each entity segment is the contiguous sorted id slice with exact byte-wise MinKey/MaxKey bounds, so the reader's key-range routing never false-skips a present entity. Small graphs take the single-file fast path (plain graph.<gen>.fb, byte-identical to today). Flag OFF by default; gated at WriteGraphGen so every producer call site routes through one switch. No fbversion bump; readers unchanged.
@cajasmota
cajasmota merged commit a41d6a0 into main Jul 22, 2026
1 of 2 checks passed
@cajasmota
cajasmota deleted the worktree-agent-a8b760dac42c3644a branch July 22, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#5890(c): streaming SegmentedWriter with flush threshold (flag-gated)

2 participants