Skip to content

fix: scope template dedupe to the member who enabled it - #753

Merged
neubig merged 1 commit into
mainfrom
fix/template-dedupe-per-member
Nov 14, 2026
Merged

neubig merged 1 commit into
mainfrom
fix/template-dedupe-per-member

Conversation

@neubig

@neubig neubig commented Nov 13, 2026

Copy link
Copy Markdown
Member

Why

Fixes #750. Every create endpoint that accepts template replayed any same-org automation for that template with a 200. A second member enabling a catalog entry another member already enabled was handed the first member's automation: the second member's trigger and config were dropped, and because a run mints its key for automation.user_id, every run (even ones the second member dispatched) produced output in the first member's account.

The lookup was per user when it was introduced (#322); #399 widened it to the org as a side effect of making management org-scoped. No catalog entry declares a once-per-org rule.

Summary

  • find_existing_template_automation now also filters on created_by_user_id (the member who enabled it). All four callers (POST /v1, /v1/plugin-spec, /v1/preset/prompt, /v1/preset/plugin) pass the caller's id.
  • Unchanged: same-member replay (200, no new row), cross-endpoint identity for one member, DRAFT artifacts not counting, INACTIVE installs counting, soft-deleted installs not blocking, org-scoped list/get/patch/delete/dispatch from fix: scope automation management to the org instead of the owner #399.
  • The OpenAPI 200 description and AGENTS.md now describe per-member dedupe.
  • New tests/test_template_dedupe_per_member.py: two members on each of the four endpoints (201, own owner/trigger/config, first member's automation untouched), same-member replay on each endpoint, cross-endpoint replay, org-scoped management of each other's installs, and a run on the second member's automation minting the key at /api/service/users/{second}/orgs/{org}/api-keys.

How to Test

uv run pytest tests/test_template_dedupe_per_member.py
uv run pytest tests/test_router.py tests/test_preset_router.py tests/test_draft_router.py tests/test_automation_tags.py tests/test_router_plugin_spec.py

New file: 11 passed on this branch; on main 6 of them fail (assert 200 == 201). The related suites pass (733 passed locally with Postgres testcontainers). Pre-commit (ruff, pycodestyle, pyright) passes.

Before / after

The same script (.pr/issue-750/demo_750.py) signs in as two members of one org and sends the same news-digest template to each endpoint.

Before (main 949c001) After (this PR)
before after

Notes

The Agent Canvas setup dialog cannot tell a 200 from a 201 (noted in the issue); that belongs in OpenHands/OpenHands and is out of scope here. .pr/ holds review evidence only and is removed on release.

This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

A second member enabling a catalog template the org already had was handed
the first member's automation with a 200: their trigger and config were
dropped, and every run kept minting the first member's key, so the output
landed in the first member's account.

find_existing_template_automation now also filters on created_by_user_id, so
each member gets their own install while a member re-enabling the same
template still gets theirs back. Management stays org-scoped.

Fixes #750

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR adds or changes temporary PR-specific documents under .pr/. They stay on this branch for review. After this PR merges, the next release PR removes them from main.

@github-actions github-actions Bot added the type: fix A bug fix label Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage

Warning

Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it.

@neubig
neubig requested a review from all-hands-bot November 13, 2026 23:23
@neubig

neubig commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

@all-hands-bot Please review the latest head ae10c93. All CI checks are green and the branch merges cleanly with main. Before/after evidence is in the PR description.

This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

@neubig
neubig requested review from all-hands-bot and removed request for all-hands-bot November 14, 2026 02:29
@all-hands-bot

Copy link
Copy Markdown
Contributor

This review was posted by an AI agent (OpenHands).

Scope

The change belongs here: template dedupe on automation creation is service-owned behavior, and issue #750 is labeled ready-for-dev. No product/architecture decision is needed — the fix restores the per-member scoping #322 introduced, which #399 widened to org-wide as a side effect.

Assessment

The fix is correct and minimal. find_existing_template_automation now filters on created_by_user_id in addition to org_id, and all four creation endpoints (POST /v1, /v1/plugin-spec, /v1/preset/prompt, /v1/preset/plugin) pass user.user_id (router.py:265, router.py:359, preset_router.py:647, preset_router.py:1168). Every creation site sets created_by_user_id to the caller — including the run-as/service-account paths, where user_id becomes the run-as identity but the creator field stays the human caller (router.py:303, router.py:400, preset_router.py:723, preset_router.py:1274), so the dedupe key is consistent across all paths. Service-account callers cannot reach the lookup at all (require_automation_creator refuses before it, and the existing test_sa_caller_gets_403_for_a_template_the_org_already_has pins that ordering).

I verified the changed filter semantics directly against the code (standalone SQLite harness exercising the json_extract branch): another member's install no longer matches, the caller's own replay does, and the unchanged guards hold — DRAFT artifacts skipped, soft-deleted rows skipped, INACTIVE installs still count, rows without template provenance excluded. The PostgreSQL branch (->/->>) is exercised by CI's unit-tests, which passed on this exact head, as did windows-tests. The other filters are unchanged, so the existing test_draft_test_artifact_does_not_count_as_template_install and test_inactive_template_install_still_returns_existing coverage carries over.

The OpenAPI 200 description and the AGENTS.md catalog-bundle section now describe per-member dedupe accurately. All ten checks on head ae10c93 are green, and the PR merges cleanly.

Test evidence

  • The new tests/test_template_dedupe_per_member.py covers every acceptance criterion from [Bug]: A template can be enabled only once per org: a second member's create returns the first member's automation #750: second member gets 201 with their own owner/trigger/config on each of the four endpoints, the first member's automation untouched, same-member replay with no extra row, cross-endpoint replay, org-scoped management of each other's installs, and the run-key minted for the second member at /api/service/users/{second}/orgs/{org}/api-keys.
  • This workspace has no Docker daemon, so I could not run the container-backed suite here; I verified the lookup logic locally on SQLite and relied on the passing Postgres unit-tests run on this head for the PostgreSQL path.

No material correctness, security, or compatibility findings.

✅ APPROVED

@neubig
neubig merged commit 2ebf361 into main Nov 14, 2026
10 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.33.0 Shipped in 1.33.0 label Nov 17, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.33.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.33.0 Shipped in 1.33.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A template can be enabled only once per org: a second member's create returns the first member's automation

3 participants