Skip to content

fix(api): extract mentions from nested blocks and past tables - #846

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
dhananjay6561:fix/nested-table-mentions
Dec 1, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
dhananjay6561:fix/nested-table-mentions

Conversation

@dhananjay6561

Copy link
Copy Markdown
Contributor

Fixes #845

Summary

mention.ExtractMentionsFromBlocks only read each top-level block's content as an array of inline items. Two things went wrong:

  • Mentions in nested blocks (children, such as an indented list item) were skipped. linkMentions already walks children, so a plain-text @name there became a chip that never notified anyone.
  • A table block's content is an object, not an array. The whole json.Unmarshal failed, so a comment, description or document with any table returned no mentions at all.

The function now walks children recursively. It decodes each block's content on 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 as linkMentions.

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.go covers top-level mentions, mentions two levels deep in children, mentions on both sides of a table, non-array content, and team-only filtering.

Type of Change

  • Other (bug fix)

Checklist

  • The change is focused and scoped.
  • Related documentation is updated (none needed).
  • New structure or direction is explained clearly.
  • I avoided unnecessary detail or premature abstraction.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 03:57
@dhananjay6561

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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

  • Block shape: content becomes json.RawMessage and children []Block is added, so a table's {"type":"tableContent",…} object degrades to a skipped block instead of aborting the whole decode.
  • Recursive extraction: new extractFromBlocks collects a block's inline mentions, then recurses into children (pre-order), so nested list items are covered.
  • Tests: new external-package mention_test.go covers 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.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit b2bb9d2 into Paca-AI:master Dec 1, 2026
6 checks passed
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.

[Bug] Mentions in nested blocks, or in content with a table, are never notified

3 participants