Skip to content

fix(slack): resolve direct-token selector contexts server-side - #7115

Closed
BillLeoutsakosvl346 wants to merge 4 commits into
fix/server-resolved-selector-contextfrom
fix/server-resolved-slack-selectors
Closed

fix(slack): resolve direct-token selector contexts server-side#7115
BillLeoutsakosvl346 wants to merge 4 commits into
fix/server-resolved-selector-contextfrom
fix/server-resolved-slack-selectors

Conversation

@BillLeoutsakosvl346

@BillLeoutsakosvl346 BillLeoutsakosvl346 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Stacked on #7095. Review the diff against the PR1 branch. Do not merge until #7095 lands and this PR is rebased and retargeted to staging.

Summary

  • Migrate Slack Channel and User selectors to PR1's authorized server-side context resolver.
  • Support OAuth/custom-bot credentials and workflow-scoped literal or exact-reference direct bot tokens.
  • Add raw-dependency propagation only where Slack needs it, while rejecting runtime block-output references before any selector request.
  • Keep Slack routes, credential binding, selector setup changes, and behavior-focused tests isolated in this PR.
  • Export the named selector credential input type required by the contract boundary without changing the wire schema.

Security behavior

  • Direct bot tokens require an authorized active workflow; credential-backed selectors may use PR1's workflowless session/credential scope.
  • Credentials are bound to Slack OAuth or Slack custom-bot service accounts before token/provider access.
  • Query cache identity uses opaque revisions; literal or resolved token plaintext is absent from query keys.
  • Missing and inaccessible references return the same sanitized selector error.
  • When an authorized stored credential cannot refresh an access token, Channel and User routes preserve the existing 401 error and add authRequired: true; unrelated authorization and direct-token failures are unchanged.
  • Successful personal/workspace environment mutations now invalidate mounted selector, canvas-label, and workflow-search caches through PR1, so an unchanged {{KEY}} refetches without exposing its value.

Focused coverage

  • Channel/User option mapping and channel visibility filtering.
  • Direct-token workflow denial and runtime-reference request suppression.
  • OAuth, custom-bot, literal-token, and referenced-token credential branches.
  • Workflowless stored-credential route behavior and provider mismatch.
  • Null token-refresh behavior plus a Channel/User route matrix proving the 401 reauthorization marker is preserved and Slack is never called.
  • Raw dependency transform and concise opaque-revision/token-privacy assertions.

Verification

  • Provider-focused Vitest: 3 files, 24 tests passed.
  • App type-check passed.
  • Root lint/format, strict API validation, client-boundary, React Query, and git diff --check passed on the combined stack.
  • Combined full repository tests passed on the final head: 19/19 tasks; app 2,368 files passed, 3 skipped; 34,842 tests passed, 46 skipped.
  • Provider-focused combined selector suites: 15 files, 75 tests passed.
  • All ten pairwise child diff intersections are empty.

Browser verification

  • After the freshness restack, a combined Jira smoke confirmed exact raw references still reach dedicated selector routes and provider/authorization failures stay sanitized. The exact mounted same-reference mutation is covered by PR1's real QueryClient regression because this local account cannot edit Secrets through the UI.
  • An existing Slack OAuth credential loaded real channel options in a workflow and in a workflowless knowledge connector.
  • Changing between two deterministic invalid literal direct tokens caused separate provider requests and returned invalid_auth without echoing either token.
  • An exact runtime <block.output> token reference produced no selector request after prior retries settled.
  • The existing workflow was restored to its original OAuth account and auth mode; no disposable Slack connector was saved.

@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 27, 2026 1:00am

Request Review

@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-selector-context branch from ad5a672 to 0b8f18c Compare August 26, 2026 20:21
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-slack-selectors branch from 939feb5 to 13c5f6a Compare August 26, 2026 20:21
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-selector-context branch from fafded6 to 0486f57 Compare August 26, 2026 22:25
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-slack-selectors branch from 13c5f6a to d035b0e Compare August 26, 2026 22:25
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-selector-context branch from 0486f57 to 17726cb Compare August 26, 2026 23:28
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-slack-selectors branch from d035b0e to 50ffc7a Compare August 26, 2026 23:28
@BillLeoutsakosvl346
BillLeoutsakosvl346 marked this pull request as ready for review August 26, 2026 23:32
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR moves Slack channel and user selectors onto authorized server-side credential resolution while keeping direct tokens and references out of client cache identity.

  • Supports workflow-scoped direct bot tokens and workflowless authorized Slack credentials.
  • Rejects runtime block-output references before selector requests.
  • Preserves reauthorization responses and provider-specific credential validation.
  • Adds focused route, resolver, context-transform, cache-privacy, and filtering tests.

Confidence Score: 5/5

The reviewed changes appear safe to merge after the documented stacked-PR dependency and retargeting steps are completed.

No blocking failure remains; the previously reported missing named input alias is now exported in the required form.

Important Files Changed

Filename Overview
apps/sim/lib/api/contracts/selectors/slack.ts Exports the named Slack selector credential schema and canonical input alias requested by the prior review thread without changing the wire schema.
apps/sim/lib/selectors/server/slack-credential.ts Centralizes authorized resolution of direct tokens, environment references, OAuth credentials, and custom-bot credentials.
apps/sim/app/api/tools/slack/channels/route.ts Migrates channel retrieval to authenticated server-side credential resolution while preserving channel visibility behavior.
apps/sim/app/api/tools/slack/users/route.ts Migrates user retrieval to authenticated server-side credential resolution and preserves sanitized failure responses.
apps/sim/hooks/selectors/providers/slack/selectors.ts Marks Slack credential context for server resolution and uses opaque selector cache scope rather than credential plaintext.
apps/sim/hooks/selectors/providers/slack/context.ts Maps raw legacy Slack authentication dependencies while suppressing unsupported runtime block references.

Sequence Diagram

sequenceDiagram
  participant UI as Slack selector UI
  participant Route as Slack selector route
  participant Auth as Authorized context resolver
  participant Slack as Slack API
  UI->>Route: Raw credential/reference + optional workflowId
  Route->>Auth: Authenticate request and resolve credential context
  alt Unauthorized or unresolved
    Auth-->>Route: Sanitized error
    Route-->>UI: 4xx response
  else Authorized
    Auth-->>Route: Access token and credential metadata
    Route->>Slack: Fetch channels or users
    Slack-->>Route: Provider results
    Route-->>UI: Filtered selector options
  end
Loading

Reviews (2): Last reviewed commit: "fix(slack): preserve selector reauthoriz..." | Re-trigger Greptile

Comment thread apps/sim/lib/api/contracts/selectors/slack.ts

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

All reported issues were addressed across 12 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread apps/sim/app/api/tools/slack/users/route.ts Outdated
Comment thread apps/sim/lib/selectors/server/slack-credential.test.ts
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-selector-context branch from 17726cb to aeaa7ec Compare August 27, 2026 00:17
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-slack-selectors branch from 50ffc7a to 16f984b Compare August 27, 2026 00:17
@BillLeoutsakosvl346
BillLeoutsakosvl346 force-pushed the fix/server-resolved-slack-selectors branch from 16f984b to 5d9a783 Compare August 27, 2026 00:31

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

1 issue found across 12 files

Confidence score: 4/5

  • In apps/sim/app/api/tools/slack/users/route.ts, swallowing Slack’s invalid_auth response prevents the user selector from explaining the authentication failure or guiding reauthorization; preserve a sanitized known error so users can recover.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/app/api/tools/slack/users/route.ts">

<violation number="1" location="apps/sim/app/api/tools/slack/users/route.ts:98">
P2: When Slack rejects a token with `invalid_auth`, this catch hides the provider error, so the user selector cannot surface the authentication failure or guide reauthorization. Preserve a sanitized known error such as `invalid_auth` before falling back to the generic response.</violation>
</file>

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

Re-trigger cubic

Comment thread apps/sim/app/api/tools/slack/users/route.ts Outdated
@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

@cubic-dev-ai review this PR

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

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@greptileai

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

All reported issues were addressed across 12 files

Requires human review: Auto-approval blocked by 1 unresolved issue from a previous review of this commit.

Re-trigger cubic

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

@cubic-dev-ai review this PR

@BillLeoutsakosvl346 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

Choose a reason for hiding this comment

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

No issues found across 12 files

Confidence score: 5/5

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

Re-trigger cubic

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

Closing this stacked implementation while we investigate a provider-agnostic server-side selector gateway. The branches are being preserved for reference and recovery; this PR is superseded by the architecture investigation, not merged.

@waleedlatif1
waleedlatif1 deleted the fix/server-resolved-slack-selectors branch August 27, 2026 18:21
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