Skip to content

fix(brain): strip claw save/merge trigger prefix in edit-sync re-extraction#52

Merged
topcoder1 merged 1 commit into
mainfrom
worktree-fix-claw-prefix-strip
Apr 28, 2026
Merged

fix(brain): strip claw save/merge trigger prefix in edit-sync re-extraction#52
topcoder1 merged 1 commit into
mainfrom
worktree-fix-claw-prefix-strip

Conversation

@topcoder1
Copy link
Copy Markdown
Owner

Why

Spotted during PR 47/PR 51 live verification on 2026-04-28: edits to claw-saved messages produce KUs whose text starts with the literal `claw save ` prefix, whereas the original ingest correctly stripped it.

Live repro (KUs from real Signal Note-to-Self traffic):

KU id text
`01KQB6KMDGCZ4N…` (original) `Pay $5,000 to Acme by Friday` ✓
`01KQB6MHCZBCD…` (after edit) `claw save Pay $7,500 to Acme by Monday` ✗

The original ingest path (signal.ts/discord.ts text triggers) emits `chat.message.saved` with `text = body.match(/^claw\s+save\b\s*(.*)$/i)[1].trim()`. The edit-sync handler in src/brain/chat-edit-sync.ts re-ran `extractPipeline` on `evt.new_text` directly, which carries the full edited body including the `claw save ` prefix. Result: prompt and KU text drift.

Fix

Tiny helper `stripClawTriggerPrefix(s)` mirroring the channel-side regex. Applied to:

  • single-message edits (`text = strippedNewText`)
  • windowed edits (`rebuildWindowTranscript(payload, msg_id, strippedNewText)`)

Test plan

  • `npm run build` clean
  • 19/19 chat-edit-sync tests pass (+2 regressions: claw save and claw merge prefix strip; LLM caller used as a spy to assert the prompt doesn't carry the prefix)
  • Live: re-run the Test B sequence and verify the new KU text matches the old (no `claw save ` prefix)

Related

Surfaced after merging #41 (PR 4 chat edit/delete sync) and #51 (sync envelope timestamp fallback). Verified live by #47 (sendReply ack wiring).

🤖 Generated with Claude Code

…action

When a user edits a message originally sent via `claw save <text>`, the
edit envelope carries the FULL edited body (`claw save <new text>`),
not just the tail. The original ingest path stripped `claw save ` before
emitting `chat.message.saved`, but PR 4's edit-sync handler re-ran
extractPipeline on the raw new_text — producing KUs whose text included
the literal `claw save ` prefix, inconsistent with the original.

Live repro on 2026-04-28:
- Original: `claw save Pay $5,000 to Acme by Friday`
  → KU text: `Pay $5,000 to Acme by Friday` ✓
- Edit:    `claw save Pay $7,500 to Acme by Monday`
  → New KU text: `claw save Pay $7,500 to Acme by Monday` ✗

Add a small `stripClawTriggerPrefix(text)` helper used both for the
single-message path and inside `rebuildWindowTranscript`. Same regex
shape the channel-side text trigger uses, so KU text stays consistent
across original ingest + edit re-extraction.

Two regression tests cover save and merge prefixes; LLM caller used as
a spy to verify the prompt doesn't carry the prefix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@topcoder1 topcoder1 merged commit 1c0488b into main Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant