Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge PR 2 lane G: storage correctness blockers, GC index, retired_generation dropped

garrytan49142ba5de51
diff --cc src/core/page-body/segment-chunks.ts
index 7d5e79380b,77deb9cfff..9be7954dfc
--- a/src/core/page-body/segment-chunks.ts
+++ b/src/core/page-body/segment-chunks.ts
@@@ -70,16 -60,25 +70,15 @@@ export async function prepareSegmentChu
throw new Error(`segment_regions_stale: regions at byte ${segment.byteStart} were computed under fence trust ${segment.fenceTrust}, the page is ${opts.fenceTrust}; rescan before chunking`);
}
const maxTokens = opts.maxChunkTokens ?? resolveMaxChunkTokens();
- const segEnd = segment.byteStart + segment.bytes.length;
- const raw = Buffer.from(segment.bytes).toString('utf8');
- const pieces: string[] = [];
+ const projected = projectSegment({ ...segment, lineStart: 0 }, { text: opts.text, fenceOverlay: opts.overlay });
const map: MappedPart[] = [];
- const factsTexts: string[] = [];
let projBytes = 0;
- for (const part of segmentProjectionParts(raw, segment.protectedRegions, segment.byteStart)) {
- let text = '';
- if (part.kind === 'text' || part.kind === 'pem') text = part.text;
- else if (part.kind === 'facts' && part.region!.open_start === undefined) {
- factsTexts.push(part.text);
- text = credentialSafeProjection(renderFactsRegion(splitFenceOverlay(part.text, opts.overlay).main));
- }
- if (!text) continue;
- const bytes = Buffer.byteLength(text, 'utf8');
- map.push({ projStart: projBytes, projEnd: projBytes + bytes, rawStart: part.start, rawEnd: part.end, linear: part.kind === 'text' });
- pieces.push(text);
+ for (const piece of projected.pieces) {
+ const bytes = Buffer.byteLength(piece.text, 'utf8');
+ map.push({ projStart: projBytes, projEnd: projBytes + bytes, rawStart: piece.rawStart, rawEnd: piece.rawEnd, linear: piece.linear });
projBytes += bytes;
}
- const projection = pieces.join('');
+ const projection = projected.pieces.map(piece => piece.text).join('');
const source = segment.region === 'truth' ? 'compiled_truth' : 'timeline';
const chunks: SegmentChunk[] = [];
const push = (c: Omit<SegmentChunk, 'local_ordinal'>) => chunks.push({ ...c, local_ordinal: chunks.length });
diff --cc test/helpers/segmented-chunks-fixture.ts
index 9ab992f709,77cbe520dc..8cb30b9ad1
--- a/test/helpers/segmented-chunks-fixture.ts
+++ b/test/helpers/segmented-chunks-fixture.ts
@@@ -85,8 -86,7 +87,8 @@@ export async function segmentPage(engin
chunkIds.set(chunk.text, Number(row!.id));
}
}
- // Clearing the body and replacing the rows unseals the projection; the fixture's rows are the projection.
- if (!opts.unsealed) await engine.executeRaw('UPDATE pages SET text_projection_revision = knowledge_revision WHERE id = $1', [pageId]);
+ // Clearing the body and replacing the rows unseals the projection; the fixture's rows are the projection, sealed at
+ // the chunker version sealSegmentedPage stamps.
- await engine.executeRaw('UPDATE pages SET text_projection_revision = knowledge_revision, chunker_version = $2 WHERE id = $1', [pageId, SEGMENTED_CHUNKER_VERSION]);
++ if (!opts.unsealed) await engine.executeRaw('UPDATE pages SET text_projection_revision = knowledge_revision, chunker_version = $2 WHERE id = $1', [pageId, SEGMENTED_CHUNKER_VERSION]);
return { pageId, chunkIds };
}