Repository navigation
fix(api): extract mentions from nested blocks and past tables - #846
Conversation
Signed-off-by: dhananjay6561 <[email protected]>
Signed-off-by: dhananjay6561 <[email protected]>
|
Hi @pikann, small fix for mention extraction in the API: mentions in nested list items, or anywhere in content that has a table, weren't notifying anyone. Unit tests are included. Happy to change anything. |
There was a problem hiding this comment.
🟡 Changes recommended
Nested or table-containing comments can trigger agent conversations with empty initial messages because the text parsers do not handle those structures, requiring parser fixes and service-test coverage.
1 open issue
What changed in this PR
Updates the shared BlockNote mention extractor used by comment handling and edit notifications to address #845.
Changes:
- Recursively extracts mentions from nested blocks.
- Decodes each block’s content independently so tables no longer hide surrounding mentions; table-cell mentions remain out of scope.
- Adds tests for top-level and nested mentions, tables, non-array input, and team-only filtering.
| File | Description |
|---|---|
services/api/internal/pkg/mention/mention.go |
Adds recursive traversal and per-block content decoding. |
services/api/internal/pkg/mention/mention_test.go |
Adds regression coverage for extraction and filtering. |
Review effort: Balanced
| } | ||
| } | ||
| } | ||
| mentions = extractFromBlocks(block.Children, mentions) |
There was a problem hiding this comment.
ℹ️ No critical issues — the fix is correct for what it targets; two table-shaped gaps are worth a decision before #845 closes.
Approach: sound — decoding each block's content independently and walking children fixes both reported failures without changing the stored format or the parser's contract.
Reviewed changes
Blockshape:contentbecomesjson.RawMessageandchildren []Blockis added, so a table's{"type":"tableContent",…}object degrades to a skipped block instead of aborting the whole decode.- Recursive extraction: new
extractFromBlockscollects a block's inline mentions, then recurses intochildren(pre-order), so nested list items are covered. - Tests: new external-package
mention_test.gocovers top-level mentions, two-level nesting, a table between two paragraphs, non-array top-level JSON, and team-only filtering with a nested mention.
ℹ️ Table-cell mentions are still not notified, and this PR closes the issue that asks for them
extractFromBlocks visits a table block's children but never its rows[].cells, so a teamMention chip inside a table cell still starts no agent and sends no notification — the same symptom as the nested-block bug being fixed. The linked issue's expected behavior is "Every teamMention in the content is notified (or the agent is started), wherever it sits in the document", and the Fixes #845 body text closes it on merge.
Technical details
# Table-cell mentions remain outside the walk
## Affected sites
- `services/api/internal/pkg/mention/mention.go:57` — `extractFromBlocks` decodes `content` as `[]InlineContent` (skipping the table object) and recurses only into `children`; a cell's inline nodes live at `content.rows[].cells`, so they are never visited.
- `services/api/internal/service/activity/mentions.go:65` — `linkMentions` likewise only rewrites `content` when it is `[]any`, so a plain-text `@handle` typed in a cell is never chipped either. Mentions in cells are therefore dead end to end, not just in extraction.
- `services/api/internal/domain/doc/contenttext.go:136` — an existing table-aware walker for the same content that already handles both cell shapes (`[]any` legacy and `{"type":"tableCell","content":[…]}` produced by @blocknote/core 0.48).
## Required outcome
- Decide explicitly whether cell mentions are in scope. If yes, walk `rows[].cells` for both cell shapes (as `writeBlockContent` already does) and extend `linkMentions` to match. If no, leave #845 open or narrow its expected behavior rather than auto-closing it with this PR.
## Suggested approach (optional)
- The table shape used in the new test fixture, `"cells":[[{"type":"text","text":"cell"}]]`, is the legacy shape; @blocknote/core 0.48 stores cells as `{"type":"tableCell","props":{},"content":[…]}` (see `contenttext_test.go`). If cells are later walked, cover both shapes so the test does not pass on a shape the editor no longer writes.ℹ️ A table in the content still leaves the agent's initial message empty
Now that these mentions actually fire, a doc or task comment containing a table triggers TriggerDocCommentMention / TriggerCommentMention with an empty message: commentText and extractTextFromBlocks still decode content as an inline array and return "" for the whole document on the first table object. Before this fix those comments started no agent at all, so this is a newly reachable degraded path rather than a regression.
Technical details
# Table content blanks the mention-trigger prompt
## Affected sites
- `services/api/internal/service/doc/activity_service.go:226` — `commentText` unmarshals `[]struct{Content []struct{…}}`; a table block's object `content` fails the unmarshal and the function returns `""`. Its result is the `message` passed to `TriggerDocCommentMention`.
- `services/api/internal/service/task/activity_service.go:306` — `extractTextFromBlocks` has the same array-only decode and falls through to the legacy `{"text":…}` branch, also yielding `""`. Its result is passed to `TriggerCommentMention` in `triggerMentionedAgent`.
## Required outcome
- A comment that contains a table plus an @mention should hand the agent its actual text, or the empty-prompt case should at least be a tracked follow-up rather than a silent hole opened by this fix.
## Suggested approach (optional)
- Reuse the tolerant per-block decode added here (or `docdom.ContentText`, which already handles tables and nested children) inside both flatteners.deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀


Fixes #845
Summary
mention.ExtractMentionsFromBlocksonly read each top-level block'scontentas an array of inline items. Two things went wrong:children, such as an indented list item) were skipped.linkMentionsalready walkschildren, so a plain-text@namethere became a chip that never notified anyone.contentis an object, not an array. The wholejson.Unmarshalfailed, so a comment, description or document with any table returned no mentions at all.The function now walks
childrenrecursively. It decodes each block'scontenton its own and skips a block whose content isn't inline content, so a table no longer hides the mentions around it. Mentions inside table cells stay out of scope, the same aslinkMentions.This fixes comment mentions on tasks and documents, and new-mention notifications for task descriptions and documents (
newlyMentionedUserIDs).Tests: new
internal/pkg/mention/mention_test.gocovers top-level mentions, mentions two levels deep inchildren, mentions on both sides of a table, non-array content, and team-only filtering.Type of Change
Checklist