Skip to content

feat(actions): assign by email and clear assignees through the API - #1147

Merged
exponential-automerge[bot] merged 4 commits into
mainfrom
feat/action-assignees-api
Nov 18, 2026
Merged

exponential-automerge[bot] merged 4 commits into
mainfrom
feat/action-assignees-api

Conversation

@positonic

@positonic positonic commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Agents create follow-up actions through the CLI/MCP (e.g. candidate follow-ups in a Syntrofi hiring project). Those land with no assignee, so they reach nobody's Today list and a person has to assign them in the app. action.assign / action.unassign and assigneeIds on create already existed, but a caller outside the UI usually knows a colleague's email, not their CUID, and there was no one-call way to clear assignees.

What

  • action.create accepts assigneeEmails, merged with assigneeIds.
  • action.assign accepts emails alongside userIds (either is enough; neither is BAD_REQUEST).
  • action.unassign accepts emails and all: true.

Rules (unchanged containment, documented)

  • Emails resolve case-insensitively to user ids, then run through the same assertAssignableUsers check as ids: project access for a project action, team membership for a team action, workspace membership otherwise. An email reaches no further than an id. An agent key can assign anyone who passes that check in an action it can edit.
  • An unregistered email fails with the same NOT_FOUND message as a registered user who isn't assignable here, so the API is not an oracle for whether an address has an account.
  • On unassign, emails match the action's current assignees only (unknown address = no-op).
  • Update semantics: additive. assign adds, unassign removes, unassign { all: true } clears. No replace-the-set call: an agent adding the requester never silently drops a person a human assigned. Clients get "replace" by clearing, then assigning (the CLI's --clear-assignees --assignee x).

Tests

src/server/api/routers/__tests__/action.test.ts → "assignees by email and clear": member by email (case-insensitive), registered non-member refused, cross-workspace member refused by id, unregistered email answers like a non-member, empty assign refused, unassign all, unassign by email matches current assignees only, create with an unknown email writes nothing, create resolves emails into the create.

Linked PRs (dependency order)

  1. this PR (app)
  2. feat: assign actions to people by id or email, and clear assignees (v1.34.0) exponential-sdk#43: SDK 1.34.0, actions.assign / actions.unassign / create assignees
  3. feat(actions): --assignee on create/update, plus --unassign and --clear-assignees (v1.31.0) exponential-cli#52: --assignee, --unassign, --clear-assignees
  4. feat(actions): assignees on create and update (v0.15.0) exponential-mcp#23: assignees, addAssignees, removeAssignees, clearAssignees

No migration. Assigning by userIds keeps working for older clients.

Agents and other non-UI callers (CLI, MCP) create follow-up actions but
could not say who they are for: they know a colleague's email, not their
user id, and there was no way to clear assignees in one call.

- action.create accepts `assigneeEmails`, merged with `assigneeIds`.
- action.assign accepts `emails` alongside `userIds` (either is enough).
- action.unassign accepts `emails` and `all: true`.

Emails resolve case-insensitively to user ids, then go through the same
assertAssignableUsers containment as ids, so an email reaches no further
than an id. An unregistered email fails with the same NOT_FOUND message
as a registered user who is not assignable here (no registration oracle).
On unassign, emails match current assignees only.

Update semantics stay additive: assign adds, unassign removes, nothing
replaces the set wholesale.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T19:29:05.688366Z e75102a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e75102a2a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/api/routers/action.ts Outdated
Comment on lines +488 to +490
const emailAssigneeIds = assigneeEmails?.length
? await resolveAssigneeEmails(
ctx.db,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve assignee emails after validating the create destination

Any authenticated caller can use action.create with a nonexistent projectId to determine whether an arbitrary email has an account: an unregistered address fails here with Assignee not found in this project, whereas a registered address reaches createAction and fails with Project not found (src/server/services/actions/createAction.ts:127–128). This bypasses the intended indistinguishability between unknown and unassignable addresses without requiring access to any project. Resolve emails after the destination authorization and existence checks, but before writing the action.

Useful? React with 👍 / 👎.

@exponential-automerge

exponential-automerge Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR-Agent: nothing blocking on 1db1256 (2 unresolved finding(s) (2 tagged minor)) — required checks passed, merged.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 1db1256)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

[minor] Duplicated email-resolution logic

assigneeIdsForEmails and resolveAssigneeEmails each re-implement the
same pipeline (normalize/trim/lowercase + dedupe → user.findMany
OR-query with insensitive mode → lowercase byEmail map), differing
only in the final mapping (placeholder id vs throw). The no-oracle
design depends on both resolvers having identical lookup semantics: if
one is later changed (a filter, trim or case-handling fix) without the
other, create and assign resolve the same email differently, and
the equivalence between an unregistered email and a registered
non-assignable user — the property that keeps the API from being an
account-existence oracle — drifts silently. Consider implementing
resolveAssigneeEmails on top of assigneeIdsForEmails (throw
assigneeNotFound(scope) when an id starts with the
unregistered-email: prefix) so the two cannot diverge.

export async function assigneeIdsForEmails(
  db: PrismaClient,
  emails: string[],
): Promise<string[]> {
  const wanted = [...new Set(emails.map((e) => e.trim().toLowerCase()))].filter(Boolean);
  if (wanted.length === 0) return [];

  const users = await db.user.findMany({
    where: { OR: wanted.map((email) => ({ email: { equals: email, mode: "insensitive" as const } })) },
    select: { id: true, email: true },
  });
  const byEmail = new Map(users.map((u) => [u.email?.toLowerCase(), u.id]));
  return wanted.map((email) => byEmail.get(email) ?? `${UNREGISTERED_EMAIL_PREFIX}${email}`);
}

/**
 * Turn assignee emails into user ids, for callers (the CLI, MCP, agents) that
 * know a colleague's email but not their CUID. Case-insensitive.
 *
 * Only resolves; the caller still runs `assertAssignableUsers` on the result,
 * so an email reaches no further than an id would. An email with no account
 * throws the very error `assertAssignableUsers` throws for an account that is
 * not assignable here, so the response cannot tell a caller whether an
 * address is registered somewhere else.
 */
export async function resolveAssigneeEmails(
  db: PrismaClient,
  scope: AssignmentScope,
  emails: string[],
): Promise<string[]> {
  const wanted = [...new Set(emails.map((e) => e.trim().toLowerCase()))].filter(Boolean);
  if (wanted.length === 0) return [];

  const users = await db.user.findMany({
    where: { OR: wanted.map((email) => ({ email: { equals: email, mode: "insensitive" as const } })) },
    select: { id: true, email: true },
  });
  const byEmail = new Map(users.map((u) => [u.email?.toLowerCase(), u.id]));
  return wanted.map((email) => {
    const id = byEmail.get(email);
    if (!id) throw assigneeNotFound(scope);
    return id;
  });
}
[minor] Contract file may be stale

This PR changes the inputs of three procedures — action.create (new
assigneeEmails), action.assign (new emails, userIds now
optional) and action.unassign (new emails and all, userIds now
optional) — but the contract file is regenerated only for
action.assign. If action.create or action.unassign are also
listed as agent procedures in this file, their entries are now out of
sync with the router and the contract test that compares router inputs
against this file will fail (and agent/CLI consumers cannot discover
the new parameters, including the headline assigneeEmails on
create). Worth confirming the regeneration covered every procedure
whose schema changed; if neither create nor unassign is agent-exposed,
this is a non-issue.

  "userIds": {
    "type": "array",
    "items": {
      "type": "string"
    },
    "default": []
  },
  "emails": {
    "type": "array",
    "items": {
      "type": "string",
      "format": "email"
    }
  }
},
"required": [
  "actionId"
✅ Resolved findings

src/server/api/routers/action.ts:487-498

[blocker] Registration oracle in create

resolveAssigneeEmails runs as the first await of action.create, before
createAction performs the workspace write-authorization check (and
workspaceId is free-form input). Any authenticated caller can therefore
determine whether an arbitrary email has an account: an unregistered
address throws NOT_FOUND "Assignee not found in this workspace"
immediately, while a registered one resolves successfully and only then
fails with the (different) workspace-authorization error. This is exactly
the account-existence oracle the PR says it avoids; assign avoids it by
checking edit permission before resolving emails. Resolve emails only
after the caller is authorized to write to the target workspace (e.g.
inside or after createAction's authorization), matching assign.

src/server/api/routers/action.ts:501-503

[minor] Un-deduped assignee ids on create

create merges assigneeIds with email-resolved ids without
deduplicating, while assign dedupes via new Set. Passing the same
person both ways (e.g. assigneeIds: ["u1"] plus
assigneeEmails: ["u1@example.com"]) puts duplicate (actionId, userId)
rows into the assignee write; if that write is a createMany without
skipDuplicates, the unique constraint fails and the call errors. Worth
confirming createAction's assignee write is duplicate-safe; if not,
dedupe the merged array as assign does.

src/server/api/routers/tests/action.test.ts:1857-1864

[minor] Suppressed any in test stub

House rule (TypeScript/ESLint — no any): the new stubAction mock uses
any twice ((args: any) on the mockImplementation and ) as any on its
return), each behind an eslint-disable comment. The disables keep CI
green, but the rule is "no any"; type the mock's argument with a narrow
shape (e.g. { where?: { userId_workspaceId?: { userId?: string; workspaceId?: string } } }) instead of suppressing the lint rule.

PR-Agent blocker: action.create looked emails up before createAction's
workspace write check, so an unregistered email failed early with
NOT_FOUND while a registered one went on to FORBIDDEN, which let any
signed-in user probe whether an address has an account.

On create, an unknown email now becomes a placeholder id that can never
match a user (assigneeIdsForEmails). It fails at assertAssignableUsers,
after authorisation, with the same error as a registered non-member.
assign keeps resolveAssigneeEmails, which already runs after the edit
check.

Also: dedupe ids merged from assigneeIds and assigneeEmails, and type the
test's membership mock instead of suppressing no-explicit-any.
…emails

action.assign now takes optional `emails` and `userIds` defaults to [];
the contract test compares the router's inputs with this file.
@exponential-automerge
exponential-automerge Bot merged commit ae9e43b into main Nov 18, 2026
10 checks passed
@positonic
positonic deleted the feat/action-assignees-api branch November 18, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant