Skip to content

feat(mothership): serve worker calls only for a user and chat sim granted - #10192

Closed
myxamediyar wants to merge 3 commits into
stagingfrom
feat/mothership-run-grant
Closed

myxamediyar wants to merge 3 commits into
stagingfrom
feat/mothership-run-grant

Conversation

@myxamediyar

Copy link
Copy Markdown
Contributor

Summary

  • Sim's Mothership worker routes (memory scope, run control, chat recall, memory notes access, workspace context, integration catalog, task wake, workflow status) and checkpoint control requests took the user, chat and owner the worker named, behind a secret the worker also holds
  • Sim now sends a run grant with every leg it starts: an HS256 JWT over the turn's user, chat and workspace or organization, keyed by HKDF from Sim's auth secret under a label used for nothing else, so only Sim can issue or check one. It lasts a day and is signed synchronously, so dispatch gains no await
  • internalCopilotAuth and the checkpoint executor check it against the identity a call names: a forged or mismatched grant is refused; a missing or expired one is served until MOTHERSHIP_REQUIRE_RUN_GRANT is set, so workers that predate grants keep working while they roll out
  • Long runs are not disrupted: run control renews a verified grant past half its life, after rechecking the chat and the user's access, so a run that keeps checking its control keeps a valid grant however long it runs. Only a grant Sim verified is renewed
  • Contract copies (sim-transport, run-control) gain the header, the control request's grant and the renewal field; .env.example documents the switch

Companion: simstudioai/mothership#981

Type of Change

  • New feature

Testing

  • run-grant.test.ts: a grant admits exactly the identity it names (another user, chat, workspace or organization is refused); a token the worker could mint with the secret it holds is refused; a missing or expired grant is served only until grants are required; a verified grant is renewed past half its life for the same identity, and an unverified call gets none
  • internal.test.ts: identity headers the grant names are admitted, a forged or mismatched grant is refused, and a call without one is refused once grants are required
  • control.test.ts: a checkpoint request whose grant names another chat is refused
  • run.test.ts: every initial and resume leg, for workspace and organization owners, carries a grant that verifies for the turn
  • lib/mothership and lib/core/config suites pass (3267 tests); bun run lint, bun run type-check and bun run check:audits pass

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)

…nted

Sim's worker-facing routes and its checkpoint control requests took the user, chat and owner the
worker named, behind a secret the worker holds. Sim now issues a run grant with every leg it
sends: an HS256 JWT over the turn's user, chat and workspace or organization, keyed by HKDF from
Sim's auth secret under its own label, lasting a day. The worker returns it on each call.

- internalCopilotAuth and the checkpoint executor check the grant against the identity the call
  names: a forged or mismatched grant is refused; a missing or expired one is served until
  MOTHERSHIP_REQUIRE_RUN_GRANT, so workers that predate grants keep working during rollout.
- Run control renews a verified grant past half its life after rechecking the chat and the
  user's access, so a run that keeps checking its control keeps a valid grant however long it
  runs. Only a grant Sim verified is renewed.
- Grants are signed synchronously, so issuing one adds no await to the dispatch path.
@vercel

vercel Bot commented Nov 19, 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 Nov 19, 2026 12:34am UTC

Request Review

@github-actions github-actions Bot added the requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Cross-repo companion check

One or more companion PRs aren't merged into staging yet. Merging this without them will leave copilot and sim out of sync — merge them in lockstep.

  • ❌ simstudioai/mothership#981 — OPEN, not merged (targets staging) — feat(worker): carry sim's run grant on every call to sim

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The changes appear safe to merge.

Summary

Adds signed grants that bind Mothership worker calls to the user, chat, and owner Sim approved, with optional enforcement and renewal for active runs.

  • Each Mothership turn carries a grant for its user, chat, and owner.
  • Worker calls must match the grant for the turn.
  • Active runs get fresh grants before their current ones expire.

No new actionable issues found in the changes since the previous review.

Reviews (2) · Last reviewed commit: "fix(mothership): read the grant switch a..." · Reviewed by Greptile

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

Comment thread apps/sim/lib/core/config/env.ts Resolved
…th secret, and match chatless grants exactly

- MOTHERSHIP_REQUIRE_RUN_GRANT arrives as a string, since env skips validation, so "false" turned
  enforcement on. It is now read with isTruthy.
- A Sim running with DISABLE_AUTH may have no BETTER_AUTH_SECRET. It now issues no grants and
  treats a call's grant as missing, instead of throwing on every leg.
- A grant issued for a turn with no chat matched any chat a call named. A grant's chat must now
  equal the call's, and absent matches only absent.
- Run control renewed grants for runs that had finished without a Stop. It now renews only while
  the run is still going.
- TSDoc on the module's exported names.

Autopsy: the tests set the switch as a boolean, always had an auth secret, issued every grant
with a chat, and checked renewal in the grant module rather than in run control's answer for a
finished run. Each case now has a test that fails without its fix.
@myxamediyar

Copy link
Copy Markdown
Contributor Author

@greptile

@myxamediyar

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@myxamediyar 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 15 files

Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.

Turn on auto-fix | Re-trigger cubic

@myxamediyar

Copy link
Copy Markdown
Contributor Author

Closing for now; deferred. The branch stays if this is picked up again.

@waleedlatif1
waleedlatif1 deleted the feat/mothership-run-grant branch November 19, 2026 01:52

This branch was previously deployed

1 inactive deployment
Preview — 57c9b6ed Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants