Skip to content

fix(engine): scope observer DM listing queries - #520

Merged
khaliqgant merged 1 commit into
mainfrom
fix/observer-scope-pushdown
Oct 11, 2026
Merged

khaliqgant merged 1 commit into
mainfrom
fix/observer-scope-pushdown

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • push an observer token's dm_conversation_ids allowlist into the initial DM conversation query
  • enrich participants, message counts, and latest messages only for authorized conversations
  • retain the existing unfiltered workspace-key behavior and D1-safe chunking for large observer allowlists

Why

A Relay Connect observer scoped to one DM still loaded and enriched every DM in the workspace before filtering. In the affected 5,268-conversation workspace that meant 203 sequential D1 statements for a capability allowed to see one conversation.

Validation

  • npm test --workspace @relaycast/engine (Node 22) — 117 files, 1,369 tests passed
  • focused observer/OAuth coverage — 13 tests passed
  • npm run typecheck --workspace @relaycast/engine — clean
  • npm run lint --workspace @relaycast/engine — clean
  • git diff --check — clean

Causal proof

The >100-conversation conformance fixture now checks both a 105-ID observer allowlist and a one-ID observer allowlist under D1's 100-bind ceiling. The one-ID observer returns only its authorized conversation and records exactly five DM-listing statements. Reverting only the engine/route pushdown makes the same test fail with 9 statements instead of 5; restoring the change passes.

Security

The scoped initial query retains the workspace predicate, deduplicates supplied conversation IDs, and keeps the existing observerAllowsConversation post-filter as defense in depth. No observer can load a conversation from another workspace.

Remaining caveat

Unrestricted workspace-key and unscoped observer reads intentionally retain the workspace-wide enrichment path. This PR fixes the narrow observer-link hot path without changing response shape or dashboard polling behavior.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Performance and query-scoping change on an existing read path; authorization still uses workspace bounds plus post-filter, with no new exposure surface.

Overview
GET /v1/dm/conversations/all now applies an observer token’s dm_conversation_ids allowlist in the first conversation query instead of loading and enriching every workspace DM and filtering afterward.

listAllDmConversations accepts optional conversationIds, deduplicates them, returns early when empty, and uses D1-safe chunking when the allowlist is large. The route derives scoped IDs from normalized observer filters (include_dms / dm_conversation_ids) while workspace-key reads stay unscoped; observerAllowsConversation remains as defense in depth.

Conformance coverage adds a single-conversation observer fixture that asserts one returned DM and five listing SQL statements with an id IN (?) predicate on the initial select.

Reviewed by Cursor Bugbot for commit b413333. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T18:25:13.855840Z b413333 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@khaliqgant

Copy link
Copy Markdown
Member Author

@codex review

@codex security review

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f16972b3-edfc-479d-be32-571471cd8ce6

📥 Commits

Reviewing files that changed from the base of the PR and between e4f57b8 and b413333.


📒 Files selected for processing (5)
  • CHANGELOG.md
  • packages/engine/CHANGELOG.md
  • packages/engine/src/__tests__/conformance/connectObserver.test.ts
  • packages/engine/src/engine/dmAll.ts
  • packages/engine/src/routes/workspace.ts

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



📝 Walkthrough

Walkthrough

The workspace DM listing now applies an observer’s conversation allowlist before participant and message enrichment. Requests without an observer retain the workspace-wide listing path.

Changes

Observer-scoped DM listing

Layer / File(s) Summary
Filter DM conversation selection
packages/engine/src/engine/dmAll.ts
listAllDmConversations accepts optional conversation IDs, deduplicates them, and returns no conversations for an empty list. When IDs are provided, the query selects matching workspace conversations before enrichment.
Wire observer filters and verify listing
packages/engine/src/routes/workspace.ts, packages/engine/src/__tests__/conformance/connectObserver.test.ts, CHANGELOG.md, packages/engine/CHANGELOG.md
The route passes the observer’s allowed IDs when DM access is enabled and an empty list otherwise. The conformance test checks the scoped response and SQL filter. Both changelogs describe the patch.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: willwashburn


Merge Risk: ⚪ Minimal · up to b4133

No confirmed issue prevents merging after normal checks; behavior for observer tokens without an explicit DM allowlist remains unverified.

Pre-merge checks | Passed 4 | Failed 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (2 skipped: 2 … 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 and concisely describes the main change: scoping observer DM listing queries.
Description check Passed The description directly explains the query-scoping change, its performance and security impact, validation results, and retained behavior.
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.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (2 skipped: 2 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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

A rabbit checks the DM trail,
One allowed chat hops past the gate.
The others rest beyond the query,
While messages follow the chosen path.
Patch notes rustle in the burrow.

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

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: b41333379b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@khaliqgant
khaliqgant merged commit 16336f3 into main Oct 11, 2026
10 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.

1 participant