Skip to content

feat(organization-search): run organization search tools in workflows as the run's person - #10534

Merged
waleedlatif1 merged 6 commits into
stagingfrom
feat/organization-search-foundation
Dec 1, 2026
Merged

waleedlatif1 merged 6 commits into
stagingfrom
feat/organization-search-foundation

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • New organization_delegated principal variant for the executor, minted by createExecutorOrganizationPrincipal. It binds the executor delegation first, so the workflow, run and deployment are re-validated. It then requires a Sim user subject and takes the organization from the workflow's workspace, never from tool input. A run with no person (schedule, webhook, workspace API key, external chat sender) fails with the existing subject_user_required fault.
  • authorizeOrganizationOperation gets an executor branch: lifetime capped at the executor delegation TTL (now one shared constant in @sim/auth), and workflowId/workspaceId scope required.
  • executor is admitted on the organization forms of knowledge.search, knowledge.documents.read, organization.people.list and organization.people.get. Knowledge operations now declare their delegated services per operation.
  • New "Organization Search" block (type organization) with operations search, read_document and search_people. These run the tools organization_search, organization_read_document and organization_search_people from the internal tool family in lib/internal/organization-search/. Adding an operation means adding a tool id, a handler, a tool config and a block option.
  • The Search MCP search/read_document implementations moved into lib/knowledge/mcp/organization-tools.ts so MCP and workflows return the same shape. MCP behavior is unchanged.
  • Migration 0477 widens the organization_search_mcp_invocation tool_name check to include search_experts, list_my_activity and list_my_chat_history, ahead of those tools. It swaps the check NOT VALID, then COMMIT, then VALIDATE, the same as 0475.
  • Mothership: no change needed for this PR. The block is Sim-only; the Assistant tools for the new operations come in later PRs.

Type of Change

  • New feature

Testing

  • lib/internal/organization-search/execute-tool.integration.ts runs against real Postgres. It covers a run as the person finding a colleague, a scheduled run being refused, a workflow outside any organization being refused, a non-member being refused, the organization coming from the workflow rather than the context, delegations that are too long-lived or missing workflow/workspace scope being refused, and an operation that doesn't admit workflows refusing them. Each guard was reverted locally and its test went red.
  • Unit tests: lib/knowledge/mcp/server.test.ts, server.protocol.test.ts, lib/internal/principals/executor.test.ts, organization-authorization.test.ts, blocks/blocks.test.ts, registry.server.test.ts, tools/request-transport.test.ts, tools/metadata.test.ts
  • bun run generate, bun run lint, check:migrations, check-block-registry origin/staging, check-canvas-sentences --block=organization, and these audits: tool-effects, boundaries, file-names, comment-hygiene, utils, explicit-any, source-conventions, tool-registry-boundary, test-patterns, integration-catalog, client-boundary, organization-egress. Full type-check and audits are left to CI.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Dec 1, 2026 5:48am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with no new blocking issue found.RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge, with no new blocking issue found.

Summary

Adds Organization Search tools that run as the person who started the workflow.

  • Workflow tools use the run’s person to read its organization data.
  • Workflows gain an Organization Search block with three operations.
  • Search MCP and workflows share search and document-reading functions.
  • Search MCP invocation records accept three more tool names.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Workflow tool call] --> B[Check executor delegation]
  B --> C{Run has a Sim user?}
  C -- No --> D[Refuse call]
  C -- Yes --> E[Get organization from workflow workspace]
  E --> F[Check Search availability]
  F --> G[Check membership and allowed operation]
  G --> H[Search sources, read documents, or find people]
  H --> I[Remove protected secrets from result]
  I --> J[Return workflow output]
Loading

Reviews (5) · Last reviewed commit: "fix(organization-search): import blockFi..." · Reviewed by Greptile

Comment thread apps/sim/tools/organization/search.ts Resolved

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 39 files

This PR changes authentication, authorization, or input validation. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 39 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/blocks/blocks/organization.ts Resolved
Comment thread apps/sim/tools/organization/search.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/blocks/blocks/organization.ts Resolved

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 39 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/blocks/blocks/organization.ts Resolved
… as the run's person

- organization_delegated executor principal, minted from a bound executor delegation; the organization comes from the workflow's workspace, a run without a person fails with subject_user_required
- executor admitted on organization knowledge search, document read, and people list/get
- Organization Search block (type organization): search, read_document, search_people, sharing the Search MCP tool implementations
- widen the Search MCP activity tool_name check for search_experts, list_my_activity, list_my_chat_history
…le results, pass native queries

- workflow Organization Search tools require Search for the organization, as MCP and the Assistant do
- search_people imports query provenance and projects its result like search and read_document
- organization_search accepts nativeQueries so a workflow can follow account cursors
- bound documentIds to 1-10 in the tool schema; declare the actorless refusal; rename the raw call field
@waleedlatif1
waleedlatif1 force-pushed the feat/organization-search-foundation branch from 0b9ec3d to 558995c Compare December 1, 2026 05:30
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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 issues found across 39 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/blocks/blocks/organization.ts Resolved
Comment thread apps/sim/tools/organization/types.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 39 files

Confidence score: 3/5

  • organization.ts leaves searchDocumentIds in the mapped payload, but the Organization Search handler’s strict schema does not allow it. Remove the extra field so validation can accept the payload.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/blocks/blocks/organization.ts">

<violation number="1" location="apps/sim/blocks/blocks/organization.ts:210">
P2: `searchDocumentIds` remains in the mapped payload alongside its converted `documentIds` value. Because the Organization Search handler validates against a strict schema that does not declare `searchDocumentIds`, filling Only Documents causes the workflow search to fail; remove block-only fields before returning the tool payload.</violation>
</file>

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/blocks/blocks/organization.ts Resolved
@waleedlatif1
waleedlatif1 merged commit b65eb1f into staging Dec 1, 2026
87 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/organization-search-foundation branch December 1, 2026 07:15

This branch was previously deployed

1 inactive deployment
Preview — bd964cf4 Deployed Dec 1, 2026 by vercel[bot]
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