Skip to content

Commit c9eda83

Browse files
authored
perf(apply): explicit read generations + hydration-snapshot consumption (#1161)
Quota campaign PR 2/5: apply-lane reads now live inside explicit per-item read generations, and apply finally consumes the persisted PR hydration snapshot. Every accepted or ambiguous GitHub mutation (lease, label, durable-comment, placeholder, recovery-label, close) advances the generation and discards bound context - reuse across a mutation boundary is impossible by construction, not by discipline. The irreducible safety floor is untouched and explicitly cache-bypassing: the two-sided lease check and the final proof/comment/close guards always read live (proven: concurrent head change and concurrent comment fixtures both still block apply with a warm generation). Snapshot consumption (v3): after validating live head, updated_at, counts, and just-in-time activity-revision agreement, apply reads pull files, commits, and inline comments from the persisted snapshot - all three list reads drop to zero for validated snapshots (v2 snapshots already covered commits/comments; v3 adds files). Mismatch means full hydration, same fail-closed contract as the review lane. Counted apply flow: 14 -> 9 GitHub requests with the live lease floor (2 pull reads + 1 comment read) preserved. Targets the repository_actions item_metadata (99k cumulative) and comments (75k) classes per the 2026-08-14 analysis. Proof: loopback call counting, safety fixtures, full gate 3435/0 + dashboard-strict, Crabbox local-container receipt at this exact head, machine-verified SHA provenance. Verdict clean (no actionable findings, proof: sufficient) on 321fdad.
1 parent 82d9ba9 commit c9eda83

22 files changed

Lines changed: 1459 additions & 126 deletions
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Apply read generations proof
2+
3+
- Status: historical proof artifact
4+
- Owner: ClawSweeper publication maintainers
5+
- Tested source: `openclaw/clawsweeper@82d9a3b14961793d13f3d0b113078eb84e4caf00`
6+
- Update when: apply generation keys, mutation observation, lease/proof barriers, or PR hydration watermarks change
7+
8+
## Claim and exercised surface
9+
10+
The controlled loopback exercises the production `LiveReadGeneration`, apply
11+
guard memoization, two-sided lease guard, and PR hydration coordinator through
12+
real HTTP endpoints. Identical fetch/context/policy reads share one value only
13+
inside a generation. An observed GitHub mutation advances the generation,
14+
clears its entries, and makes a previously bound context fail a runtime
15+
generation assertion.
16+
17+
The pre-comment and pre-close lease barriers deliberately bypass a warm
18+
generation. Each barrier therefore performs two live pull-head reads around one
19+
live complete comment-list read. Fixtures advance the generation after a
20+
concurrent head change and after a new durable comment; both cases block apply.
21+
22+
Apply parses the persisted PR hydration snapshot from report front matter and
23+
validates the live head SHA, `updated_at`, file/commit/inline-comment counts,
24+
and the just-in-time activity revision before reuse. Existing v2 snapshots can
25+
reuse commits and inline comments while reading their missing file window.
26+
Current v3 snapshots also retain that bounded file window, so a validated v3
27+
hit performs zero pull-file, commit, or inline-comment list reads. Any mismatch
28+
uses the normal full list path.
29+
30+
OpenClaw Bay is unaffected. This changes internal publication reads and
31+
cache-only report metadata, not Bay's observer contract or action boundary.
32+
33+
## Generation and invalidation inventory
34+
35+
| Event | Generation behavior | Covered mutation surfaces |
36+
| --- | --- | --- |
37+
| Apply starts one item | Create one generation and bind guard reads to it | item fetch, context hydration, policy guards |
38+
| Mutation runner reports accepted | Advance generation and discard bound context | lease post/delete, label definition/item labels, durable comment post/patch, placeholder delete, recovery label removal, close comment, item close |
39+
| Mutation runner reports ambiguous outcome | Advance generation before propagating the error | every observed GitHub write attempt whose non-mutation cannot be proven |
40+
| Mutation runner reports rejected/no-op | Preserve generation | guard rejection and explicitly known no-mutation errors only |
41+
| Final proof, comment, or close guard | Bypass generation cache | final `fetchItem`/context freshness and low-signal policy checks |
42+
| Two-sided lease verification | Bypass generation cache | head/source, comments, head/source |
43+
44+
## Counted formula and safety result
45+
46+
For the representative apply slice, `F` is the first item fetch, `C` context
47+
hydration, `P` policy reads, `L` the irreducible lease barrier, and `U` the six
48+
unique generation reads:
49+
50+
```text
51+
before = F(1) + C(4) + P(6) + L(3) = 14
52+
after = U(6) + L_live(3) = 9
53+
```
54+
55+
The `L(3)` floor is unchanged. With the generation already warm, both the
56+
pre-comment and pre-close barriers still recorded two `/pull` requests and one
57+
`/comments` request. Concurrent head and comment changes were both rejected.
58+
A validated v3 snapshot recorded files=0, commits=0, inline-comments=0.
59+
60+
## Environment and commands
61+
62+
The exact source passed the complete host gate on Node 24.19.0:
63+
64+
```bash
65+
pnpm run check
66+
```
67+
68+
Result: 3,444 tests, 3,435 passed, 9 platform skips, 0 failures. Coverage was
69+
81.57% lines, 74.01% branches, and 87.39% functions. Static checks included
70+
`check:dashboard-strict`, docs, limits, formatting, all TypeScript builds, and
71+
all linters.
72+
73+
The deterministic transport proof ran through Crabbox's explicitly requested
74+
Docker-backed `local-container` provider on Ubuntu 26.04/arm64 with Node
75+
24.19.0 and pnpm 11.10.0. The successful fresh-PR lease was
76+
`cbx_0241049e673e` (`golden-barnacle-01a8`) and stopped automatically.
77+
78+
```bash
79+
proof_source_head="$(git rev-parse HEAD)"
80+
proof_source_tree="$(git rev-parse 'HEAD^{tree}')"
81+
git cat-file -e "${proof_source_head}^{commit}"
82+
git cat-file -e "${proof_source_tree}^{tree}"
83+
PROOF_SOURCE_HEAD="$proof_source_head" PROOF_SOURCE_TREE="$proof_source_tree" \
84+
/Users/steipete/Projects/crabbox/bin/crabbox run \
85+
--provider local-container \
86+
--fresh-pr openclaw/clawsweeper#1161 \
87+
--no-hydrate \
88+
--allow-env PROOF_SOURCE_HEAD,PROOF_SOURCE_TREE \
89+
--preflight --timing-json --ttl 30m --shell -- \
90+
"awk '/^echo CRABBOX_PHASE:check$/{exit} {print}' scripts/e2e/run-apply-read-generations-container.sh | bash"
91+
```
92+
93+
The successful receipt covers the checked-in toolchain, all three builds,
94+
source identity, and loopback behavior phases. A separate Linux full-gate
95+
attempt reached the repository workflow fixtures but those macOS-authored
96+
cursor-trace fixtures reject Linux filesystem metadata; the exact same complete
97+
gate is green on the required Node 24 host. No product assertion relies on that
98+
platform-specific shard.
99+
100+
## Static verification recipe
101+
102+
Run from the repository root. The final diff check permits only this proof
103+
directory after the tested source commit.
104+
105+
```bash
106+
receipt="docs/proof/apply-read-generations/receipt.json"
107+
jq -e '
108+
.schema_version == 1 and
109+
.crabbox.provider == "local-container" and
110+
.crabbox.runtime == "docker" and
111+
.crabbox.exit_code == 0 and
112+
.crabbox.run_status == "succeeded" and
113+
.crabbox.lease_stopped == true and
114+
.requests.before == 14 and
115+
.requests.after == 9 and
116+
.requests.barrier == {"pull": 2, "comments": 1} and
117+
.requests.validated_snapshot == {"files": 0, "commits": 0, "inline_comments": 0} and
118+
.assertions.concurrent_head_blocked == true and
119+
.assertions.concurrent_comment_blocked == true and
120+
.assertions.generation_bound_value_rejected == true and
121+
.full_gate.dashboard_strict == true and
122+
.full_gate.fail == 0
123+
' "$receipt"
124+
tested_head="$(jq -r '.source.head' "$receipt")"
125+
tested_tree="$(jq -r '.source.tree' "$receipt")"
126+
git cat-file -e "${tested_head}^{commit}"
127+
git cat-file -e "${tested_tree}^{tree}"
128+
test "$(git rev-parse "${tested_head}^{tree}")" = "$tested_tree"
129+
test -z "$(git diff --name-only "$tested_head"..HEAD -- . \
130+
':(exclude)docs/proof/apply-read-generations/**')"
131+
```
132+
133+
## Limits
134+
135+
The behavior fixture uses deterministic loopback endpoints, not live target
136+
mutations. It proves request ownership, invalidation, barrier transport, and
137+
race decisions; it does not claim production latency. v2 records cannot avoid
138+
the one file-list read because that schema did not persist files. No Worker,
139+
dashboard, queue, or target repository state was mutated by the proof.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"schema_version": 1,
3+
"recorded_at": "2026-08-14T04:48:48Z",
4+
"claim": "Apply reuses identical GitHub reads only within one mutation-bounded generation while preserving live final barriers and validated snapshot safety.",
5+
"source": {
6+
"head": "82d9a3b14961793d13f3d0b113078eb84e4caf00",
7+
"tree": "feb92bdcd220ed054fe9a73e1615bb327802d0d5",
8+
"commit_object_verified": true,
9+
"tree_object_verified": true,
10+
"pull_request": 1161
11+
},
12+
"crabbox": {
13+
"provider": "local-container",
14+
"lease_id": "cbx_0241049e673e",
15+
"slug": "golden-barnacle-01a8",
16+
"runtime": "docker",
17+
"image": "ubuntu:26.04",
18+
"architecture": "arm64",
19+
"node": "v24.19.0",
20+
"pnpm": "11.10.0",
21+
"exit_code": 0,
22+
"run_status": "succeeded",
23+
"lease_stopped": true,
24+
"sync_ms": 13856,
25+
"command_ms": 11421,
26+
"total_ms": 25278
27+
},
28+
"transport": "loopback HTTP from a Crabbox fresh-PR checkout",
29+
"requests": {
30+
"formula_before": "F(1)+C(4)+P(6)+L(3)=14",
31+
"formula_after": "U(6)+L_live(3)=9",
32+
"before": 14,
33+
"after": 9,
34+
"barrier": {
35+
"pull": 2,
36+
"comments": 1
37+
},
38+
"validated_snapshot": {
39+
"files": 0,
40+
"commits": 0,
41+
"inline_comments": 0
42+
}
43+
},
44+
"assertions": {
45+
"generation_bound_value_rejected": true,
46+
"mutation_advances_generation": true,
47+
"barriers_bypass_warm_generation": true,
48+
"concurrent_head_blocked": true,
49+
"concurrent_comment_blocked": true,
50+
"snapshot_mismatch_full_fallback": true,
51+
"v2_snapshot_compatibility": true
52+
},
53+
"full_gate": {
54+
"environment": "macOS host, Node v24.19.0, pnpm 11.10.0",
55+
"command": "pnpm run check",
56+
"tests": 3444,
57+
"pass": 3435,
58+
"fail": 0,
59+
"skip": 9,
60+
"coverage_lines_percent": 81.57,
61+
"coverage_branches_percent": 74.01,
62+
"coverage_functions_percent": 87.39,
63+
"dashboard_strict": true,
64+
"docs": true,
65+
"format": true,
66+
"lint": true,
67+
"build_all": true
68+
},
69+
"limits": [
70+
"The behavior proof uses deterministic loopback GitHub endpoints rather than live target mutations.",
71+
"Persisted v2 snapshots still require one pull-file list read because v2 did not contain files.",
72+
"The successful Crabbox receipt covers toolchain, build, source identity, and behavior proof; the exact-source complete gate is recorded separately because Linux cursor-trace fixtures reject Linux filesystem metadata.",
73+
"The receipt source commit is followed only by this proof package; the verification recipe rejects intervening non-proof changes."
74+
]
75+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import http from "node:http";
2+
3+
const reviewedHead = "a".repeat(40);
4+
const state = {
5+
head: reviewedHead,
6+
comments: [],
7+
counts: {},
8+
};
9+
10+
function count(path) {
11+
state.counts[path] = (state.counts[path] ?? 0) + 1;
12+
}
13+
14+
function json(response, status, value) {
15+
response.writeHead(status, { "content-type": "application/json" });
16+
response.end(`${JSON.stringify(value)}\n`);
17+
}
18+
19+
const server = http.createServer((request, response) => {
20+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
21+
if (request.method === "POST") {
22+
let body = "";
23+
request.setEncoding("utf8");
24+
request.on("data", (chunk) => {
25+
body += chunk;
26+
});
27+
request.on("end", () => {
28+
if (url.pathname === "/reset") {
29+
state.head = reviewedHead;
30+
state.comments = [];
31+
state.counts = {};
32+
return json(response, 200, { ok: true });
33+
}
34+
if (url.pathname === "/mutate") {
35+
const mutation = JSON.parse(body || "{}");
36+
if (typeof mutation.head === "string") state.head = mutation.head;
37+
if (Array.isArray(mutation.comments)) state.comments = mutation.comments;
38+
return json(response, 200, { ok: true });
39+
}
40+
return json(response, 404, { error: "not found" });
41+
});
42+
return;
43+
}
44+
45+
if (url.pathname === "/counts") return json(response, 200, state.counts);
46+
count(url.pathname);
47+
if (url.pathname === "/issue") {
48+
return json(response, 200, {
49+
number: 42,
50+
title: "Generation proof",
51+
state: "open",
52+
comments: state.comments.length,
53+
});
54+
}
55+
if (url.pathname === "/pull") {
56+
return json(response, 200, {
57+
number: 42,
58+
updated_at: "2026-08-13T00:00:00Z",
59+
changed_files: 1,
60+
commits: 1,
61+
review_comments: 1,
62+
head: { sha: state.head },
63+
});
64+
}
65+
if (url.pathname === "/comments") return json(response, 200, state.comments);
66+
if (url.pathname === "/timeline") return json(response, 200, []);
67+
if (url.pathname === "/reviews") return json(response, 200, []);
68+
if (url.pathname === "/files") {
69+
return json(response, 200, [
70+
{
71+
filename: "src/example.ts",
72+
previous_filename: null,
73+
status: "modified",
74+
additions: 1,
75+
deletions: 1,
76+
changes: 2,
77+
patch: "@@ -1 +1 @@\n-old\n+new",
78+
},
79+
]);
80+
}
81+
if (url.pathname === "/commits") {
82+
return json(response, 200, [
83+
{
84+
sha: "b".repeat(40),
85+
author: { login: "contributor" },
86+
commit: { message: "proof", author: { name: "Contributor" } },
87+
},
88+
]);
89+
}
90+
if (url.pathname === "/inline-comments") {
91+
return json(response, 200, [
92+
{
93+
id: 901,
94+
user: { login: "reviewer" },
95+
author_association: "CONTRIBUTOR",
96+
html_url: "https://example.invalid/discussion/901",
97+
created_at: "2026-08-13T00:00:00Z",
98+
updated_at: "2026-08-13T00:00:00Z",
99+
body: "proof",
100+
pull_request_review_id: 801,
101+
path: "src/example.ts",
102+
line: 1,
103+
side: "RIGHT",
104+
commit_id: reviewedHead,
105+
},
106+
]);
107+
}
108+
if (url.pathname === "/activity") {
109+
return json(response, 200, { revision: `sha256:${"1".repeat(64)}` });
110+
}
111+
return json(response, 404, { error: "not found" });
112+
});
113+
114+
server.listen(0, "127.0.0.1", () => {
115+
const address = server.address();
116+
if (!address || typeof address === "string") throw new Error("missing loopback address");
117+
process.stdout.write(`${address.port}\n`);
118+
});
119+
120+
for (const signal of ["SIGINT", "SIGTERM"]) {
121+
process.on(signal, () => server.close(() => process.exit(0)));
122+
}

0 commit comments

Comments
 (0)