Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(persistence): G7a publication hooks in publishMutation and publishGroup (GBRA-95)

garrytanb22a9bb0ea91
diff --git a/src/core/persistence/coordinator.ts b/src/core/persistence/coordinator.ts
index 90c06c9b00..45317da2c6 100644
--- a/src/core/persistence/coordinator.ts
+++ b/src/core/persistence/coordinator.ts
@@ -54,6 +54,7 @@ import { publicationBeliefOptions, withBeliefBatch } from '../belief/ledger.ts';
import { markBeliefCommits } from '../belief/append.ts';
import { classifyPgAccessError } from '../pg-access-classify.ts';
import { commitThroughDoor, doorCommitLanded, doorMarker, replayAfterDoorCommit, sourceCanonicalGit, strictChanged } from './git-door.ts';
+import { assertNoPrivateCommit, declareStrictPublication } from './git-declared.ts';
interface PreparedMutationBase {
sourceExclusive?: boolean;
@@ -585,6 +586,8 @@ export async function publishMutation(engine: BrainEngine, row: WriteRequest, pr
const door = recovery?.version === 1 ? recovery : null;
// A write prepared strict rechecks its flag under the source lock; one prepared without it publishes as before (only conversion sets the flag).
if (door?.door && !await sourceCanonicalGit(tx, row.source_id, true)) throw strictChanged(row.source_id);
+ // G7a (git-declared.ts): a strict publication never writes or commits a private page's bytes.
+ if (!skill) await assertNoPrivateCommit(tx, row, prepared, snapshot, binding);
if (recovery) {
const records = recoveryFiles(recovery);
for (const record of records) if ((skill ? bundleFileHash(record) : fileHash(record.path)) !== record.beforeHash) {
@@ -616,6 +619,8 @@ export async function publishMutation(engine: BrainEngine, row: WriteRequest, pr
if (!skill) await classifyUnboundPage(tx, row);
if (prepared.databaseOnlyReason === 'mirror_read_only') await classifyMirrorPage(tx, row);
const final = skill ? null : await publicationPostimage(tx, row, prepared);
+ // G7a: a strict file-less write must be declared; its class is stamped before the door commit, in this transaction.
+ if (!skill) await declareStrictPublication(tx, row, prepared, snapshot, final, binding);
decoratePublicationOutcome(row, prepared, outcome, final, files.length, skill);
await recordPublicationFenceTrend(tx, row, outcome);
// G2: a strict source's file is committed before its row; its Git effect only pushes.
diff --git a/src/core/persistence/group-publish.ts b/src/core/persistence/group-publish.ts
index 79ce1abab9..4ac8db0cc7 100644
--- a/src/core/persistence/group-publish.ts
+++ b/src/core/persistence/group-publish.ts
@@ -55,6 +55,7 @@ import { assertUnboundPublication, classifyUnboundPage } from './unbound-source.
import { boundPublication, declarePublication, publicationLeaseMs, publicationTransaction, type PublicationBound } from './publication-deadline.ts';
import { classifyMirrorPage, sourceMirrorReadOnly } from './mirror-read-only.ts';
import { commitThroughDoor, doorMarker, sourceCanonicalGit, strictChanged } from './git-door.ts';
+import { assertNoPrivateCommit, declareStrictPublication } from './git-declared.ts';
import { authorizePageVisibility } from './page-visibility.ts';
import { withFilesystemPublication } from './filesystem-guard.ts';
import { isWriteTargetContained } from '../path-confine.ts';
@@ -364,6 +365,8 @@ export async function publishGroup(engine: BrainEngine, rows: WriteRequest[], pr
async () => { if (!file && attribute) await setMemberAttribution(tx, publicationAttribution(row, member.trust)); },
]) as [unknown, Awaited<ReturnType<BrainEngine['readPageSnapshot']>>];
if (!sync) await member.validate?.(tx);
+ // G7a (git-declared.ts): a strict member never writes or commits a private page's bytes; one refusal rolls the group back.
+ await assertNoPrivateCommit(tx, row, member, snapshot, binding);
if (file) {
if (persistenceFileHash(file.record.path) !== file.record.beforeHash) throw new OperationError('unexpected_file_bytes', 'The canonical file changed during preparation.', 'The members publish one at a time.');
await seam('before_publication', row);
@@ -377,6 +380,7 @@ export async function publishGroup(engine: BrainEngine, rows: WriteRequest[], pr
await classifyUnboundPage(tx, row);
if (member.databaseOnlyReason === 'mirror_read_only') await classifyMirrorPage(tx, row);
const final = await publicationPostimage(tx, row, member);
+ await declareStrictPublication(tx, row, member, snapshot, final, binding);
decoratePublicationOutcome(row, member, outcome, final, file ? 1 : 0, false);
effects = async () => {
await recordPublicationFenceTrend(tx, row, outcome);