gunk-dev/the-valley

bd-c324184-occ-starvation-under-contention.md

source694235b21e19main's published tip history
4.0 KiB · Rendered
1---
2type: bug
3id: bd-c324184
4status: open
5title: Optimistic concurrency control starves under contention and foundational changes
6created: 2026-09-01
7source: knowledge base design review, 2026-09-01
8---
9
10# OCC starves under contention and foundational changes
11
12Integration 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
14and its required pure checks transfer by input-closure digest equality. When a landed change
15modifies a foundational dependency—such as `flake.lock`, root schemas, or shared libraries—it
16invalidates the input closures of all concurrently pending changes. Under high change frequency or
17multiple concurrent agents, contributors repeatedly experience check staleness and are forced to
18re-attest locally, leading to optimistic concurrency starvation (livelock).
19
20## The mechanism of starvation
21
22The integrator evaluates integration requests sequentially at the commit point
23([integration.md](../../design/integration.md)). For each pure check, it compares the input-closure
24digest recorded in the author's attestation against the input-closure digest recomputed over the
25candidate merge tree (`attest inputs`).
26
27In 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
301. The input closure for virtually every downstream derivation changes.
312. 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.
333. The integrator marks the check as stale (`request-stale`) and refuses to advance the ref.
344. 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
37If 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
45Because re-attestation happens decentralized on contributor nodes rather than in a centralized
46queue, the system exhibits classic OCC livelock under contention. If re-attestation latency exceeds
47the inter-arrival time of changes to shared dependencies, pending changes starve indefinitely.
48
49## Why this is acceptable today
50
51Today the project operates at $N=1$ human developer plus sequential agent dispatches. Changes are
52serialized before integration requests are pushed, and concurrent submissions against the same ref
53are rare. The defect is structural to the OCC design and becomes acute as soon as multiple agents
54work 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)