Skip to content

fix(board): give a task's run to its assignee, not to whoever pressed Run - #80

Merged
artempartos merged 4 commits into
developfrom
fix/mcp-task-trigger-actor
Aug 10, 2026
Merged

artempartos merged 4 commits into
developfrom
fix/mcp-task-trigger-actor

Conversation

@artempartos

@artempartos artempartos commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

The symptom

Press Run on a board card assigned to someone else and the run starts under you, not under the assignee.

Why it matters

run.user is not a label. SessionService.create_for_workflow_step reads it to choose:

  • the agent credential the container is handed (SessionCompany.agent_credentials_for),
  • the agent runtime (run_membership(...).default_agent_runtime),
  • the model (run_credentials(...).first.agent_type).

So it decides which account executes the work and which one is billed.

And it does not stay contained. Every session tool resolves its own actor as task.assignee || workflow_run&.user (InternalTools::BoardMoveTask#resolve_actor, BoardAddComment, BoardAttachAsset), where workflow_run is the run of the session doing the work. A run owned by the wrong account therefore has an agent that moves every unassigned card as that account → which fires that column's auto-trigger as that account → which starts another run owned by it → whose agent does the same. One wrong owner walks the board.

Provenance (not a regression from #77)

Both are the same underlying mistake — conflating "who is allowed to launch this" with "who owns what gets launched" — so this fixes it once rather than per caller.

The fix

One rule, TaskService#run_owner_for: the task's assignee, falling back to whoever asked, skipping a candidate who

  • has no active membership in the task's company (no agent credential there → the container starts with nothing to authenticate as and fails opaquely), or
  • holds the viewer role (the platform refuses to let a viewer launch a session at all, so attributing a run to one smuggles in work they could not have started).

Every entry point inherits it: the card's Run button, trigger_task_workflow, and a column auto-trigger from a card move or a resolved gate. The same task now costs the same account however it started.

Two supporting details:

  • requested_by_id goes into the trigger event's data, so attributing the run to the assignee does not lose who asked. TriggerEvent has only one actor column, and it now means "owner"; the audit answer lives beside it.
  • A previous run's owner is never a fallback. On a task already launched under the wrong account, that owner is the wrong account — inheriting it would make the repair reproduce the bug. trigger_task_workflow also reads runs_as back off the created run instead of predicting it, so there is no second copy of the rule to drift.

Behaviour changes to review

Path Before After
Run button on an assigned card clicker owns the run assignee owns it
Run button, unassigned card clicker unchanged
Card dragged into an automated column mover owns the run assignee owns it, mover recorded as requested_by_id
trigger_task_workflow (MCP) personal token's owner assignee, else the caller
Assignee is a viewer / left the company n/a skipped, falls back to the requester

The drag/auto-trigger row is the widest one — say the word and I will scope it back to the two explicit triggers.

Not covered

Runs already created under the wrong account keep propagating until they drain, and this change does not repair them. Worth noting: MCP-seeded triggers recorded source: "manual", identical to a button click, so the blast radius cannot be reconstructed precisely from trigger_events alone — only by actor and timestamp. Happy to add a provenance marker and/or a repair query if you want the history cleaned.

Check suite

docker compose exec -T web make check_all — all green (rails-test, rubocop, brakeman, system-test, eslint, typescript, fe-test, vite-build); backend line coverage 91.46%.

New tests: 6 in task_service_test.rb (assignee wins; unassigned → requester; viewer assignee skipped; revoked assignee skipped; requested_by_id recorded; card move attributes to the assignee), 1 in tasks_controller_test.rb (the button), and the MCP tool's own set including "a previous run's owner is not inherited on a forced retrigger".

🤖 Generated with Claude Code

artempartos and others added 2 commits August 10, 2026 17:33
trigger_task_workflow passed the calling token's owner as the actor, and
that actor becomes run.user — which is not just a label:
SessionService.create_for_workflow_step reads it to pick the agent
credential, the runtime and the model. A project's MCP server carries one
person's amcp_ token, so every board task an agent triggered ran as, and
was billed to, whoever set that server up.

Attribution now follows the task the way every other agent-initiated board
action already does (InternalTools::BoardMoveTask#resolve_actor and
friends): task.assignee, else the previous run's owner, else the caller,
skipping any candidate with no active membership in the company since they
hold no credential there. Moving a card into an automated column is the
main way these runs start, so matching that rule is what makes the same
task cost the same account whichever path launched it.

Authorization is unchanged — still the caller's, via the same policy the
board controller uses. The response now names the account in `runs_as` so
the choice is never silent again.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
… Run

run.user is not a label — SessionService.create_for_workflow_step reads it
to choose the agent credential, the agent runtime and the model, so it
decides which account executes a run and which one is billed. Pressing Run
on a card someone else is assigned to therefore spent the clicker's
credential on their work, and the personal-MCP tool did the same with the
token owner's.

Ownership now resolves in one place, TaskService#run_owner_for: the task's
assignee, falling back to whoever asked, skipping a candidate with no active
membership in the company (no credential there) or with the viewer role
(the platform refuses to let a viewer launch a session at all). The card's
Run button, trigger_task_workflow and a column auto-trigger all inherit it,
so the same task costs the same account however it started. requested_by_id
goes into the trigger event's data, so attributing the run to the assignee
does not lose who asked.

Why one place rather than a fix per caller: every session tool resolves its
own actor as `task.assignee || workflow_run&.user`, where workflow_run is
the run of the session doing the work. A run owned by the wrong account has
an agent that moves each unassigned card as that account, firing more runs
owned by it, whose agents do the same — one wrong owner walks the board.
For the same reason a previous run's owner is never a fallback: on a task
already launched under the wrong account, that owner IS the wrong account.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos artempartos changed the title fix(mcp): attribute an MCP-triggered task run to the task, not the token fix(board): give a task's run to its assignee, not to whoever pressed Run Aug 10, 2026
artempartos and others added 2 commits August 10, 2026 18:27
… run

A nil agent credential is not an error anywhere downstream —
SessionContextService writes credentials only `if credential.present?` — so
handing a run to an assignee who never connected an agent traded a run on
the wrong account for one that comes up with nothing to authenticate as and
dies with whatever the CLI says about being logged out.

can_own_runs? now also requires an AgentCredential in the task's company,
falling back to whoever asked. Not covered, and pre-existing: a candidate
who holds some credential but not the runtime the step pins still resolves
to nil, which would need a second copy of SessionService's runtime cascade
to catch here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Moving somebody else's card is housekeeping; the work it kicks off is still
theirs. Comment only.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 5758e89 into develop Aug 10, 2026
7 checks passed
alex-astafyev pushed a commit to alex-astafyev/flow that referenced this pull request Aug 19, 2026
* origin/develop:
  fix(board): give a task's run to its assignee, not to whoever pressed Run (AixleHQ#80)
  refactor(profile): redesign My Profile into paired identity/agents bands (AixleHQ#78)
  fix(inertia): address partial reloads by their server-side prop names (AixleHQ#79)
artempartos added a commit that referenced this pull request Nov 12, 2026
* chore(deps): bump ransack to 6.1.0 and cuprite to 0.20.1

Supersedes #711.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* chore(deps): bump @tabler/icons-react to 3.51.0 and react-resizable-panels to 4.21.0

Supersedes #712. react-resizable-panels goes to 4.21.0 rather than the PR's
4.20.0: it clears the three-day age gate, so yarn resolves it anyway.
glob 13.0.6 -> 13.0.7 carries the backported AbortSignal fix for
GHSA-3g3m-2fjr-6pw4 (dev-only, through license-checker).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* chore(deps): bump glob to 13.0.7 in the Bitbucket app

13.0.7 backports the AbortSignal fix for GHSA-3g3m-2fjr-6pw4 to the 13.x line.
The advisory still lists <=14.0.1 as vulnerable, so alert #80 stays open
until its range is corrected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

---------

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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