v0.41.24.0 fix(conversation-parser): threshold gates + bold-paren-time pattern — 20,167 Circleback messages unblocked (closes #1533) (#1543)

* fix(conversation-parser): threshold-gated fallback + acceptance floor (closes #1533)

`gbrain conversation-parser scan` reported `phase: no_match` on meeting
pages where 175 of 226 lines (77.8%) were valid `imessage-slack` format.
The 36 reformatted Circleback meetings could not flow through the
conversation facts pipeline.

Root cause: `scorePattern` only scans the first 10 non-blank lines. A
meeting page's `## Summary` + blockquote + `## Transcript` preamble takes
all 10 head slots, so every pattern scored 0 and the orchestrator
short-circuited to `no_match` without ever seeing the transcript.

Fix: two-tier scoring with threshold gates.

1. Fast path unchanged: chat-only pages match on line 1, scoring 1.0,
   skipping the fallback entirely.
2. Full-body fallback fires when `top.score < SCORING_HEAD_TRIGGER_THRESHOLD`
   (0.3). NOT `=== 0` — Codex P1 #1 caught the bug class where a stray
   head match (blockquote that accidentally matches an unrelated
   pattern at 0.1) would suppress the fallback. 0.3 leaves the fast
   path untouched while triggering on any preamble-dominated page.
3. Minimum acceptance floor `SCORING_MIN_ACCEPTANCE` (0.05) prevents
   essay false positives: a 300-line essay with one stray
   `**Name** (date time):` line scores ~0.003 — without the floor it
   would flip to `regex_match` with `messages.length = 1`. Closes
   Codex P1 #2.

DRY refactor: extract `getNonBlankLines` + `scoreFromLines` so the
quick_reject + regex loop lives in one place. New exported
`scorePatternFull` for direct unit testing. Fallback pre-splits the
body ONCE per pass to avoid 12 redundant splits.

Plan + decisions + Codex consult absorption at:
~/.claude/plans/system-instruction-you-are-working-starry-frost.md

Tests: 10 new cases in test/conversation-parser/parse.test.ts (87
pass). Highlights:
- #1533 IRON-RULE regression pin (meeting page → regex_match,
  imessage-slack, 20 messages)
- Stray-head-match guard (Codex P1 #1: irc-classic 0.1 in head does
  not suppress fallback; imessage-slack wins on full body)
- Essay false-positive guard (Codex P1 #2: 1/301 score below
  acceptance floor stays no_match)
- 300-line preamble + 50 chat lines hits fallback
- Cap test reshaped (Codex P2 #6): pins behavior not constant value

Once landed and a brain has `cycle.conversation_facts_backfill.enabled
= true` (opt-in), the 36 Circleback meetings flow through the fact
extractor automatically. Operators on the manual path run
`gbrain extract-conversation-facts <source>` directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(conversation-parser): add bold-paren-time built-in pattern (closes user-facing half of #1533)

Per /codex follow-up D-FOLLOWUP-1.B: the threshold-gated fallback fix
(8d7a18ac) closed the bug CLASS — but the user's actual 112 Circleback
meeting files at ~/git/brain/meetings/ use a transcript shape that no
existing built-in pattern matches:

  **Participant 2** (00:00): Companies that we...      ← (HH:MM)
  **Participant 1** (00:00:00): We found the...        ← (HH:MM:SS)

Without a pattern that matches this shape, even the fallback re-scoring
all 12 candidates against the full body returned zero matches → no_match.

Add `bold-paren-time` as the 13th built-in. Two sub-shapes covered via
non-capturing optional seconds group; capture indexes stay identical.
date_source: frontmatter so the page's `date:` provides the day anchor.

Time semantics: Circleback timestamps are elapsed-time-from-meeting-
start, not wall-clock. Parser treats them as wall-clock 24h on the
frontmatter date, so every message lands on the same day at HH:MM. The
fact extractor only cares about speaker + content, so this is honest
enough; precise per-line wall-clock would need an elapsed_time flag on
PatternEntry (v0.42+ scope).

Declaration position: after imessage-slack and telegram-bracket so on
the rare tie those more-specific patterns win. The regex requires `\)`
immediately after the time group, so imessage-slack's
`(2024-03-15 9:00 AM)` shape falls through correctly.

EMPIRICAL RESULT against all Circleback meetings in ~/git/brain/meetings:
- 367 total files with `source: circleback`
- Pre-fix:  0 parsed (no pattern matched the shape)
- Post-fix: 113 parsed (112 via bold-paren-time, 1 via telegram-bracket)
- 20,167 messages flow through to the fact extractor (was 0)
- 254 remain no_match (notes-only meetings without inline transcripts —
  transcripts in those cases live in separate files referenced via
  blockquote, not in the meeting body)

Smoke-tested manually against 3 representative files:
- 2026-03-19-yc-partner-strategy-ai-leverage-review.md → 225 messages
- 2026-01-15-ro-khanna-c4.md → 294 messages
- 2026-04-01-narrative-arc-equity-regrets.md → 9 messages (HH:MM:SS variant)

Tests: 54 unit cases pass (88 across full parser suite). 3 new cases in
parse.test.ts pin the contract: (HH:MM) shape matches, (HH:MM:SS) shape
matches, imessage-slack still wins on full-datetime overlap, and meeting
page with preamble + bold-paren-time transcript hits the threshold
fallback correctly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: bump version and changelog (v0.41.21.0)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: bump conversation-parser entry to v0.41.21.0 (13 patterns + threshold gates)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(privacy): scrub OpenClaw fork name from new pattern's source_doc + CLAUDE.md

CI verify failed on check:privacy — the new bold-paren-time pattern
added in 80208f21 referenced the private OpenClaw fork name in
builtins.ts:125 (comment) and builtins.ts:178 (source_doc), and the
CLAUDE.md doc-sync commit 1710020a leaked it once more.

CLAUDE.md privacy rule (line 550): the private fork name is banned
in CHANGELOG.md, README.md, docs/, skills/, PR titles + bodies,
commit messages, and comments in checked-in code. Canonical
replacement: "your OpenClaw" or "OpenClaw reference deployment".

This commit rewrites all three sites. Source pipeline attribution
stays accurate ("OpenClaw meeting-ingestion pipeline reformat of
Circleback transcripts") without naming the specific private fork.

bun run verify: 28/28 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: bump version 0.41.21.0 → 0.41.24.0

Queue reservation by user — 0.41.22.0 / 0.41.23.0 slots left for
sibling worktrees. Bumps VERSION, package.json, CHANGELOG header,
and the CLAUDE.md entry's version tag in lockstep. llms-full.txt
regenerated.

bun run verify: 28/28 green. Parser tests: 92/92.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-05-27 08:33:50 -07:00
committed by GitHub
co-authored by Claude Opus 4.7
parent 48e1000306
commit 726dfff02c
8 changed files with 582 additions and 32 deletions
+266 -6
View File
@@ -22,6 +22,7 @@ import {
deriveDateContext,
applyPattern,
scorePattern,
scorePatternFull,
} from '../../src/core/conversation-parser/parse.ts';
import { BUILTIN_PATTERNS } from '../../src/core/conversation-parser/builtins.ts';
import type { Page } from '../../src/core/types.ts';
@@ -336,13 +337,272 @@ describe('scorePattern — boundary', () => {
const tg = BUILTIN_PATTERNS.find((p) => p.id === 'telegram-bracket')!;
expect(scorePattern('\n\n \n', tg)).toBe(0);
});
test('caps at SCORING_HEAD_LINES (10) lines', () => {
// 100 telegram lines → still scores 1.0 because only first 10 sampled.
const body = Array.from(
{ length: 100 },
(_, i) => `**[18:${String(i).padStart(2, '0')}] \u{1f464} Alice:** msg ${i}`,
).join('\n');
// T5 reshape (Codex P2 #6): pins BEHAVIOR not the constant value.
// The prior test ("100 matching lines score 1.0") would pass with
// head=10 or head=1000 — it didn't prove anything about the cap.
test('head cap ignores lines past line 10 (10 match + 1 non-match scores 1.0)', () => {
const tg = BUILTIN_PATTERNS.find((p) => p.id === 'telegram-bracket')!;
const matching = Array.from(
{ length: 10 },
(_, i) => `**[18:${String(i).padStart(2, '0')}] \u{1f464} Alice:** msg ${i}`,
);
const body = [...matching, 'plain text outside the head window'].join('\n');
// First 10 lines all match → 10/10. Line 11 was ignored.
expect(scorePattern(body, tg)).toBe(1);
});
test('head cap stops at line 10 (9 non-match + 1 match at line 10 + 100 match after scores 0.1)', () => {
const tg = BUILTIN_PATTERNS.find((p) => p.id === 'telegram-bracket')!;
const nonMatches = Array.from({ length: 9 }, (_, i) => `non-matching prose line ${i}`);
const matchingLate = Array.from(
{ length: 100 },
(_, i) => `**[18:${String(i).padStart(2, '0')}] \u{1f464} Alice:** msg ${i}`,
);
// Line 10 (index 9 in the matching array) IS a match; lines 11-109 are too
// but are past the head cap and don't count.
const body = [...nonMatches, matchingLate[0], ...matchingLate.slice(1)].join('\n');
// Head sees 9 non-matches + 1 match = 1/10 = 0.1. Pre-fix: same result.
// Post-fix: same result (this test pins head-cap behavior, not the new
// fallback path — that's tested separately below).
expect(scorePattern(body, tg)).toBe(0.1);
});
});
// ---------------------------------------------------------------------------
// scorePatternFull — direct unit tests (v0.41.18+ T3 #5)
// ---------------------------------------------------------------------------
describe('scorePatternFull — full-body scoring (v0.41.18+ Codex P1 #1)', () => {
test('empty body scores 0', () => {
const im = BUILTIN_PATTERNS.find((p) => p.id === 'imessage-slack')!;
expect(scorePatternFull('', im)).toBe(0);
});
test('preamble + 20 matching lines scores 20/(preamble + 20)', () => {
const im = BUILTIN_PATTERNS.find((p) => p.id === 'imessage-slack')!;
const preamble = ['## Summary', 'Three sentences.', '> Source: ref', '## Transcript'];
const matches = Array.from(
{ length: 20 },
(_, i) => `**Garry Tan** (2026-01-29 12:00 PM): message ${i}`,
);
const body = [...preamble, ...matches].join('\n');
// 24 total non-blank, 20 match → 20/24 ≈ 0.833
expect(scorePatternFull(body, im)).toBeCloseTo(20 / 24, 5);
});
test('preamble-only-no-match scores 0', () => {
const im = BUILTIN_PATTERNS.find((p) => p.id === 'imessage-slack')!;
const body = '## Summary\nProse paragraph.\n> Blockquote\n## Heading';
expect(scorePatternFull(body, im)).toBe(0);
});
});
// ---------------------------------------------------------------------------
// bold-paren-time pattern (v0.41.18+ D-FOLLOWUP-1.B; closes user-facing
// half of #1533 — the 112 Circleback meeting files at
// ~/git/brain/meetings/*.md with `source: circleback` frontmatter)
// ---------------------------------------------------------------------------
describe('bold-paren-time pattern (Circleback meeting transcripts)', () => {
test('matches **Speaker** (HH:MM): text with frontmatter date', () => {
const body = [
'**Garry Tan** (00:00): Hey, can you hear me?',
'**Participant 2** (02:22): Yeah, just joined.',
'**Garry Tan** (15:09): That makes sense.',
].join('\n');
const r = parseConversation(body, { fallbackDate: '2026-03-19' });
expect(r.phase).toBe('regex_match');
expect(r.matched_pattern_id).toBe('bold-paren-time');
expect(r.messages).toHaveLength(3);
expect(r.messages[0]).toEqual({
speaker: 'Garry Tan',
timestamp: '2026-03-19T00:00:00Z',
text: 'Hey, can you hear me?',
});
expect(r.messages[2]).toEqual({
speaker: 'Garry Tan',
timestamp: '2026-03-19T15:09:00Z',
text: 'That makes sense.',
});
});
test('matches **Speaker** (HH:MM:SS): text shape (Circleback seconds variant)', () => {
const body = [
'**Participant 1** (00:00:00): opening line',
'**Participant 2** (00:00:19): quick reply',
'**Participant 1** (01:23:45): later in the meeting',
].join('\n');
const r = parseConversation(body, { fallbackDate: '2026-04-01' });
expect(r.phase).toBe('regex_match');
expect(r.matched_pattern_id).toBe('bold-paren-time');
expect(r.messages).toHaveLength(3);
// Seconds segment is non-capturing; minute_group still captures the
// minutes component. Time-format is wall-clock 24h on frontmatter date.
expect(r.messages[0].timestamp).toBe('2026-04-01T00:00:00Z');
expect(r.messages[1].timestamp).toBe('2026-04-01T00:00:00Z');
expect(r.messages[2].timestamp).toBe('2026-04-01T01:23:00Z');
});
test('imessage-slack shape still wins over bold-paren-time on overlap', () => {
// Both patterns start with `**` and have parens. The imessage-
// slack regex requires a full date+time inside; bold-paren-time
// requires just `(HH:MM)`. The dates-with-AM/PM shape MUST fall
// through to imessage-slack, not bold-paren-time.
const body = '**Alice Example** (2024-03-15 9:00 AM): hello world';
const r = parseConversation(body);
expect(r.phase).toBe('regex_match');
expect(r.matched_pattern_id).toBe('imessage-slack');
expect(r.messages).toHaveLength(1);
expect(r.messages[0].text).toBe('hello world');
});
test('meeting page with preamble + bold-paren-time transcript hits fallback', () => {
// Real Circleback shape: ## Summary + blockquote + ## Transcript
// before the bold-paren-time chat. Same fallback gate that
// closes #1533 must work for this pattern too.
const preamble = [
'## Summary',
'Meeting covered Q1 roadmap discussion.',
'> Source: circleback meeting #7411053',
'## Topics Discussed',
'- Roadmap',
'- Hiring',
'## Transcript',
];
const transcript = Array.from(
{ length: 20 },
(_, i) => `**Participant 2** (${String(Math.floor(i / 6)).padStart(2, '0')}:${String((i * 11) % 60).padStart(2, '0')}): transcript line ${i}`,
);
const body = [...preamble, ...transcript].join('\n');
const r = parseConversation(body, { fallbackDate: '2026-03-19' });
expect(r.phase).toBe('regex_match');
expect(r.matched_pattern_id).toBe('bold-paren-time');
expect(r.messages).toHaveLength(20);
});
});
// ---------------------------------------------------------------------------
// parseConversation — full-body fallback (v0.41.18+ #1533 + Codex P1 #1, #2, #8)
// ---------------------------------------------------------------------------
describe('parseConversation — full-body fallback', () => {
// T3 #1: IRON-RULE regression pin for #1533. Pre-fix this returns
// no_match because head 10 sees only preamble.
test('#1533: meeting page with ## Summary + blockquote + ## Transcript before chat hits fallback', () => {
const preamble = [
'## Summary',
'This meeting covered Q1 roadmap discussion.',
'Three engineers participated in the call.',
'Action items were captured during the conversation.',
'> Source: [meeting recording](https://example.com/rec/123)',
'## Topics Discussed',
'- Product roadmap for Q1',
'- Engineering team allocation',
'- Customer feedback synthesis',
'## Transcript',
];
const transcript = Array.from(
{ length: 20 },
(_, i) => `**Garry Tan** (2026-01-29 12:00 PM): line ${i}`,
);
const body = [...preamble, ...transcript].join('\n');
const r = parseConversation(body);
expect(r.phase).toBe('regex_match');
expect(r.matched_pattern_id).toBe('imessage-slack');
expect(r.messages).toHaveLength(20);
});
// T3 #2: diagnostic now reports total_non_blank - matched, not total.
test('#1533: unmatched_line_count subtracts matched messages after fallback', () => {
const preamble = [
'## Summary',
'Prose A.',
'Prose B.',
'> Blockquote',
'## Transcript',
];
const transcript = Array.from(
{ length: 20 },
(_, i) => `**Garry Tan** (2026-01-29 12:00 PM): line ${i}`,
);
const body = [...preamble, ...transcript].join('\n');
const r = parseConversation(body, { diagnostic: true });
expect(r.phase).toBe('regex_match');
expect(r.unmatched_line_count).toBe(5); // 25 total non-blank - 20 messages = 5
});
// T3 #3: a 50-line essay with no chat shape stays no_match.
test('pure-prose 50-line essay stays no_match (fallback found nothing to anchor)', () => {
const body = Array.from(
{ length: 50 },
(_, i) => `This is the ${i + 1}th paragraph of a pure-prose article.`,
).join('\n');
const r = parseConversation(body);
expect(r.phase).toBe('no_match');
expect(r.messages).toHaveLength(0);
});
// T3 #4: proves "full-body" not just "wider window" — 300-line preamble
// far exceeds any reasonable head-bump alternative.
test('300-line preamble + 50 chat lines hits fallback (any preamble length)', () => {
const preamble = Array.from(
{ length: 300 },
(_, i) => `Preamble paragraph ${i + 1} with prose content here.`,
);
const transcript = Array.from(
{ length: 50 },
(_, i) => `**Garry Tan** (2026-01-29 12:00 PM): chat line ${i}`,
);
const body = [...preamble, ...transcript].join('\n');
const r = parseConversation(body);
expect(r.phase).toBe('regex_match');
expect(r.matched_pattern_id).toBe('imessage-slack');
expect(r.messages).toHaveLength(50);
});
// T3 #6 (Codex P1 #1 + #8): stray-head-match doesn't suppress fallback.
// Pre-fix: irc-classic 0.1 in head → no fallback → irc-classic wins with 1
// message. Post-fix: 0.1 < 0.3 trigger → fallback re-scores → imessage-slack
// wins (50/60 ≈ 0.83 vs irc-classic 1/60 ≈ 0.017).
test('Codex P1 #1: stray irc-classic match in head does not suppress fallback', () => {
const preamble = [
'## Meeting Notes',
'<presenter> Garry Tan opening remarks', // stray irc-classic match
'- agenda item 1',
'- agenda item 2',
'- agenda item 3',
'- agenda item 4',
'- agenda item 5',
'- agenda item 6',
'- agenda item 7',
'## Transcript',
];
const transcript = Array.from(
{ length: 50 },
(_, i) => `**Garry Tan** (2024-01-29 12:00 PM): real transcript line ${i}`,
);
const body = [...preamble, ...transcript].join('\n');
const r = parseConversation(body);
expect(r.phase).toBe('regex_match');
// The critical assertion: imessage-slack wins, NOT irc-classic.
expect(r.matched_pattern_id).toBe('imessage-slack');
expect(r.messages).toHaveLength(50);
});
// T3 #7 (Codex P1 #2): essay with one stray chat-shape line stays
// no_match. 1/301 ≈ 0.003, below SCORING_MIN_ACCEPTANCE (0.05).
test('Codex P1 #2: 300-line essay with one stray chat line stays no_match (acceptance floor)', () => {
const prose = Array.from(
{ length: 150 },
(_, i) => `Essay paragraph ${i + 1} of pure prose with no chat shape.`,
);
const strayChatLine = '**Author Name** (2024-01-01 9:00 AM): stray quoted snippet';
const morePros = Array.from(
{ length: 150 },
(_, i) => `Essay continuation paragraph ${i + 151}.`,
);
const body = [...prose, strayChatLine, ...morePros].join('\n');
const r = parseConversation(body);
// Pre-fix: regex_match with messages.length === 1.
// Post-fix: no_match because 1/301 < 0.05 acceptance floor.
expect(r.phase).toBe('no_match');
expect(r.messages).toHaveLength(0);
});
});