Skip to content

feat(docs): comments on documents - #65

Merged
pulkitxm merged 5 commits into
mainfrom
feat/doc-comments
Jul 24, 2026
Merged

feat(docs): comments on documents#65
pulkitxm merged 5 commits into
mainfrom
feat/doc-comments

Conversation

@pulkitxm

Copy link
Copy Markdown
Member

Add threaded, realtime comments to the internal document reading view, mirroring issue comments.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec7cc6c3-3300-4846-baa6-15a808d22197

📥 Commits

Reviewing files that changed from the base of the PR and between b08cac8 and bb83863.

📒 Files selected for processing (6)
  • apps/web/src/lib/query/use-doc-comments.ts
  • apps/web/src/lib/realtime/delta-bridge.test.tsx
  • apps/web/src/lib/realtime/delta-bridge.tsx
  • packages/core/src/content/doc-comment-service.test.ts
  • packages/core/src/content/doc-comment-service.ts
  • packages/db/src/schema/content.ts
📝 Walkthrough

Walkthrough

Adds document comments with database persistence, authorization, threaded replies, REST endpoints, optimistic client mutations, realtime synchronization, and a document-surface UI for rendering and managing comments.

Changes

Document comment foundation

Layer / File(s) Summary
Persistence and comment service
packages/db/src/schema/content.ts, packages/shared/src/events/sync.ts, packages/core/src/content/doc-comment-service.ts, packages/core/src/realtime/backfill.ts, packages/core/src/content/doc-comment-service.test.ts
Adds the doc_comment table, service operations for listing, creating, updating, and soft-deleting comments, authorization and one-level threading rules, scoped sync actions, backfill loading, and service tests.
API and synchronization contracts
apps/web/src/app/api/docs/..., apps/web/src/lib/query/{keys,schemas,sync,use-doc-comments}.ts, apps/web/src/lib/realtime/delta-bridge.tsx, apps/web/src/lib/query/sync.test.ts
Adds document-comment REST handlers, schemas and query keys, optimistic CRUD hooks, stale-aware sync delta application, realtime cache patching, and synchronization tests.
Comment rendering and document wiring
apps/web/src/features/docs/doc-comments.tsx, apps/web/src/features/docs/doc-comments.test.tsx, apps/web/src/features/docs/doc-surface.tsx
Adds nested comment rendering with reply, edit, and delete actions; passes workspace members into the component; and tests reply rendering and optimistic creation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • Noveum/orbit#12: Also changes realtime delta handling in delta-bridge.tsx, including echo suppression behavior for sync actions.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding document comments to docs.
Description check ✅ Passed The description matches the changeset by describing threaded, realtime document comments in the reading view.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/doc-comments

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (2)
apps/web/src/lib/query/sync.ts (1)

26-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate delta-merge logic for comments vs. doc comments.

docCommentDeltaSchema/applyDocCommentDelta are copy-pasted from commentDeltaSchema/applyCommentDelta with only the reactions field removed. Consider factoring the shared insert/update/delete/staleness logic into a generic helper parameterized by the entity shape, to avoid future divergence between the two code paths.

Also applies to: 175-199

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/lib/query/sync.ts` around lines 26 - 38, Refactor the duplicated
delta processing between docCommentDeltaSchema/applyDocCommentDelta and
commentDeltaSchema/applyCommentDelta into a shared generic helper parameterized
by the entity schema or shape. Preserve each entity’s distinct fields, including
the absence of reactions for document comments, while centralizing insert,
update, delete, and staleness handling so both paths remain behaviorally
consistent.
apps/web/src/features/docs/doc-comments.test.tsx (1)

107-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test doesn't exercise the composer's actual submit wiring.

Calling createMutate(...) directly bypasses DocComments's onSubmit handler that wires the composer to create.mutate. Consider driving this through the rendered composer (type text, click submit) so a regression in the actual wiring would be caught.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/features/docs/doc-comments.test.tsx` around lines 107 - 116,
Update the optimistic comment test around DocComments to submit through the
rendered doc-comment composer instead of calling createMutate directly: enter
“Looks solid” in the composer, trigger its submit control, then retain the
existing mutation-call and pending-comment assertions so the component’s
onSubmit wiring is exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/lib/query/use-doc-comments.ts`:
- Around line 13-26: Update useDocComments to consume
docCommentListSchema.nextCursor and support fetching subsequent comment pages,
exposing the accumulated comments and a way to request more results. Preserve
the existing disabled behavior when docId is null and ensure pagination stops
when nextCursor is absent, rather than silently returning only the first
DOC_COMMENT_PAGE_SIZE comments.
- Around line 46-48: Update the pending ID generation in the optimistic comment
flow to use Bun.randomUUIDv7() instead of the millisecond-based ISO timestamp,
while preserving the existing pending- prefix and onSuccess dedup/removal
behavior.

In `@apps/web/src/lib/realtime/delta-bridge.tsx`:
- Around line 105-113: Update patchDocCommentCaches to extract each cached
query’s docId and ignore actions whose incoming.docId differs before calling
applyDocCommentDelta. Pass the matching docId through the existing cache-update
flow so only the corresponding document’s comments are modified.

In `@packages/core/src/content/doc-comment-service.ts`:
- Around line 74-78: Validate page.cursor against an existing document comment
before adding the pagination filter, and return or throw the established
invalid-cursor error when no matching record exists. Update the cursor-handling
logic in the document comment pagination method, preserving the existing tuple
comparison only for valid cursors.
- Line 73: Update listDocComments to exclude replies whose root comment is
soft-deleted, not just comments matching docId and deletedAt. Extend the query
around the filters construction to join or otherwise validate the parent/root
comment’s deletedAt status, while preserving visibility of non-deleted roots and
their replies.

In `@packages/db/src/schema/content.ts`:
- Line 159: Update the docComment schema’s parentId definition to add a
self-referencing foreign key to the doc_comment table’s id, matching the
doc.parentId pattern and configuring onDelete: 'set null'.

---

Nitpick comments:
In `@apps/web/src/features/docs/doc-comments.test.tsx`:
- Around line 107-116: Update the optimistic comment test around DocComments to
submit through the rendered doc-comment composer instead of calling createMutate
directly: enter “Looks solid” in the composer, trigger its submit control, then
retain the existing mutation-call and pending-comment assertions so the
component’s onSubmit wiring is exercised.

In `@apps/web/src/lib/query/sync.ts`:
- Around line 26-38: Refactor the duplicated delta processing between
docCommentDeltaSchema/applyDocCommentDelta and
commentDeltaSchema/applyCommentDelta into a shared generic helper parameterized
by the entity schema or shape. Preserve each entity’s distinct fields, including
the absence of reactions for document comments, while centralizing insert,
update, delete, and staleness handling so both paths remain behaviorally
consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e27d7a87-fe99-4977-ab52-27497e5b1b9d

📥 Commits

Reviewing files that changed from the base of the PR and between 5efade1 and b08cac8.

📒 Files selected for processing (17)
  • apps/web/src/app/api/docs/[id]/comments/[commentId]/route.ts
  • apps/web/src/app/api/docs/[id]/comments/route.ts
  • apps/web/src/features/docs/doc-comments.test.tsx
  • apps/web/src/features/docs/doc-comments.tsx
  • apps/web/src/features/docs/doc-surface.tsx
  • apps/web/src/lib/query/keys.ts
  • apps/web/src/lib/query/schemas.ts
  • apps/web/src/lib/query/sync.test.ts
  • apps/web/src/lib/query/sync.ts
  • apps/web/src/lib/query/use-doc-comments.ts
  • apps/web/src/lib/realtime/delta-bridge.tsx
  • packages/core/src/content/doc-comment-service.test.ts
  • packages/core/src/content/doc-comment-service.ts
  • packages/core/src/index.ts
  • packages/core/src/realtime/backfill.ts
  • packages/db/src/schema/content.ts
  • packages/shared/src/events/sync.ts

Comment thread apps/web/src/lib/query/use-doc-comments.ts
Comment thread apps/web/src/lib/query/use-doc-comments.ts
Comment thread apps/web/src/lib/realtime/delta-bridge.tsx
Comment thread packages/core/src/content/doc-comment-service.ts Outdated
Comment thread packages/core/src/content/doc-comment-service.ts
Comment thread packages/db/src/schema/content.ts Outdated

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@pulkitxm
pulkitxm merged commit 2c77288 into main Jul 24, 2026
5 checks passed
@pulkitxm
pulkitxm deleted the feat/doc-comments branch July 24, 2026 13:51
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