Skip to content

feat(server): associate connections with entities (union with feeds)#1158

Merged
buremba merged 2 commits into
mainfrom
feat/connection-entity-association
May 29, 2026
Merged

feat(server): associate connections with entities (union with feeds)#1158
buremba merged 2 commits into
mainfrom
feat/connection-entity-association

Conversation

@buremba
Copy link
Copy Markdown
Member

@buremba buremba commented May 29, 2026

What

Server side of connection↔entity association (mirrors the feeds.entity_ids pattern).

  • entity_ids on create / connect / update actions — cross-org validation via assertEntityIdsInOrg; tri-state clear on update (undefined leaves unchanged, [] clears), matching feeds.
  • List entity_names + the entity_id filter become a UNION of the connection's own entity_ids and its feeds' entity_ids (so existing feed-derived associations keep working and direct tags are added on top).
  • Parse entity_idsnumber[] (Postgres returned the bigint[] as the literal string '{2}'; the UI picker needs a typed array).
  • New integration test connections-cross-org-entity (cross-org reject, in-org set, tri-state clear, union list both ways).
  • Bumps the owletto submodule pointer for the matching UI.

Validation

  • 7/7 integration tests (this suite + feeds-cross-org-entity) on Node 22 against real pgvector.
  • tsc --noEmit (packages/server): clean.
  • Live e2e on an embedded-Postgres stack: created an entity + a tagged connection, verified entity_ids: [2] / entity_names: "Acme Corp" and the entity filter through the real HTTP API; toggled a second entity via the UI and confirmed [2,3] persisted + surfaced under both entities. The serialization bug ('{2}' string → [2]) was caught here and fixed.

Dependency / merge order

Prod's serving DB (owletto) is missing connections.entity_ids due to squashed-baseline drift — repaired by #1157, which must land (and deploy) before this ships to prod. Merge the owletto web PR first, then update this pointer to the merged SHA.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Connections can be tagged with multiple entity IDs on create, connect, and update.
    • Updates can clear all entity tags by providing an empty list.
    • Connection listings aggregate and show entity names from both direct tags and feed-associated entities.
  • Tests

    • Added integration tests covering entity association behavior and cross-organization validation for connections.

Review Change Stack

Add entity_ids to manage_connections create/connect/update (cross-org
validated via assertEntityIdsInOrg, tri-state clear on update); list
entity_names + entity_id filter become a UNION of the connection's own
entity_ids and its feeds' entity_ids; parse entity_ids to number[] so the
API returns a typed array. Bumps owletto pointer for the matching UI.

Depends on the connections.entity_ids drift migration (#1157) for prod DBs.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c174e499-4905-4e8b-8e80-6325a0be2614

📥 Commits

Reviewing files that changed from the base of the PR and between 40e5dfa and 30f5b20.

📒 Files selected for processing (1)
  • packages/owletto

📝 Walkthrough

Walkthrough

Adds optional multi-entity tagging to connections: accept entity_ids on create/connect/update, validate they belong to the same org, persist them to connections.entity_ids, support tri-state update semantics (omit preserves, null/[] clears, array sets), aggregate entity_names from connection and feed tags on list, and add integration tests; also repins packages/owletto.

Changes

Entity ID tagging for connections

Layer / File(s) Summary
API Contract Extensions
packages/server/src/sandbox/namespaces/connections.ts, packages/server/src/tools/admin/manage_connections.ts
ConnectionsConnectInput and ConnectionsUpdateInput gain optional entity_ids fields; create, connect, and update action schemas accept entity_ids?: number[] with documented tri-state semantics.
Write Path: Create and Connect with validation
packages/server/src/tools/admin/manage_connections.ts
Import array parsing/encoding and assertEntityIdsInOrg; handleCreate and handleConnect validate provided entity_ids, derive a bigint[] DB value, and persist into connections.entity_ids on insert.
Write Path: Update with tri-state semantics
packages/server/src/tools/admin/manage_connections.ts
handleUpdate validates provided entity_ids against org ownership, derives entityIdsValue, and updates connections.entity_ids using COALESCE(${entityIdsValue}::bigint[], entity_ids) so undefined preserves, null/[] clears, and array replaces.
Read Path: List query with entity aggregation and filtering
packages/server/src/tools/admin/manage_connections.ts
entity_names now unions c.entity_ids (direct) and feed-level entity IDs (feed-derived); entity_id filter matches either source; list results normalize entity_ids via parsePgNumberArray.
Integration tests for entity tagging behavior
packages/server/src/__tests__/integration/connections-cross-org-entity.test.ts
Adds tests and a toIds helper that verify cross-org rejection, update tri-state semantics (persist, omit-preserve, explicit-clear), direct-entity listing, and feed-derived entity listing.
Subproject repin
packages/owletto
Repin of the packages/owletto subproject reference to a new commit hash.

Possibly related PRs

  • lobu-ai/lobu#1146: Introduces similar cross-org entity ID validation patterns for manage_feeds and manage_watchers using assertEntityIdsInOrg.

🐰 I hopped through code and pulled a thread,
Cleared cross‑org hops where foreign tags once spread,
Three states I nibble—keep, clear, or set,
Feeds and direct tags now both counted in net,
A carrot for tests, and a repin ahead.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding entity association to connections with a union pattern matching feeds.
Description check ✅ Passed The description includes a detailed 'What' section explaining the changes, a comprehensive 'Validation' section documenting testing, and a 'Dependency / merge order' section addressing deployment concerns. All template sections are adequately covered.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/connection-entity-association

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

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

@buremba buremba enabled auto-merge (squash) May 29, 2026 16:16
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/server/src/tools/admin/manage_connections.ts (1)

195-200: 💤 Low value

Schema description mentions null but schema doesn't accept it.

The description says "Pass [] (or null) to clear" but Type.Optional(Type.Array(...)) only accepts undefined or an array—null would fail TypeBox validation. Consider updating the description to just "Pass [] to clear all links; omit to leave unchanged."

🤖 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 `@packages/server/src/tools/admin/manage_connections.ts` around lines 195 -
200, The schema description for the entity_ids property is inconsistent: it
claims "Pass [] (or null) to clear" but the schema uses
Type.Optional(Type.Array(...)) which does not accept null. Update the
description text on the entity_ids field to remove "or null" (e.g., "Pass [] to
clear all links; omit to leave unchanged") so it matches the
Type.Optional(Type.Array(Type.Number())) validation, or alternatively change the
schema to accept null by wrapping with Type.Union([Type.Array(...),
Type.Null()]) if you intend to allow null; make this change where entity_ids is
defined.
🤖 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.

Nitpick comments:
In `@packages/server/src/tools/admin/manage_connections.ts`:
- Around line 195-200: The schema description for the entity_ids property is
inconsistent: it claims "Pass [] (or null) to clear" but the schema uses
Type.Optional(Type.Array(...)) which does not accept null. Update the
description text on the entity_ids field to remove "or null" (e.g., "Pass [] to
clear all links; omit to leave unchanged") so it matches the
Type.Optional(Type.Array(Type.Number())) validation, or alternatively change the
schema to accept null by wrapping with Type.Union([Type.Array(...),
Type.Null()]) if you intend to allow null; make this change where entity_ids is
defined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a1fb9ab-2640-4a12-ba9c-02fb4fb700b7

📥 Commits

Reviewing files that changed from the base of the PR and between 1d7d69f and 40e5dfa.

📒 Files selected for processing (4)
  • packages/owletto
  • packages/server/src/__tests__/integration/connections-cross-org-entity.test.ts
  • packages/server/src/sandbox/namespaces/connections.ts
  • packages/server/src/tools/admin/manage_connections.ts

@buremba buremba merged commit 4fb67f7 into main May 29, 2026
22 of 23 checks passed
@buremba buremba deleted the feat/connection-entity-association branch May 29, 2026 16:19
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

2 participants