@quolu/lattice 0.113.0 → 0.113.2
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/package.json +1 -1
- package/src/todo-store.mjs +41 -10
- package/src/todo-version-compact.mjs +11 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quolu/lattice",
|
|
3
|
-
"version": "0.113.
|
|
3
|
+
"version": "0.113.2",
|
|
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",
|
package/src/todo-store.mjs
CHANGED
|
@@ -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 >
|
|
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.
|
|
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;
|
|
@@ -1775,11 +1787,13 @@ async function readTodoStoreView(options = {}) {
|
|
|
1775
1787
|
* unreadable. perf-store: validated once per process per unchanged plan.json (todo-version-memo).
|
|
1776
1788
|
*/
|
|
1777
1789
|
async function retainedPlanVersion(repoRoot, base, version) {
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1790
|
+
// m1: only the three digests stay in the memo; the record itself (a whole revision's migration) is dropped after the read.
|
|
1791
|
+
const identity = await memoByFileIdentity([path.resolve(repoRoot, base, version, TODO_VERSION_COMPACT_FILE)], async () => {
|
|
1792
|
+
const compact = await readCompactRecord(repoRoot, base, version, { verify: false }).catch(() => null);
|
|
1793
|
+
return compact === null ? null : { plan_digest: compact.plan_digest, predecessor_plan_digest: compact.predecessor_plan_digest,
|
|
1794
|
+
topology_digest: compact.topology_digest };
|
|
1795
|
+
});
|
|
1796
|
+
if (identity !== null) return { plan: identity, journalRef: `${base}/${version}/journal/active.jsonl` };
|
|
1783
1797
|
const ref = `${base}/${version}/plan.json`;
|
|
1784
1798
|
const plan = await memoByFileIdentity([path.resolve(repoRoot, ref)], async () => {
|
|
1785
1799
|
const value = await readArtifact(repoRoot, ref, {
|
|
@@ -2173,7 +2187,7 @@ async function readRawStoreJson(repoRoot, ref, maxBytes) {
|
|
|
2173
2187
|
}
|
|
2174
2188
|
|
|
2175
2189
|
async function rawLastEventDigest(repoRoot, ref, { missing = false } = {}) {
|
|
2176
|
-
const bytes = await readRawStoreFile(repoRoot, ref, TODO_LIMITS.
|
|
2190
|
+
const bytes = await readRawStoreFile(repoRoot, ref, TODO_LIMITS.snapshotBytes, { missing });
|
|
2177
2191
|
if (bytes === null) return null;
|
|
2178
2192
|
const lines = decodeUtf8(bytes, 'STORE_INCONSISTENT', 'invalid_utf8').split('\n').filter(Boolean);
|
|
2179
2193
|
let digest;
|
|
@@ -2893,6 +2907,13 @@ function carriedPlanScopedChain(store, previous, plan, journalRef, taskMigration
|
|
|
2893
2907
|
payload: { from, to, reason: event.payload.reason } });
|
|
2894
2908
|
pushPlanScopedEvent(successor.plan_scoped, carried);
|
|
2895
2909
|
}
|
|
2910
|
+
// m1: the declaration travels with the plan, so a read of this version finds it in its own chain instead of walking every
|
|
2911
|
+
// retained predecessor (a plan declared 975 revisions ago opened all 1,649 compact records per read).
|
|
2912
|
+
if (previous.coordination) {
|
|
2913
|
+
const { mode, reason, declared_by: actor, declared_at: recordedAt } = previous.coordination;
|
|
2914
|
+
pushPlanScopedEvent(successor.plan_scoped, buildPlanScopedEvent(successor, { kind: 'coordination_mode', actor,
|
|
2915
|
+
recorded_at: recordedAt, provenance: null, payload: { mode, reason } }));
|
|
2916
|
+
}
|
|
2896
2917
|
// 接続: only the schedule connections still open travel; a settled or removed one equals no connection.
|
|
2897
2918
|
for (const entry of projectTodoScheduleConnections(previous.plan_scoped?.events ?? [])) {
|
|
2898
2919
|
const taskId = ids.get(entry.task_id);
|
|
@@ -3057,6 +3078,14 @@ export function buildPlanGenesis(plan, input) {
|
|
|
3057
3078
|
return event;
|
|
3058
3079
|
}
|
|
3059
3080
|
|
|
3081
|
+
/** No reader accepts a genesis segment past `snapshotBytes`; refuse before the revision writes anything. */
|
|
3082
|
+
function refuseOversizeGenesis(event) {
|
|
3083
|
+
const bytes = canonicalLine(event).length;
|
|
3084
|
+
if (bytes > TODO_LIMITS.snapshotBytes) {
|
|
3085
|
+
fail('STORE_WRITE_REFUSED', 'revision_genesis_exceeds_limit', { bytes, limit: TODO_LIMITS.snapshotBytes });
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
|
|
3060
3089
|
export function buildRevisionGenesis(plan, input) {
|
|
3061
3090
|
const event = {
|
|
3062
3091
|
schema: 'lattice.todo_event.v2', project_id: plan.project_id, plan_key: plan.plan_key,
|
|
@@ -3074,6 +3103,7 @@ export function buildRevisionGenesis(plan, input) {
|
|
|
3074
3103
|
};
|
|
3075
3104
|
event.event_digest = todoSelfDigest(event, 'event_digest');
|
|
3076
3105
|
if (!validateTodoEvent(event)) throw new TypeError('revision genesis violates lattice.todo_event.v2');
|
|
3106
|
+
refuseOversizeGenesis(event);
|
|
3077
3107
|
return event;
|
|
3078
3108
|
}
|
|
3079
3109
|
|
|
@@ -3093,6 +3123,7 @@ export function buildPhaseRevisionGenesis(plan, input) {
|
|
|
3093
3123
|
};
|
|
3094
3124
|
event.event_digest = todoSelfDigest(event, 'event_digest');
|
|
3095
3125
|
if (!validateTodoEvent(event)) throw new TypeError('phase revision genesis violates lattice.todo_event.v4');
|
|
3126
|
+
refuseOversizeGenesis(event);
|
|
3096
3127
|
return event;
|
|
3097
3128
|
}
|
|
3098
3129
|
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { readFile } from 'node:fs/promises';
|
|
11
11
|
import { gunzipSync, gzipSync } from 'node:zlib';
|
|
12
12
|
import { canonicalizeTodoArtifact, isTodoDigest, isTodoIdentifier, todoSelfDigest } from './todo-contracts.mjs';
|
|
13
|
-
import { memoByFileIdentity } from './todo-version-memo.mjs';
|
|
14
13
|
|
|
15
14
|
export const TODO_VERSION_COMPACT_SCHEMA = 'lattice.todo_version_compact.v1';
|
|
16
15
|
export const TODO_VERSION_COMPACT_FILE = 'compact.json.gz';
|
|
@@ -104,16 +103,15 @@ export const packVersionCompact = (record) => gzipSync(Buffer.from(`${canonicali
|
|
|
104
103
|
* and keeps the shape check: one gunzip and one parse per version, which a read pays for every retained version of a plan.
|
|
105
104
|
*/
|
|
106
105
|
export async function readVersionCompact(directory, maxBytes = 8 * 1024 * 1024, { verify = true } = {}) {
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}, verify ? 'verify' : 'read');
|
|
106
|
+
// Not memoized: a record holds a revision's whole per-task migration, so keeping one per retained version grew RSS with the
|
|
107
|
+
// revision count (m1). Callers memoize the small value they derive (identity, note migration).
|
|
108
|
+
let packed;
|
|
109
|
+
try { packed = await readFile(`${directory}/${TODO_VERSION_COMPACT_FILE}`); } catch (error) {
|
|
110
|
+
if (error?.code === 'ENOENT') return null;
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
const text = gunzipSync(packed, { maxOutputLength: maxBytes }).toString('utf8');
|
|
114
|
+
const value = JSON.parse(text);
|
|
115
|
+
if ((verify && text !== `${canonicalizeTodoArtifact(value)}\n`) || !validateVersionCompact(value, { verify })) throw new Error('compact_record_invalid');
|
|
116
|
+
return value;
|
|
119
117
|
}
|