Skip to content

feat(workspace-vars): add workspace scoped environment + fix cancellation of assoc. workspace invites if org invite cancelled#1208

Merged
waleedlatif1 merged 8 commits intostagingfrom
feat/workspace-env-vars
Sep 1, 2025
Merged

feat(workspace-vars): add workspace scoped environment + fix cancellation of assoc. workspace invites if org invite cancelled#1208
waleedlatif1 merged 8 commits intostagingfrom
feat/workspace-env-vars

Conversation

@icecrasher321
Copy link
Collaborator

@icecrasher321 icecrasher321 commented Aug 31, 2025

Summary

  • Add workspace scoped environment that takes precedence
  • Fix issue with cancelling org invites not cancelling associated "bulk" workspace invites.

Keeping migrations separate for clean separation of concerns.

Type of Change

  • Bug fix
  • New feature

Testing

In Progress

Checklist

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

Screenshots

Regular view:
Screenshot 2025-09-01 at 3 01 17 PM

Naming Conflict:
Screenshot 2025-09-01 at 3 01 25 PM

Trying to Save with naming conflict:
Screenshot 2025-09-01 at 3 01 39 PM

Tooltip for making a var workspace scoped:
Screenshot 2025-09-01 at 3 01 49 PM

Envvar dropdown that shows set of all available envvars:
Screenshot 2025-09-01 at 3 02 05 PM

@vercel
Copy link

vercel bot commented Aug 31, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 1, 2025 11:00pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 1, 2025 11:00pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements workspace-scoped environment variables that take precedence over personal environment variables, along with a bug fix for workspace invitation cancellation. The changes introduce a hierarchical environment variable system where workspace-level variables override personal ones during workflow execution.

The implementation adds a new workspace_environment database table to store workspace-scoped environment variables, following the same encryption patterns as personal environment variables but scoped to workspaces. The system maintains backward compatibility by continuing to support personal environment variables while adding workspace-level overrides.

Key architectural changes include:

  • New API endpoints at /api/workspaces/[id]/environment for CRUD operations on workspace environment variables
  • Updated environment store with three new methods: loadWorkspaceEnvironment, upsertWorkspaceEnvironment, and removeWorkspaceEnvironmentKeys
  • Enhanced workflow execution across all contexts (manual, scheduled, webhook, chat) to load both personal and workspace variables with workspace taking precedence
  • New utility functions in lib/environment/utils.ts for merging environment variables with conflict detection
  • UI updates to the settings modal allowing users to manage workspace variables and promote personal variables to workspace scope

The workspace invitation fix addresses a data consistency issue by adding an orgInvitationId column to link workspace invitations with their parent organization invitations. This enables proper cascading cancellation when organization invitations are cancelled, preventing orphaned workspace invitations.

The changes integrate seamlessly with the existing workspace-based architecture, where workflows, chats, and other resources are already scoped to workspaces. This enables teams to share common environment configurations while maintaining individual personal overrides.

Confidence score: 2/5

  • This PR has significant implementation inconsistencies and potential issues that could cause problems in production
  • Score lowered due to type safety violations, inconsistent API implementation patterns, and critical logic bugs in invitation handling
  • Pay close attention to apps/sim/app/api/workspaces/[id]/environment/route.ts and apps/sim/app/api/organizations/invitations/accept/route.ts for type assertions and inconsistent invitation logic

Context used:

Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

24 files reviewed, 8 comments

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 force-pushed the feat/workspace-env-vars branch from 029c460 to f032bdb Compare September 1, 2025 22:44
@vercel vercel bot temporarily deployed to Preview – docs September 1, 2025 22:45 Inactive
@vercel vercel bot temporarily deployed to Preview – docs September 1, 2025 22:55 Inactive
@waleedlatif1 waleedlatif1 merged commit 9ea7ea7 into staging Sep 1, 2025
3 of 4 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/workspace-env-vars branch September 1, 2025 22:57
waleedlatif1 added a commit that referenced this pull request Sep 2, 2025
…tion of assoc. workspace invites if org invite cancelled (#1208)

* feat(env-vars): workspace scoped environment variables

* fix cascade delete or workspace invite if org invite with attached workspace invites are created

* remove redundant refetch

* feat(env-vars): workspace scoped environment variables

* fix redirect for invitation error, remove check for validated emails on workspace invitation accept

* styling improvements

* remove random migration code

* stronger typing, added helpers, parallelized envvar encryption

---------

Co-authored-by: waleedlatif1 <walif6@gmail.com>
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…tion of assoc. workspace invites if org invite cancelled (simstudioai#1208)

* feat(env-vars): workspace scoped environment variables

* fix cascade delete or workspace invite if org invite with attached workspace invites are created

* remove redundant refetch

* feat(env-vars): workspace scoped environment variables

* fix redirect for invitation error, remove check for validated emails on workspace invitation accept

* styling improvements

* remove random migration code

* stronger typing, added helpers, parallelized envvar encryption

---------

Co-authored-by: waleedlatif1 <walif6@gmail.com>
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