Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/core/chronicle/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,17 @@ export async function recordChronicleDecision(tx: BrainEngine, row: DecidingRequ
outcome: Record<string, unknown>): Promise<void> {
if (!snapshot || snapshot.page.deleted_at || !snapshot.page.content_hash || !row.operation) return;
const kind = typeof row.intent?.kind === 'string' ? row.intent.kind : null;
if (!DECIDING_OPERATIONS.has(row.operation) && !(row.operation === 'submit_job' && kind && DECIDING_INTENTS.has(kind))) return;
const carryForward = row.operation === 'add_link';
if (!DECIDING_OPERATIONS.has(row.operation) && !carryForward && !(row.operation === 'submit_job' && kind && DECIDING_INTENTS.has(kind))) return;
const page = snapshot.page;
// add_link authors no content: it only carries a still-pending, extractable decision to the new hash (opt-outs and done work stay put).
if (carryForward) {
const pending = await tx.executeRaw(
`SELECT 1 FROM chronicle_page_state WHERE source_id=$1 AND page_id=$2 AND state='pending' AND trigger='auto'
AND no_extract=false AND extractor_version=$3 LIMIT 1`,
[row.source_id, Number(page.id), CHRONICLE_EXTRACTOR_VERSION]);
if (pending.length === 0) return;
}
const base = { sourceId: row.source_id, pageId: Number(page.id), contentHash: String(page.content_hash), slug: page.slug,
trigger: 'auto' as const, principalKind: row.principal_kind ?? null, principalId: row.principal_id ?? null, requestId: row.id };
if (!isChronicleShaped(page.type, page.slug)) {
Expand Down
19 changes: 19 additions & 0 deletions test/chronicle-auto-decision.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,22 @@ describe('one eligibility function (E13/E11/C13/C14)', () => {
expect(decideChronicle({ page, authority: null, noExtract: false, enabled: true, settings, now }).reason).toBe('too_short');
});
});

describe('managed add_link', () => {
test('add_link must not strand a pending meeting decision', () => brain(async ({ engine, ctx }) => {
const { runPhaseChronicle } = await import('../src/core/cycle/chronicle.ts');
await engine.setConfig('chronicle.auto_settle_seconds', '0');
await put(ctx, 'people/alice-example', '---\ntype: person\ntitle: Alice Example\n---\nSynthetic test person.');
await put(ctx, 'meetings/link-repro', meeting());
const before = (await engine.getPage('meetings/link-repro', { sourceId: 'default' }))!;
await operationsByName.add_link.handler(ctx, {
from: 'meetings/link-repro', to: 'people/alice-example', context: 'Synthetic participant',
});
const after = (await engine.getPage('meetings/link-repro', { sourceId: 'default' }))!;
expect(after.content_hash).not.toBe(before.content_hash);
await engine.executeRaw("UPDATE chronicle_page_state SET next_attempt_at=now()-interval '1 second',decided_at=now()-interval '1 hour' WHERE state='pending'");
let calls = 0;
await runPhaseChronicle(engine, { judge: async () => { calls++; return { events: [] }; } });
expect(calls).toBe(1);
}), 120_000);
});
Loading