Skip to content

fix(alert): skip unchanged prefix nodes while streaming - #620

Open
EnesKartal wants to merge 1 commit into
comarkdown:mainfrom
EnesKartal:fix/alerts-streaming-rescan
Open

EnesKartal wants to merge 1 commit into
comarkdown:mainfrom
EnesKartal:fix/alerts-streaming-rescan

Conversation

@EnesKartal

@EnesKartal EnesKartal commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

The built-in �lert plugin now skips state.reusableNodes during its post hook and only walks the newly parsed tail nodes (state.tree.nodes.slice(state.reusableNodes.length)).

Why

In { streaming: true } mode, state.tree.nodes prepends state.reusableNodes (completed prefix nodes from previous parses that have already run through post hooks) before running post plugins. Because �lert walked the entire state.tree via �isit, every streaming append rescanned all unchanged prefix nodes even when the document contained no alerts.

Added unit tests in est/plugins/alert-streaming.test.ts verifying that unchanged prefix nodes are not revisited during comark:post:alert on incremental appends while streamed alert blockquotes after a reused prefix still transform properly.

Fixes #513


Read this PR faster    Follow each request

Summary by CodeRabbit

  • Bug Fixes
    • Improved alert handling during streamed updates: unchanged paragraph content is preserved, and alerts split across incoming chunks are correctly displayed as note blocks.

@EnesKartal
EnesKartal requested a review from farnabaz as a code owner November 19, 2026 15:24
@coldtea-pr-lens

coldtea-pr-lens Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Architecture

Walkthrough of Alert plugin skips reused streaming prefix nodes, in three steps

Read this PR faster


Data flow

Data flow diagram for comarkdown/comark at b0aaccd

Follow each request


Review

✨ Nothing flagged · reviewed b0aaccd


Tip

The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture… row. Drawing still runs as before
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • After a push, tick Redraw to draw the latest commit
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion
  • Set github.description: false in .github/pr-lens.yml to stop PR Lens adding buttons to your PR descriptions

Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it.  Star PR Lens on GitHub

@vercel

vercel Bot commented Nov 19, 2026

Copy link
Copy Markdown

@EnesKartal is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The alert plugin now skips reusable prefix nodes during traversal when reusable nodes exist. Streaming tests cover prefix preservation, appended text, and alert transformation.

Changes: Streaming alert traversal

Layer / File(s) Summary
Alert traversal and streaming validation
packages/comark/src/plugins/alert.ts, packages/comark/test/plugins/alert-streaming.test.ts
The post hook starts traversal at the reusable-node boundary when one exists. Tests check that traversal does not read watched prefix tags, that the prefix node retains its identity, and that a streamed alert becomes a note blockquote.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to b0aac

The alert plugin now skips unchanged prefix nodes during streaming appends, which reduces redundant work while still transforming alerts. No merge-blocking risk was found, and the new streaming tests cover the changed behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(alert): skip unchanged prefix nodes while streaming" matches the main change. The alert plugin now skips reusable prefix nodes during streaming, so only the newly parsed tail is process…
Linked Issues check Passed Issue #513 requires the alert plugin to skip unchanged nodes during streaming appends while keeping alert transforms working. At the reviewed head, packages/comark/src/plugins/alert.ts sets start to s…
Out of Scope Changes check Passed The change set, as described by the PR summary, touches only the alert plugin (+3/-1 lines) and a new streaming test file (+75 lines). The alert plugin change is the slice that implements the #513 req…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix(alert): skip unchanged prefix nodes while streaming" matches the main change. The alert plugin now skips reusable prefix nodes during streaming, so only the newly parsed tail is processed. The title is specific, short, and names the plugin and the streaming context. It does not cover the added streaming tests, which is acceptable.

Full details: Linked Issues check

Explanation

Issue #513 requires the alert plugin to skip unchanged nodes during streaming appends while keeping alert transforms working. At the reviewed head, packages/comark/src/plugins/alert.ts sets start to state.reusableNodes?.length ?? 0. When start > 0, the visitor walks only state.tree.nodes.slice(start), so reused prefix nodes are not visited. When no reusable nodes exist, the full tree is visited, so non-streaming behavior is unchanged. The alert marker handling (the [!NOTE]-style span and paragraph branches) is unchanged and still runs on the tail nodes, so alerts continue to transform. The PR summary reports two added tests in packages/comark/test/plugins/alert-streaming.test.ts: one checks that the prefix node tag is not read during an append, and one checks that a streamed alert after a reused prefix becomes a note blockquote. I did not read the test file, and I did not run the reproduction (verify.sh) or the performance check. The code change matches the requirement, but the measured effect is not independently confirmed. The diff tool was unavailable, so I read the head file directly and did not confirm the base version.

Full details: Out of Scope Changes check

Explanation

The change set, as described by the PR summary, touches only the alert plugin (+3/-1 lines) and a new streaming test file (+75 lines). The alert plugin change is the slice that implements the #513 requirement. The tests support that same requirement. No unrelated files or behavior changes are reported. The head version of alert.ts contains no changes beyond the reusable-node slicing and the marker logic that existed before. The diff tool was unavailable, so the base-to-head comparison relies on the PR summary and the head file content.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 44f1371c-6a44-4b43-8056-3e7c604d5df7
Commits

Reviewing files that changed from the base of the PR and between 382d146 and b0aaccd.

Files selected for processing: 2

  • packages/comark/src/plugins/alert.ts
  • packages/comark/test/plugins/alert-streaming.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@620

@comark/angular

npm i https://pkg.pr.new/@comark/angular@620

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@620

@comark/html

npm i https://pkg.pr.new/@comark/html@620

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@620

@comark/react

npm i https://pkg.pr.new/@comark/react@620

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@620

@comark/vue

npm i https://pkg.pr.new/@comark/vue@620

commit: b0aaccd

@codspeed

codspeed Bot commented Nov 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 44 untouched benchmarks


Comparing EnesKartal:fix/alerts-streaming-rescan (b0aaccd) with main (382d146)

Open in CodSpeed

@farnabaz

Copy link
Copy Markdown
Collaborator

Thanks @EnesKartal, the fix is correct and the tests are great 🙏

One suggestion before we merge: instead of building a new tree with nodes.slice(start), could we teach visit / visitAsync to skip top-level nodes? Something like an optional 4th argument:

export function visit(document, checker, visitor, options?: { skip?: number })
export async function visitAsync(document, checker, visitor, options?: { skip?: number })

// in walkGenerator
let i = options?.skip ?? 0

and then in the alert plugin:

visit(state.tree, checker, visitor, { skip: state.reusableNodes?.length ?? 0 })

Why:

  • no extra array copy on every streaming parse
  • removals and replacements from the visitor (return false / returning a node, and the depth-cap removal) keep landing on the real state.tree.nodes; with the sliced copy they would be silently lost
  • other post plugins that use visit can then skip reused nodes the same way

Could you also add a case in test/visit.test.ts for skip, including a removal or replacement after the skipped nodes? And update docs to match new API (https://comark.dev/plugins/custom/ast-api)?

Thanks!

This branch has not been deployed

No deployments
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.

Alerts rescan unchanged paragraphs during streaming

2 participants