@lmzhen/dsh-evolution-state-domain 0.1.0-rc.9 → 0.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
2
+ import { DomainError, defineDomain, domainTable } from "@deepseek-ai/dsh-storage-domain";
3
3
  //#region lib/types/index.js
4
4
  /**
5
5
  * storage-domain provider for evolution state.
@@ -18,6 +18,8 @@ const reviewStateSchema = z.object({
18
18
  lastTurn: z.number().int().nonnegative()
19
19
  });
20
20
  const curatorStateSchema = z.object({
21
+ /** Optional record-shape version; legacy records without it stay compatible. */
22
+ schemaVersion: z.number().int().nonnegative().optional(),
21
23
  lastRunAt: z.number().nonnegative(),
22
24
  runCount: z.number().int().nonnegative(),
23
25
  lastSummary: z.string(),
@@ -52,14 +54,38 @@ const EVOLUTION_DOMAIN = defineDomain({
52
54
  pending: domainTable(pendingSchema)
53
55
  }
54
56
  });
57
+ /**
58
+ * Bounded open() retry (rc.42 audit P1-4, package-private): a rejected open
59
+ * used to poison the shared `opening` promise forever, so one transient
60
+ * backend failure (lock, busy) took the provider down until process restart.
61
+ * Transient failures now recover within the budget; deterministic failures
62
+ * (corrupt domain version) surface after it, and the cleared promise lets a
63
+ * later call start a fresh budget.
64
+ */
65
+ const OPEN_MAX_ATTEMPTS = 3;
66
+ const OPEN_RETRY_BASE_MS = 100;
55
67
  function apply(ctx) {
56
68
  let domain = null;
57
69
  let opening = null;
58
70
  async function ensure() {
59
71
  if (domain) return domain;
60
- const facility = ctx.get("storageDomain");
61
- if (!facility) throw new Error("evolution-state-domain requires @deepseek-ai/dsh-storage-domain");
62
- opening ??= facility.open(EVOLUTION_DOMAIN);
72
+ if (!opening) {
73
+ opening = (async () => {
74
+ const facility = ctx.get("storageDomain");
75
+ if (!facility) throw new Error("evolution-state-domain requires @deepseek-ai/dsh-storage-domain");
76
+ let lastError;
77
+ for (let attempt = 1; attempt <= OPEN_MAX_ATTEMPTS; attempt += 1) try {
78
+ return await facility.open(EVOLUTION_DOMAIN);
79
+ } catch (error) {
80
+ lastError = error;
81
+ if (attempt < OPEN_MAX_ATTEMPTS) await new Promise((resolve) => setTimeout(resolve, OPEN_RETRY_BASE_MS * 2 ** (attempt - 1)));
82
+ }
83
+ throw lastError;
84
+ })();
85
+ opening.catch(() => {
86
+ opening = null;
87
+ });
88
+ }
63
89
  domain = await opening;
64
90
  return domain;
65
91
  }
@@ -100,8 +126,9 @@ function apply(ctx) {
100
126
  return slot.record;
101
127
  });
102
128
  return slot.record;
103
- } catch {
104
- return null;
129
+ } catch (error) {
130
+ if (error instanceof DomainError && error.code === "missing-key") return null;
131
+ throw error;
105
132
  }
106
133
  },
107
134
  async releasePendingClaim(id, claimId) {
@@ -136,11 +163,12 @@ function apply(ctx) {
136
163
  record: resolved.record,
137
164
  applied: true
138
165
  };
139
- } catch {
140
- return {
166
+ } catch (error) {
167
+ if (error instanceof DomainError && error.code === "missing-key") return {
141
168
  record: null,
142
169
  applied: false
143
170
  };
171
+ throw error;
144
172
  }
145
173
  }
146
174
  };
@@ -18,6 +18,7 @@ export declare const reviewStateSchema: z.ZodObject<{
18
18
  lastTurn: z.ZodNumber;
19
19
  }, z.core.$strip>;
20
20
  export declare const curatorStateSchema: z.ZodObject<{
21
+ schemaVersion: z.ZodOptional<z.ZodNumber>;
21
22
  lastRunAt: z.ZodNumber;
22
23
  runCount: z.ZodNumber;
23
24
  lastSummary: z.ZodString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-state-domain",
3
3
  "description": "storage-domain provider for evolution state (community build)",
4
- "version": "0.1.0-rc.9",
4
+ "version": "0.2.0-rc.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -35,14 +35,14 @@
35
35
  "zod": "^3.0.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
38
+ "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
39
39
  "@deepseek-ai/cordis": "^4.0.1",
40
- "@deepseek-ai/dsh-storage-domain": "^0.1.0-rc.6",
41
- "@lmzhen/dsh-evolution-state-storage": "^0.1.0-rc.9"
40
+ "@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
41
+ "@lmzhen/dsh-evolution-state-storage": "^0.2.0-rc.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
45
- "@deepseek-ai/dsh-storage-domain": "^0.1.0-rc.6",
46
- "@lmzhen/dsh-evolution-state-storage": "^0.1.0-rc.9"
44
+ "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
45
+ "@deepseek-ai/dsh-storage-domain": "^0.1.1-rc.2",
46
+ "@lmzhen/dsh-evolution-state-storage": "^0.2.0-rc.1"
47
47
  }
48
48
  }