@quolu/lattice 0.113.0 → 0.113.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/todo-store.mjs +27 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quolu/lattice",
3
- "version": "0.113.0",
3
+ "version": "0.113.1",
4
4
  "description": "Schedulability compiler for multi-agent development: observe real code boundaries, refactor the conflicting seam, recompile the plan for parallel execution",
5
5
  "author": {
6
6
  "name": "Quo / クオ at kitepon.dev",
@@ -293,11 +293,23 @@ async function readSnapshotArtifact(repoRoot, ref) {
293
293
  */
294
294
  const acceptedSegments = new Set();
295
295
 
296
+ /**
297
+ * A revision genesis carries every task's migrated state in one line, so it grows with the plan (ADR 0201 bounds a plan by
298
+ * bytes) and no sealing can split it. A segment that is exactly one sequence-0 plan_genesis may therefore reach
299
+ * `snapshotBytes`; every other segment stays within `journalSegmentBytes`.
300
+ */
301
+ function isOversizeGenesisSegment(bytes) {
302
+ if (bytes.length > TODO_LIMITS.snapshotBytes || bytes.indexOf(0x0a) !== bytes.length - 1) return false;
303
+ try {
304
+ const event = JSON.parse(bytes.toString('utf8'));
305
+ return event?.kind === 'plan_genesis' && event.sequence === 0;
306
+ } catch { return false; }
307
+ }
308
+
296
309
  function parseJournalSegment(bytes, ref = null, { canonical: checkCanonical = true } = {}) {
297
310
  const detail = ref === null ? undefined : { ref };
298
- if (bytes.length === 0 || bytes.length > TODO_LIMITS.journalSegmentBytes) {
299
- fail('STORE_CORRUPT', bytes.length > TODO_LIMITS.journalSegmentBytes
300
- ? 'journal_segment_limit_exceeded' : 'journal_empty', detail);
311
+ if (bytes.length === 0 || (bytes.length > TODO_LIMITS.journalSegmentBytes && !isOversizeGenesisSegment(bytes))) {
312
+ fail('STORE_CORRUPT', bytes.length > 0 ? 'journal_segment_limit_exceeded' : 'journal_empty', detail);
301
313
  }
302
314
  const text = decodeUtf8(bytes, 'STORE_CORRUPT', 'journal_invalid_utf8');
303
315
  if (!text.endsWith('\n') || text.startsWith('\uFEFF')) fail('STORE_CORRUPT', 'journal_byte_contract', detail);
@@ -370,7 +382,7 @@ async function readJournal(repoRoot, journalRef, { verify = true } = {}) {
370
382
  const segments = await readSealedSegments(repoRoot, journalRef, 'sealed', { canonical: verify });
371
383
  let activeBytes;
372
384
  try {
373
- activeBytes = state === null ? gunzipSync(await readFile(packed.absolute), { maxOutputLength: TODO_LIMITS.journalSegmentBytes })
385
+ activeBytes = state === null ? gunzipSync(await readFile(packed.absolute), { maxOutputLength: TODO_LIMITS.snapshotBytes })
374
386
  : normalizeCheckoutEol(await readFile(state.absolute));
375
387
  } catch { fail('STORE_CORRUPT', 'journal_gzip_invalid', { ref: `${journalRef}.gz` }); }
376
388
  const duplicateActive = segments.at(-1)?.bytes.equals(activeBytes) === true;
@@ -2173,7 +2185,7 @@ async function readRawStoreJson(repoRoot, ref, maxBytes) {
2173
2185
  }
2174
2186
 
2175
2187
  async function rawLastEventDigest(repoRoot, ref, { missing = false } = {}) {
2176
- const bytes = await readRawStoreFile(repoRoot, ref, TODO_LIMITS.journalSegmentBytes, { missing });
2188
+ const bytes = await readRawStoreFile(repoRoot, ref, TODO_LIMITS.snapshotBytes, { missing });
2177
2189
  if (bytes === null) return null;
2178
2190
  const lines = decodeUtf8(bytes, 'STORE_INCONSISTENT', 'invalid_utf8').split('\n').filter(Boolean);
2179
2191
  let digest;
@@ -3057,6 +3069,14 @@ export function buildPlanGenesis(plan, input) {
3057
3069
  return event;
3058
3070
  }
3059
3071
 
3072
+ /** No reader accepts a genesis segment past `snapshotBytes`; refuse before the revision writes anything. */
3073
+ function refuseOversizeGenesis(event) {
3074
+ const bytes = canonicalLine(event).length;
3075
+ if (bytes > TODO_LIMITS.snapshotBytes) {
3076
+ fail('STORE_WRITE_REFUSED', 'revision_genesis_exceeds_limit', { bytes, limit: TODO_LIMITS.snapshotBytes });
3077
+ }
3078
+ }
3079
+
3060
3080
  export function buildRevisionGenesis(plan, input) {
3061
3081
  const event = {
3062
3082
  schema: 'lattice.todo_event.v2', project_id: plan.project_id, plan_key: plan.plan_key,
@@ -3074,6 +3094,7 @@ export function buildRevisionGenesis(plan, input) {
3074
3094
  };
3075
3095
  event.event_digest = todoSelfDigest(event, 'event_digest');
3076
3096
  if (!validateTodoEvent(event)) throw new TypeError('revision genesis violates lattice.todo_event.v2');
3097
+ refuseOversizeGenesis(event);
3077
3098
  return event;
3078
3099
  }
3079
3100
 
@@ -3093,6 +3114,7 @@ export function buildPhaseRevisionGenesis(plan, input) {
3093
3114
  };
3094
3115
  event.event_digest = todoSelfDigest(event, 'event_digest');
3095
3116
  if (!validateTodoEvent(event)) throw new TypeError('phase revision genesis violates lattice.todo_event.v4');
3117
+ refuseOversizeGenesis(event);
3096
3118
  return event;
3097
3119
  }
3098
3120