[Fix] Slack-started tasks get 403 "User context required" when creating or updating environments - #188
Merged
mrubens merged 1 commit intoJul 11, 2026
Conversation
Contributor
Author
|
No code issues found. See task Reviewed the shared |
mrubens
marked this pull request as ready for review
July 11, 2026 13:48
mrubens
requested review from
brunobergher,
daniel-lxs and
mrubens
as code owners
July 11, 2026 13:48
8 tasks
mrubens
deleted the
fix/environment-writes-live-acting-user-1mga6gt1092gj
branch
July 12, 2026 04:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Tasks started from chat surfaces (Slack app mentions and other channel auto-start paths) can now create and update environments through the MCP endpoints.
POST /api/mcp/environmentsandPATCH /api/mcp/environments/:idpreviously returned 403 "User context required" for every Slack-started task, because those runs are enqueued withskipInitialActingUser: trueand dequeued before an acting user is attached — so their run tokens are minted as the deployment service principal with no mint-time user claim, which was the only identity the handlers accepted.Both handlers now resolve the effective human through a shared
resolveEnvironmentWriteUserIdhelper: prefer the livetask_runs.actingUserId(via the MCP proxy's existingresolveActingUserIdOrNull), fall back to the token's mint-time claim, and still return 403 when no human actor is resolvable. Environment writes remain forbidden for pure deployment-principal automation.Why this change was made
The live
actingUserIdis the codebase's established source of truth for "which human is driving this run" — it feeds actor-scoped credential resolution and is written only by trusted server-side writers (web steer, follow-up delivery); run tokens cannot reassign it. The environment write handlers were the outlier in requiring frozen mint-time attribution, which made every Slack-launched task unable to manage environments even when a linked user was actively driving it. The resolved user only feeds deployment-scoped attribution (createdByUserIdon the environment and its config-version audit rows), so no per-user privilege is granted; the task-control handlers (launchTask, sendMessage, steerMessage, task-stop) act as a user and intentionally keep their stricter gating.How it was tested
New handler tests cover both endpoints: deployment-principal run tokens are rejected with no live actor, accepted once a live actor is attached, mint-time fallback works, user auth tokens skip the lookup entirely, and the persisted
createdByUserIdprefers the live actor over a differing mint-time claim (14/14 passing).pnpm lintandpnpm check-typespass.Impact
Slack-started Roomote tasks asked to set up or patch environments can now do so once the requesting user's messages have attached them as the run's acting user, instead of dead-ending on a 403 the task cannot recover from. Web-launched tasks and dashboard flows are unchanged, and automation-only runs with no human actor are still rejected.