{
 "number": 36549,
 "input_hash": "784d0f47c74a0259",
 "model": "ledger",
 "prompt_hash": null,
 "created": "2026-10-18T01:14:41+00:00",
 "result": {
  "summary": "Replaces the generic heuristic in `memusage::MallocUsage` with allocator-specific models for glibc, musl, macOS libmalloc, and Windows heap allocators, and accounts for STL container overheads under libc++ and MSVC. Adds unit tests that measure allocator chunk spacing across allocation sizes to check `MallocUsage` accuracy. Updates functional tests (`mempool_limit.py` and `fill_mempool`) to dynamically adapt to varying malloc overhead instead of relying on hardcoded memory sizes.",
  "problem": "`memusage::MallocUsage()` relied on an outdated heuristic measured on glibc 2.19 that overestimates chunk sizes by 16 bytes for half of all requests, ignores minimum chunk sizes and mmapped thresholds, and fails to model non-glibc allocators on macOS, Windows, and musl. This leads to inaccurate dynamic memory accounting across the node (such as the mempool and UTXO cache) and broke tests when allocator overhead assumptions failed.",
  "card": "This PR replaces the heuristic in memusage::MallocUsage with platform-specific allocator models for glibc, musl, macOS libmalloc, and Windows heap allocators, while adjusting STL node overhead for libc++ and MSVC. The old formula, measured on glibc 2.19, distorted memory accounting across caches and the mempool by overestimating half of glibc allocations by 16 bytes and miscalculating on non-glibc platforms. Author verification shows exact matches across 16 architectures for glibc 2.43 and within 0.2% for musl 1.2.5. Functional tests are also updated to prevent failures from platform-dependent allocator overheads.",
  "evidence": [
   "Commit 3d35a71b3d: glibc model 'matches glibc 2.43 exactly on x86_64, i386, aarch64, armhf, armel, riscv64, ppc64, ppc64le, ppc, s390x, loongarch64, alpha, hppa, m68k, sh4 and sparc64 (over 300000 request sizes each)'",
   "Commit 3d35a71b3d: musl model 'matches RSS measurements of musl 1.2.5 within 0.2%'",
   "Commit 3d35a71b3d: macOS and Windows models were validated against CI measurements on macOS 15 (arm64) and Windows Server 2022"
  ],
  "scope_notes": "The unit test introduces custom address-gap analysis to reverse-engineer allocator slot sizes at runtime.",
  "changed_since_previous": "Adapted functional tests in `mempool_limit.py` and `test_framework/mempool_util.py` to handle dynamic allocator overheads during mempool filling and eviction, and enabled exhaustive testing of all sizes (`ALL_SIZES = true`) in `memusage_tests.cpp`.",
  "thread": {
   "last_event_at": null,
   "events": 0,
   "head_sha": "6140d4c45155987c461b928ad9e94abf714208d6",
   "schema_floor": 2,
   "schema": 2
  },
  "waiting_on": [],
  "risk": {
   "level": "medium",
   "touches": [
    "validation",
    "mempool_policy",
    "tests"
   ],
   "why": "Inaccuracies in memory usage calculations could lead to premature mempool eviction, incorrect cache flushing, or excessive memory consumption causing out-of-memory crashes."
  },
  "discussion": {
   "author_status": "no discussion",
   "open_concerns": [],
   "resolved_concerns": []
  },
  "reviewability": {
   "state": "Ready",
   "label": "Ready",
   "reason": "Nothing known that would invalidate a review now."
  },
  "agreement": {
   "state": "Crickets",
   "summary": "Crickets: no substantive comment either way",
   "reason": "Derived from the claims and support below; every entry links to the statement it came from.",
   "evidence": [],
   "objections": [],
   "support": [],
   "participants": [],
   "derivation": "no substantive comment either way",
   "model_state": null,
   "corrections": [],
   "notes": null
  },
  "dependencies": {
   "depends_on": [],
   "enables": []
  },
  "categories": [
   {
    "name": "build",
    "member": false,
    "evidence": "Changes memusage memory modeling and adds unit tests; does not modify build scripts, depends, or CI infrastructure.",
    "band": "Unranked",
    "reason_tag": "test coverage",
    "score": 0.0,
    "factors": {
     "bug_severity": 1,
     "leverage": 1,
     "performance": 1,
     "security_stability": 1,
     "user_value": 0
    },
    "rationale": "None."
   },
   {
    "name": "mempool",
    "member": false,
    "evidence": "No mempool label; main change is in src/memusage.h, while touches to test/functional/mempool_limit.py and mempool_util.py are test edits following from the memory accounting update.",
    "band": "Unranked",
    "reason_tag": "bug fix",
    "score": 0.0,
    "factors": {
     "bug_severity": 1,
     "leverage": 0,
     "performance": 1,
     "security_stability": 1,
     "user_value": 0
    },
    "rationale": "The PR addresses generic heap allocation modeling in memusage::MallocUsage rather than mempool policy or data structures directly. Edits to mempool test files merely follow the core accounting changes to prevent test failures under different allocator models."
   },
   {
    "name": "p2p",
    "member": false,
    "evidence": "No involvement with peer-to-peer networking, connection management, or message handling.",
    "band": "Unranked",
    "reason_tag": "cleanup",
    "score": 0.0,
    "factors": {
     "bug_severity": 1,
     "leverage": 1,
     "performance": 1,
     "security_stability": 1,
     "user_value": 0
    },
    "rationale": "None."
   },
   {
    "name": "tests",
    "member": false,
    "evidence": "No tests label; src/test/memusage_tests.cpp tests the memusage utility directly, and edits to test/functional/test_framework/mempool_util.py are downstream adjustments.",
    "band": "Unranked",
    "reason_tag": "test coverage",
    "score": 0.0,
    "factors": {
     "bug_severity": 1,
     "leverage": 0,
     "performance": 1,
     "security_stability": 1,
     "user_value": 0
    },
    "rationale": "The PR does not modify test framework runners, harnesses, or general testing machinery. The new tests and helper updates are specific unit and functional test adjustments pinning the behavior of memusage."
   },
   {
    "name": "utils",
    "member": true,
    "evidence": "Modifies `memusage::MallocUsage`, a shared memory accounting utility primitive used across the node.",
    "band": "P3",
    "reason_tag": "bug fix",
    "score": 0.38,
    "factors": {
     "bug_severity": 1,
     "leverage": 1,
     "performance": 1,
     "security_stability": 1,
     "user_value": 0
    },
    "rationale": "The PR replaces outdated glibc 2.19 allocation heuristics with accurate models for glibc, musl, macOS, and Windows. The commit notes explain the old logic 'overestimates the size of glibc chunks by 16 bytes for half of all request sizes' and lacked support for other platforms, skewing node memory accounting for caches and the mempool."
   }
  ],
  "confidence": "high",
  "uncertainties": [],
  "needs": []
 },
 "cost_usd": 0.0,
 "source": {
  "record": "2026-10-18T01:14:41+00:00",
  "code": "2026-10-18T01:17:05+00:00",
  "judgments": 5
 }
}