Skip to content

Commit adc2bc5

Browse files
committed
feat(dashboard): add durable lifecycle Bay kanban
1 parent 30d0321 commit adc2bc5

16 files changed

Lines changed: 1702 additions & 12 deletions

‎dashboard/bay-page.ts‎

Lines changed: 20 additions & 2 deletions
Large diffs are not rendered by default.

‎dashboard/exact-review-lifecycle.ts‎

Lines changed: 431 additions & 1 deletion
Large diffs are not rendered by default.

‎dashboard/exact-review-queue.ts‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,10 @@ const RECORD_EXPORT_SECTIONS: readonly RecordSection[] = [
556556
];
557557

558558
export class ExactReviewQueue {
559+
private state;
559560
private storage;
560561
private env;
561-
private ready: Promise<void>;
562+
private ready: Promise<void> | null = null;
562563
private migratedAt = 0;
563564
private legacyMirrorDisabled = false;
564565
private legacyMirrorWarningReported = false;
@@ -576,6 +577,7 @@ export class ExactReviewQueue {
576577
>();
577578

578579
constructor(state, env) {
580+
this.state = state;
579581
this.storage = state.storage;
580582
this.env = env;
581583
this.batchStore = new ExactReviewPublicationBatchStore(this.storage);
@@ -588,17 +590,25 @@ export class ExactReviewQueue {
588590
this.stateWriterCoordinator = new StateWriterCoordinator(this.storage);
589591
this.lifecycleProjectionStore = new ExactReviewLifecycleProjectionStore(this.storage);
590592
this.lifecycleTelemetryStore = new ExactReviewLifecycleTelemetryStore(this.storage);
591-
const initialize = () => this.initializeStorage();
592-
this.ready =
593-
typeof state.blockConcurrencyWhile === "function"
594-
? Promise.resolve(state.blockConcurrencyWhile(initialize))
595-
: initialize();
593+
// Direct in-process users retain the established eager setup behavior.
594+
// A real Durable Object has blockConcurrencyWhile; defer that setup until a
595+
// non-Bay request so constructing it for the public pure reader cannot
596+
// initialize or migrate storage before the route is known.
597+
if (typeof state.blockConcurrencyWhile !== "function") {
598+
this.ready = this.initializeStorage();
599+
}
596600
}
597601

598602
async fetch(request: Request) {
599-
await this.ready;
600-
this.cleanupLegacyCompatibilitySync();
601603
const url = new URL(request.url);
604+
// This is deliberately the only route that may observe lifecycle rows
605+
// before storage initialization. It must stay a pure reader: no schema
606+
// creation, cleanup, queue reclamation, alarm scheduling, or GitHub work.
607+
if (request.method === "GET" && url.pathname === "/lifecycle-bay") {
608+
return json({ durable_lifecycle_bay: this.lifecycleProjectionStore.readBaySnapshot() });
609+
}
610+
await this.ensureReady();
611+
this.cleanupLegacyCompatibilitySync();
602612
if (request.method === "POST" && url.pathname === "/review-coverage/inventory") {
603613
const inventory = normalizeReviewCoverageInventory(await request.json().catch(() => null));
604614
if (!inventory) return json({ error: "invalid_review_coverage_inventory" }, 400);
@@ -3094,7 +3104,7 @@ export class ExactReviewQueue {
30943104
}
30953105

30963106
async alarm() {
3097-
await this.ready;
3107+
await this.ensureReady();
30983108
this.cleanupLegacyCompatibilitySync();
30993109
const startedAt = Date.now();
31003110
await this.storage.deleteAlarm();
@@ -3831,6 +3841,16 @@ export class ExactReviewQueue {
38313841
await this.scheduleNext(current, completedAt);
38323842
}
38333843

3844+
private ensureReady() {
3845+
if (this.ready) return this.ready;
3846+
const initialize = () => this.initializeStorage();
3847+
this.ready =
3848+
typeof this.state.blockConcurrencyWhile === "function"
3849+
? Promise.resolve(this.state.blockConcurrencyWhile(initialize))
3850+
: initialize();
3851+
return this.ready;
3852+
}
3853+
38343854
private async terminalizePublicationCandidates(
38353855
candidates: Array<Pick<ExactReviewQueueItem, "key" | "revision" | "decision">>,
38363856
options: { apply?: boolean; legacyReconciliation?: "v1" | "state_batch_v2" } = {},

‎dashboard/worker.ts‎

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ export default {
720720
return authenticatedExactReviewReconcile(request, env);
721721
if (url.pathname === "/api/exact-review-queue" && request.method === "GET")
722722
return exactReviewQueueRequest(env, "/stats");
723+
if (url.pathname === "/api/durable-lifecycle-bay" && request.method === "GET")
724+
return json({ durable_lifecycle_bay: await durableLifecycleBaySnapshot(env) });
723725
if (url.pathname === "/api/recent-durable-publication-events" && request.method === "GET")
724726
return exactReviewQueueRequest(
725727
env,
@@ -1780,6 +1782,173 @@ async function exactReviewQueueRequest(env, path, request?: Request) {
17801782
);
17811783
}
17821784

1785+
export async function durableLifecycleBaySnapshot(env, now = Date.now()) {
1786+
let response: Response;
1787+
let body: Record<string, unknown>;
1788+
try {
1789+
response = await exactReviewQueueRequest(env, "/lifecycle-bay");
1790+
body = objectValue(await response.json().catch(() => null));
1791+
} catch {
1792+
return unknownDurableLifecycleBay("unavailable", now);
1793+
}
1794+
const snapshot = objectValue(body.durable_lifecycle_bay) as Record<string, unknown>;
1795+
const checkedAt = Date.now();
1796+
if (!response.ok) return unknownDurableLifecycleBay("unavailable", now);
1797+
if (!validDurableLifecycleBaySnapshot(snapshot, checkedAt)) {
1798+
return unknownDurableLifecycleBay("malformed", checkedAt);
1799+
}
1800+
if (checkedAt - Date.parse(String(snapshot.generated_at)) > 60_000) {
1801+
return unknownDurableLifecycleBay("stale", checkedAt);
1802+
}
1803+
return snapshot;
1804+
}
1805+
1806+
function unknownDurableLifecycleBay(reason, now = Date.now()) {
1807+
return {
1808+
version: 1,
1809+
source: "exact-review-lifecycle-projection-v1",
1810+
generated_at: new Date(now).toISOString(),
1811+
freshness: { maximum_age_ms: 60_000 },
1812+
collection: { state: "unknown", reason },
1813+
inventory: null,
1814+
lanes: null,
1815+
sample: null,
1816+
};
1817+
}
1818+
1819+
function validDurableLifecycleBaySnapshot(value, now = Date.now()) {
1820+
const snapshot = objectValue(value);
1821+
if (
1822+
snapshot.version !== 1 ||
1823+
snapshot.source !== "exact-review-lifecycle-projection-v1" ||
1824+
!Number.isFinite(Date.parse(String(snapshot.generated_at || ""))) ||
1825+
Date.parse(String(snapshot.generated_at)) > now + 60_000 ||
1826+
!objectValue(snapshot.freshness) ||
1827+
Number(snapshot.freshness.maximum_age_ms) !== 60_000
1828+
) {
1829+
return false;
1830+
}
1831+
const collection = objectValue(snapshot.collection);
1832+
if (collection.state === "unknown") {
1833+
return (
1834+
["unavailable", "malformed", "mixed", "stale", "over_cap"].includes(
1835+
String(collection.reason),
1836+
) &&
1837+
snapshot.inventory === null &&
1838+
snapshot.lanes === null &&
1839+
snapshot.sample === null
1840+
);
1841+
}
1842+
if (collection.state !== "complete") return false;
1843+
const inventory = objectValue(snapshot.inventory);
1844+
const lanes = objectValue(snapshot.lanes);
1845+
const sample = objectValue(snapshot.sample);
1846+
if (
1847+
!["lifecycle_records", "target_revisions", "unique_targets"].every(
1848+
(key) => Number.isSafeInteger(inventory[key]) && Number(inventory[key]) >= 0,
1849+
) ||
1850+
![
1851+
"pending",
1852+
"acknowledgement_pending",
1853+
"completed",
1854+
"superseded",
1855+
"requeued",
1856+
"terminal_attention",
1857+
].every((key) => Number.isSafeInteger(lanes[key]) && Number(lanes[key]) >= 0) ||
1858+
Number(sample.limit) !== 24 ||
1859+
!Number.isSafeInteger(sample.returned) ||
1860+
!Number.isSafeInteger(sample.omitted) ||
1861+
!Array.isArray(sample.cards) ||
1862+
sample.returned !== sample.cards.length ||
1863+
sample.cards.length > 24 ||
1864+
sample.omitted !== Math.max(0, Number(inventory.lifecycle_records) - sample.cards.length)
1865+
) {
1866+
return false;
1867+
}
1868+
return sample.cards.every(validDurableLifecycleBayCard);
1869+
}
1870+
1871+
function validDurableLifecycleBayCard(value) {
1872+
const card = objectValue(value);
1873+
const target = objectValue(card.target);
1874+
const facts = objectValue(card.facts);
1875+
return (
1876+
/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(String(target.repository || "")) &&
1877+
Number.isSafeInteger(target.number) &&
1878+
Number(target.number) > 0 &&
1879+
target.url === `https://github.com/${target.repository}/issues/${target.number}` &&
1880+
Number.isSafeInteger(card.revision) &&
1881+
Number(card.revision) > 0 &&
1882+
[
1883+
"pending",
1884+
"completed",
1885+
"acknowledgement_pending",
1886+
"acknowledgement_skipped",
1887+
"superseded",
1888+
"requeue",
1889+
"dead_letter",
1890+
"target_closed",
1891+
"target_missing",
1892+
"policy_noop",
1893+
"guarded_open",
1894+
"failed",
1895+
].includes(String(card.state)) &&
1896+
[
1897+
"pending",
1898+
"acknowledgement_pending",
1899+
"completed",
1900+
"superseded",
1901+
"requeued",
1902+
"terminal_attention",
1903+
].includes(String(card.lane)) &&
1904+
(card.terminal_label === null ||
1905+
[
1906+
"review_completed_routed",
1907+
"superseded",
1908+
"requeue",
1909+
"acknowledgement_skipped",
1910+
"dead_letter",
1911+
"target_closed",
1912+
"target_missing",
1913+
"policy_noop",
1914+
"guarded_open",
1915+
"failure",
1916+
].includes(String(card.terminal_label))) &&
1917+
Array.isArray(card.terminal_history) &&
1918+
card.terminal_history.every((entry) =>
1919+
[
1920+
"review_completed_routed",
1921+
"superseded",
1922+
"requeue",
1923+
"dead_letter",
1924+
"target_closed",
1925+
"target_missing",
1926+
"policy_noop",
1927+
"guarded_open",
1928+
"failure",
1929+
].includes(String(entry)),
1930+
) &&
1931+
typeof card.current_revision === "boolean" &&
1932+
facts.admission === "recorded" &&
1933+
Number.isSafeInteger(facts.claim_count) &&
1934+
Number(facts.claim_count) >= 0 &&
1935+
[null, "completed", "failed", "cancelled"].includes(facts.review_result) &&
1936+
typeof facts.github_effect_recorded === "boolean" &&
1937+
Array.isArray(facts.canonical_receipts) &&
1938+
facts.canonical_receipts.every((entry) =>
1939+
["accepted", "deduped", "superseded"].includes(entry),
1940+
) &&
1941+
[null, "durable", "not_required"].includes(facts.router_receipt) &&
1942+
["not_required", "pending", "observed", "skipped_locked", "unavailable"].includes(
1943+
facts.acknowledgement,
1944+
) &&
1945+
Number.isFinite(Date.parse(String(card.updated_at || ""))) &&
1946+
Number.isSafeInteger(card.age_ms) &&
1947+
Number(card.age_ms) >= 0 &&
1948+
card.provenance === "exact-review-lifecycle-projection-v1"
1949+
);
1950+
}
1951+
17831952
async function recentDurablePublicationEventsSnapshot(env, window = "24h") {
17841953
const response = await exactReviewQueueRequest(
17851954
env,

‎docs/proof/csw-093/README.md‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# CSW-093 Workstream 5 proof contract
2+
3+
## Claim
4+
5+
OpenClaw Bay renders a bounded lifecycle Kanban from only the durable
6+
`ExactReviewLifecycleProjection` reducer. Its read path neither changes queue
7+
or Durable Object state nor treats a workflow, worker step, or action result as
8+
a lifecycle fact.
9+
10+
## Exercised surface
11+
12+
- Public Worker route: `GET /api/durable-lifecycle-bay`
13+
- Durable Object route: `GET /lifecycle-bay`
14+
- The built `/bay-demo` page and its lifecycle Kanban renderer
15+
16+
## Controlled scenario
17+
18+
A local Worker/Durable Object fixture records synthetic lifecycle projections
19+
for: pending, acknowledgement pending, completed, superseded, requeued,
20+
dead-letter, target closed/missing, policy/guarded/failure, and acknowledgement
21+
skipped. It includes a re-review sequence where an older revision remains
22+
requeued or superseded while a later revision starts in its own earlier lane.
23+
The fixture also covers malformed, mixed, unavailable, stale, and 513-row
24+
sources, plus a 25+ card complete source to exercise the 24-card round-robin
25+
sample.
26+
27+
## Required observations
28+
29+
- The pure Worker/DO read causes no Durable Object write, schema initialization,
30+
prune, lease reclaim, alarm scheduling, or GitHub request; a subsequent
31+
ordinary initialized queue request against that same local DO still succeeds.
32+
- Cards retain the target/revision/fence record cardinality internally and never
33+
expose a fence, run, claim, delivery, receipt, comment, or digest identifier.
34+
- `Completed` appears only from the lifecycle reducer; acknowledgement-pending
35+
and acknowledgement-skipped cards do not appear in Completed.
36+
- Incomplete, malformed, mixed, unavailable, stale, or over-cap data renders
37+
one Unknown state with no partial lane totals or cards. A complete zero-row
38+
response renders Empty instead.
39+
- Browser screenshots capture Completed, Terminal attention, Unknown, and the
40+
bounded sample view.
41+
42+
## Command and environment
43+
44+
Run the focused tests and builds plus the generated proof script through
45+
Docker-backed Crabbox local-container on `mcr.microsoft.com/playwright:v1.60.0-noble`,
46+
with `--no-hydrate` and `--timing-json`. Run lint, format, and diff checks as
47+
the final local branch gates. The proof blocks external network access except
48+
the local Worker; it never contacts GitHub, production Worker/DO state, queues,
49+
gates, or R2.
50+
51+
## Artifacts and limits
52+
53+
The proof script writes a redacted runtime transcript, a readable Worker/DO
54+
initialization transcript, machine-readable sequence/summary, response captures,
55+
and screenshots under this directory. It proves the controlled Worker/DO and
56+
browser surface only; it does not claim production data volume, production
57+
freshness, or live Activity behavior.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"durable_lifecycle_bay": {
3+
"version": 1,
4+
"source": "exact-review-lifecycle-projection-v1",
5+
"generated_at": "2026-08-01T11:57:39.410Z",
6+
"freshness": {
7+
"maximum_age_ms": 60000
8+
},
9+
"collection": {
10+
"state": "unknown",
11+
"reason": "unavailable"
12+
},
13+
"inventory": null,
14+
"lanes": null,
15+
"sample": null
16+
}
17+
}
223 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
✔ durable lifecycle Bay is a pure, redacted per-target-revision reducer snapshot (146.444668ms)
2+
✔ durable lifecycle Bay keeps ordinary queue initialization available after a pure direct read (42.677301ms)
3+
✔ durable lifecycle Bay fail-closes unknown snapshots without partial cards or counts (199.364784ms)
4+
ℹ tests 3
5+
ℹ suites 0
6+
ℹ pass 3
7+
ℹ fail 0
8+
ℹ cancelled 0
9+
ℹ skipped 0
10+
ℹ todo 0
11+
ℹ duration_ms 1345.909156

0 commit comments

Comments
 (0)