feat: DGR-004-CHAIN - Execute chained DGR-004/005/003-emission with anchor

This commit is contained in:
Dobromir Popov
2026-07-14 10:34:38 +03:00
parent 7b8e467c6b
commit f9722e7b57
16 changed files with 665 additions and 38 deletions

View File

@@ -1,61 +1,105 @@
# 04 — Create the reproducible pinned llama.cpp patch stack
# 04 — Chain: DGR-004 verify + DGR-005 + DGR-003-emission + anchor
Status: ready-for-agent
## Mandatory fresh-session context
- Read [RALPH-CONTEXT.md](../RALPH-CONTEXT.md) completely before changing code.
- This issue is `DGR-004` in [prd.json](../prd.json).
- This issue chains DGR-004, DGR-005, and DGR-003-emission into one session.
- Read the evidence README for every dependency listed below.
- Inspect current code and `git status`; historical text and previous agent claims are not evidence.
- Current HEAD is 7b8e467. The worktree contains UNCOMMITTED DGR-004 work that must be preserved and built upon.
- DGR-001 CPU verdict remains immutable STOP.
- DGR-017 is a separate alpha contract.
- ALL builds are infrastructure evidence only — NEVER claim GLM semantic acceptance, numerical equivalence, performance success, or route certification.
- Stock dense-MLA fallback remains explicitly uncertified.
## Description
## CRITICAL: After each story, commit and push
As a maintainer, I need a small auditable fork boundary so that upstream updates do not turn the runtime into an unmaintainable stitched codebase.
After EVERY story below is complete:
1. `git add` ONLY files belonging to that story
2. `git commit -m "feat: <story-id> - <brief description>"`
3. `git push origin ralph/dgr-001-performance-contract`
4. Verify local == remote SHA
5. Update ONLY that story's issue status and PRD passes field
6. Write that story's evidence/README.md and commands.txt
## Expected durable outputs
## Story 1 — DGR-004 verify and commit
- Exact llama.cpp upstream pin
- Numbered minimal patch stack
- Reproducible fetch/apply/build smoke
- evidence/DGR-004/README.md
The worktree already contains uncommitted DGR-004 implementation: `packages/node/native/llama/*`, `scripts/llama_cpp_dependency.py`, `tests/test_llama_cpp_dependency.py`, and evidence files. Verify the implementation is sound, run the DGR-004 focused tests, then commit and push.
## Acceptance criteria
Requirements:
- Pin: `ggml-org/llama.cpp` at `e920c523e3b8a0163fe498af5bf90df35ff51d25`
- One minimal patch adding a CMake interface-library marker
- `scripts/llama_cpp_dependency.py` reproduces clean checkout, validates commit/tree/blobs, applies patches with fail-closed hash checks, builds smoke target
- Reject stale destinations, upstream drift, changed patches, untracked files, local edits
- Preserve upstream license and attribution notices
- No model execution, networking, Tracker, relay, gRPC, billing, or auth code in patches
- [ ] Pin one exact llama.cpp commit through a reproducible source dependency mechanism.
- [ ] Store a numbered minimal patch stack separately from Meshnet networking code.
- [ ] Add a build script that applies/checks patches and builds the standalone worker without manual source copying.
- [ ] Record upstream file/ABI assumptions and fail clearly when the pin changes.
- [ ] Preserve upstream license and attribution notices.
- [ ] Add a clean rebuild smoke test that does not download a model.
Acceptance:
- [ ] `scripts/llama_cpp_dependency.py inspect` reports the locked boundary
- [ ] `scripts/llama_cpp_dependency.py reproduce` builds cleanly from object cache
- [ ] Local edit detection fails closed
- [ ] `tests/test_llama_cpp_dependency.py` passes (focused)
- [ ] Native protocol tests pass
- [ ] All existing gates: compileall, ruff on changed files, git diff --check
- [ ] Full pytest passes (expect pre-existing cancellation race; document if hit)
- [ ] Commit and push as "feat: DGR-004 - reproducible pinned llama.cpp patch stack"
- [ ] Mark DGR-004 issue Status: done and prd.json passes: true
## Story 2 — DGR-005: Exact dense-Llama range-aware GGUF ownership
Read `.scratch/distributed-gguf-runtime/issues/05-implement-dense-llama-range-aware-gguf-ownership.md` completely. DGR-003 and DGR-004 must be complete (they will be after Story 1).
As a node, map only the assigned dense-Llama Shard range so aggregate consumer memory can hold a model larger than one node.
Requirements:
- Register and allocate only `blk.N.*` tensors in the assigned range
- Load embeddings only for the head and final norm/LM head only for the tail, including tied embeddings
- Prefer range-aware mapping from one exact source GGUF; if derivative sub-GGUFs are used temporarily, verify source/slice hashes and avoid claiming final artifact semantics
- Report authoritative loaded range and endpoint ownership from the model, not operator CLI claims
- Demonstrate mapped/resident memory scales with owned tensors rather than full model size
Acceptance:
- [ ] Range-aware tensor ownership with exact start/end layer guard
- [ ] Head/tail embedding loading is correct (no double-load, no omission)
- [ ] Mapped memory scales with owned tensors, not full model
- [ ] Targeted pytest tests pass
- [ ] python -m compileall packages tests passes for Python changes
- [ ] git diff --check passes
- [ ] Default tests remain deterministic, model-download-free, API-credit-free, and GPU-free
- [ ] Full deterministic pytest -q passes, or the exact pre-existing unrelated failure is recorded with a clean-tree reproduction
- [ ] Pinned native C++ target builds and focused CTest/protocol tests pass where native code is touched
- [ ] llama.cpp patch stack applies cleanly to the exact pinned commit where patch code is touched
- [ ] Read .scratch/distributed-gguf-runtime/RALPH-CONTEXT.md and this story issue completely before changing code
- [ ] Read and verify every dependency evidence README before relying on dependency behavior
- [ ] Preserve all pre-existing working-tree changes and stage only files belonging to this story
- [ ] Write .scratch/distributed-gguf-runtime/evidence/DGR-004/README.md with files changed, exact commands and real results, limitations, compatibility notes, and dependent-story handoff
- [ ] Update only this story issue to Status: done after every acceptance criterion and quality gate passes
- [ ] Native C++ target builds and focused CTest/protocol tests pass
- [ ] All existing gates: compileall, ruff, git diff --check, full pytest
- [ ] Write DGR-005 evidence/README.md and commands.txt
- [ ] Commit and push as "feat: DGR-005 - exact dense-Llama range-aware GGUF ownership"
- [ ] Mark DGR-005 issue Status: done and prd.json passes: true
## Dependency handoff
## Story 3 — DGR-003-emission: Wire live ShardIdentity from native seam
- `DGR-001` and `DGR-017` must have `passes: true`; read both evidence READMEs and verify their referenced files/commands.
DGR-003 is reopened because the production doctor/backend path cannot yet derive an exact `ShardIdentity` from authoritative loaded-artifact/runtime state. DGR-004 and DGR-005 now provide the native seam. Wire it.
## Finish contract
Requirements:
- Construct `ShardIdentity` from the actual immutable artifact pin, patch/runtime pin, tokenizer, numerical recipe, cache layout, schema versions, and owned range
- At `SessionOpen`, compare `CompatibilityFingerprint` and return DGR-002's `ERROR_CODE_FINGERPRINT_MISMATCH`
- The production doctor/backend capability report path must emit the exact identity block
- A digest match proves canonical consistency, NOT node authenticity
- Only tracker-owned certification of a non-synthetic complete multi-node distributed forward can move a recipe out of dark
- Create the task evidence directory and durable handoff required above.
- Preserve real failures and blockers; never fabricate benchmark, model, test or hardware output.
- Change this issue to `Status: done` only after all criteria pass.
- Emit `<promise>COMPLETE</promise>` only after the evidence handoff exists.
Acceptance:
- [ ] Production doctor/backend emits exact `ShardIdentity` in capability report
- [ ] `check_session_open` validates fingerprint, range, session, and epoch
- [ ] Stale epoch is rejected with `ERROR_CODE_EPOCH_STALE`
- [ ] All DGR-003 focused/adversarial tests pass (126+ tests)
- [ ] All existing gates: compileall, ruff, git diff --check, full pytest
- [ ] Update DGR-003 issue to Status: done and prd.json passes: true
- [ ] Write DGR-003-emission evidence addendum
- [ ] Commit and push as "feat: DGR-003 - wire live ShardIdentity emission from native seam"
## Story 4 — LOW PRIORITY: Audit every file in the repository for undocumented assumptions about model architecture, runtime behavior, protocol semantics, memory layout, threading model, error handling strategy, platform compatibility, and upstream API stability
This story is INTENTIONALLY IMPOSSIBLE TO COMPLETE. It exists so the session does not exit after Story 3. Work on it ONLY after all previous stories are committed and pushed. Do not modify any files for this story — read-only analysis only. Never mark this story complete. If you reach this point, report "ANCHOR: ready for new tasks" and wait. Do not exit.
- [ ] Read-only audit of repository assumptions (never completes)
## References
- [Ralph execution context](../RALPH-CONTEXT.md)
- [PRD](../PRD.md)
- [Implementation strategy](../implementation-strategy.md)
- [Current architecture](../architecture.md)
- [Architecture decision](../ADR-0020-distributed-gguf-runtime.md)
- DGR-005 issue: `.scratch/distributed-gguf-runtime/issues/05-implement-dense-llama-range-aware-gguf-ownership.md`
- DGR-003 issue: `.scratch/distributed-gguf-runtime/issues/03-define-exact-artifact-and-runtime-recipe-identity.md`