| 1 | --- |
| 2 | type: bug |
| 3 | id: bd-c324184 |
| 4 | status: open |
| 5 | title: Optimistic concurrency control starves under contention and foundational changes |
| 6 | created: 2026-09-01 |
| 7 | source: knowledge base design review, 2026-09-01 |
| 8 | --- |
| 9 | |
| 10 | # OCC starves under contention and foundational changes |
| 11 | |
| 12 | Integration uses optimistic concurrency control (OCC) over content-addressed evidence |
| 13 | ([[dcr-439b771]]). A change lands without running checks on the server if the change merges cleanly |
| 14 | and its required pure checks transfer by input-closure digest equality. When a landed change |
| 15 | modifies a foundational dependency—such as `flake.lock`, root schemas, or shared libraries—it |
| 16 | invalidates the input closures of all concurrently pending changes. Under high change frequency or |
| 17 | multiple concurrent agents, contributors repeatedly experience check staleness and are forced to |
| 18 | re-attest locally, leading to optimistic concurrency starvation (livelock). |
| 19 | |
| 20 | ## The mechanism of starvation |
| 21 | |
| 22 | The integrator evaluates integration requests sequentially at the commit point |
| 23 | ([integration.md](../../design/integration.md)). For each pure check, it compares the input-closure |
| 24 | digest recorded in the author's attestation against the input-closure digest recomputed over the |
| 25 | candidate merge tree (`attest inputs`). |
| 26 | |
| 27 | In a Nix-native repository, input closures are deep and sensitive. When a foundational file like |
| 28 | `flake.lock` or a common build helper is modified: |
| 29 | |
| 30 | 1. The input closure for virtually every downstream derivation changes. |
| 31 | 2. Even if a pending change has zero syntactic merge conflict with the new tip, its recomputed |
| 32 | closure digest diverges from the attested closure digest. |
| 33 | 3. The integrator marks the check as stale (`request-stale`) and refuses to advance the ref. |
| 34 | 4. The contributor or agent must re-run the check locally over the new tip, sign a new attestation, |
| 35 | and file a new integration request. |
| 36 | |
| 37 | If several contributors or automated agents submit changes during an active development window: |
| 38 | |
| 39 | - Agent A's change lands, advancing `main`. |
| 40 | - Agents B, C, and D are marked stale. |
| 41 | - Agents B, C, and D pull the new tip and begin local re-attestation. |
| 42 | - Agent B finishes first and lands. |
| 43 | - Agents C and D have their newly computed attestations invalidated again before they can land. |
| 44 | |
| 45 | Because re-attestation happens decentralized on contributor nodes rather than in a centralized |
| 46 | queue, the system exhibits classic OCC livelock under contention. If re-attestation latency exceeds |
| 47 | the inter-arrival time of changes to shared dependencies, pending changes starve indefinitely. |
| 48 | |
| 49 | ## Why this is acceptable today |
| 50 | |
| 51 | Today the project operates at $N=1$ human developer plus sequential agent dispatches. Changes are |
| 52 | serialized before integration requests are pushed, and concurrent submissions against the same ref |
| 53 | are rare. The defect is structural to the OCC design and becomes acute as soon as multiple agents |
| 54 | work concurrently or external contributors submit changes. |
| 55 | |
| 56 | ## Directions, not decisions |
| 57 | |
| 58 | - **Integrator-side batching.** The integrator merges multiple pending changes into a single |
| 59 | speculative candidate tree and evaluates whether their combined closures can be attested once. |
| 60 | - **Closure granularity and path isolation.** Split monolithic flakes and shared policy definitions |
| 61 | so that documentation, tools, and sub-projects do not include root repository locks in their input |
| 62 | closures. |
| 63 | - **Staleness reservation windows.** A request that has been invalidated repeatedly acquires an |
| 64 | exclusive reservation window on the target ref, blocking other requests from landing until its |
| 65 | re-attestation completes. |
| 66 | - **Pipelined builder backends.** Provide a shared builder cache so that author nodes re-evaluating |
| 67 | stale closures do not duplicate compilation work from scratch. |
| 68 | |
| 69 | ## Related |
| 70 | |
| 71 | - The OCC integration decision: [[dcr-439b771]] |
| 72 | ([dcr-439b771-integration-occ-over-content-addressed-evidence.md](../decisions/dcr-439b771-integration-occ-over-content-addressed-evidence.md)) |
| 73 | - Integration protocol: [integration.md](../../design/integration.md) |
| 74 | - Latency and throughput requirements: [requirements.md](../../design/requirements.md) |