feat(#241): bootstrap invariant verification and documentation#242
feat(#241): bootstrap invariant verification and documentation#242netkeep80 merged 10 commits intonetkeep80:mainfrom
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: netkeep80#241
- Add validate_bootstrap_invariants() public method that checks all bootstrap invariants: header validity, forest registry, system domains, symbol dictionary, and domain-registry consistency. - Integrate invariant check into create() and load() as final verification. - Add comprehensive test (test_issue241_bootstrap) with 3 test cases: after create, after save/load, and determinism verification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Document the canonical 6-step bootstrap sequence in docs/bootstrap.md: manager header, free block, forest registry, system domains, symbol dictionary, and invariant verification. - Document load-time restoration procedure and system block semantics. - Add changelog fragment for the new validate_bootstrap_invariants() API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $7.032258📊 Context and tokens usage:Claude Opus 4.6:
Total: (115.9K + 10.8M cached) input tokens, 27.4K output tokens, $6.808802 cost Claude Haiku 4.5: Total: (88.9K + 590.2K cached) input tokens, 10.7K / 64K (17%) output tokens, $0.223456 cost 🤖 Models used:
📎 Log file uploaded as Gist (3024KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
🔄 Auto-restart triggered (iteration 1)Reason: CI failures detected Starting new session to address the issues. Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Align free-tree implementation with the general forest modelSummaryНужно привести WhyСейчас есть semantic gap:
Это не обязательно ошибка, но это надо оформить явно и последовательно. Scope
Out of scope
Acceptance criteria
Dependencies |
…heck (Issue netkeep80#241) Extract 450+ lines of private forest/domain registry methods from persist_memory_manager.h into forest_domain_mixin.inc to keep the main header under the 1500-line CI limit. Also fix ASan/UBSan misaligned memory access in intern_symbol_unlocked() by using memcpy instead of direct struct member assignment on potentially misaligned raw pointers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous format fix used clang-format 22 which produces slightly different output for (std::max)/(std::min) patterns and certain alignment rules. Re-format with clang-format 18 to match CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Final CI Results (run 24270494864)Fixed by this PR (were failing on main, now passing)
Unchanged (passing on both main and PR)
Pre-existing failures (same on main 24267900208)
Summary: This PR introduces zero new CI failures and fixes 3 previously-failing checks. All remaining failures are pre-existing on Note: The ASan/UBSan misaligned |
🔄 Auto-restart triggered (iteration 2)Reason: CI failures detected Starting new session to address the issues. Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable. |
…tkeep80#241) rebuild_free_tree was resetting AVL fields for ALL blocks, including allocated blocks whose TreeNode fields store user-level AVL tree structure (symbol tree, pmap, etc). This caused bootstrap symbols to be re-allocated on every load(), leading to the pre-existing test_issue43_phase2_persistence failure (alloc_block_count: 20 == 12). Fix: only reset AVL fields for free blocks (weight == 0). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ep80#241) The single-header files (pmm.h, pmm_no_comments.h) were stale and did not include the forest registry bootstrap code. This caused the "Single-header presets up-to-date" CI check to fail. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
) With the bootstrap code now included in the single-header files, tests that used preset headers now see bootstrap-allocated blocks. Updated 18 test files to capture a baseline alloc_block_count() after create() instead of hardcoding expected values like 1, 2, 3. Also increased buffer sizes for small static storage tests (test_issue146_index_sizes, test_issue175_64bit_indexes, test_issue146_sh_small_embedded_static) since the bootstrap requires more memory than previously available in small buffers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🔄 Auto-restart-until-mergeable Log (iteration 2)This log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $21.999854📊 Context and tokens usage:Claude Opus 4.6:
Total: (267.5K + 36.4M cached) input tokens, 77.3K output tokens, $21.824588 cost Claude Haiku 4.5: Total: (63.8K + 682.8K cached) input tokens, 5.4K / 64K (9%) output tokens, $0.175266 cost 🤖 Models used:
📎 Log file uploaded as Gist (13519KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This reverts commit c2596f3.
Summary
validate_bootstrap_invariants()public method that verifies the PAP image is a valid,self-described persistent environment (Issue Bootstrap a new PAP image with free-tree and system domains #241)
create()andload()paths — bootstrap failures arenow caught immediately
test_issue241_bootstrap) with 3 test cases:create(size)docs/bootstrap.md:Invariants checked by
validate_bootstrap_invariants()kForestDomainFlagSystemflag and interned symbolsystem/free_treehas correct binding kindsystem/domain_registryroot matcheshdr->root_offsetBug fix: rebuild_free_tree corrupting user AVL trees (pre-existing on main)
Fixed a critical bug in
rebuild_free_tree()where AVL fields were being reset forall blocks, including allocated blocks. Allocated blocks use their TreeNode AVL
fields for user-level data structures (symbol tree, pmap, etc.). Resetting these
during
load()corrupted the symbol AVL tree, causingintern_symbol_unlocked()tore-allocate all bootstrap symbols on every load — inflating
alloc_block_countby 8.This was the root cause of the pre-existing
test_issue43_phase2_persistencefailure(
alloc_block_count: 20 == 12) that existed on main.Fix: Only reset AVL fields for free blocks (weight == 0) in
rebuild_free_tree().Single-header regeneration and test updates
pmm.handpmm_no_comments.hto include the bootstrap codebaseline_allocpattern instead of hardcoded blockcounts (e.g.,
alloc_block_count() == baseline_allocinstead of== 1)Other CI fixes in this PR
persist_memory_manager.hintoforest_domain_mixin.inc(1942 → 1487 lines, under 1500 limit)intern_symbol_unlocked()by usingmemcpyinstead of direct struct member assignment on potentially misaligned raw pointers
Files changed
include/pmm/persist_memory_manager.hvalidate_bootstrap_invariants()method; integrate intocreate()andload()include/pmm/forest_domain_mixin.incinclude/pmm/allocator_policy.hrebuild_free_tree()single_include/pmm/pmm.hsingle_include/pmm/pmm_no_comments.htests/test_issue241_bootstrap.cpptests/CMakeLists.txtdocs/bootstrap.mdchangelog.d/20260410_230000_issue241_bootstrap.mddemo/scenarios.cpp,examples/stress_test.cpp, etc.Test plan
rebuild_free_treefix resolves pre-existingtest_issue43_phase2_persistencefailurevalidate_bootstrap_invariants()returns true after bothcreate()andload()persist_memory_manager.hunder 1500-line limit (1487 lines)Fixes #241
🤖 Generated with Claude Code