Skip to content

A task.create idempotency key is scoped to its poster - #233

Merged
zlareb1 merged 14 commits into
mainfrom
fix/task-idempotency-per-poster
Nov 4, 2026
Merged

zlareb1 merged 14 commits into
mainfrom
fix/task-idempotency-per-poster

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A task.create idempotency key belongs to its poster: another poster that sends the same key into the same inbox now stores its own task instead of receiving the first poster's task and brief.

Why

Failing case: poster A creates a task in inbox X with idempotency_key="finding-42" and a confidential brief. Poster B, listed in X's posters but with no read on X's owner namespace, creates with the same key. fetch_task_by_idempotency_key filtered only on (org, inbox, key), so B got created=false and A's task back, title, brief and outcome included, which task.get refuses B. B's own task was never stored. Keys derived from the work item (a finding id, a PR number) collide in practice.

Pattern: a lookup by a caller-chosen key that leaves the caller out of the key.

Fix: the key lookup, the key's lease (_one_create_per_key) and the insert's dedup token (insert_created_task) now include the poster's server-set subject (_caller_subject, the token subject; the stored from_subject). A retry by the same poster still finds its first task.

Scope and risk

server/tasks/store/repo.py, server/tasks/app/transitions.py, the field comment on TaskCreateInput.idempotency_key, and the docs that describe the key. No column or migration: from_subject is already stored on every task row. Concurrency is unchanged for one poster; two posters with one key no longer serialize on one lease. The lease name and dedup token come from one digest (repo.create_key_digest).

Compatibility, rollout and rollback

  • Wire: no field change. Behaviour change: a second poster's create with a reused key now answers created=true with its own task.
  • Rolling upgrade: N-1 names its lease and token without the poster, so neither build shares the other's lease or token. A same-poster create of each build racing on one key can store two tasks, as docs/architecture/rolling-upgrades.md rule 10 allows. Rule 10 also said the build before takes no lease and writes a random token; that described a build older than N-1, and it now says the ready-event delivery's lease and token are shared across builds while the create's are not. A retry that crosses builds still finds the task, since both builds' lookups match it. N-1 replicas keep answering another poster's task for a reused key until they stop serving.
  • Operator steps: none.
  • Rollback: no schema or generated state to undo, but rolling back brings the bug back: where two posters now hold a task under one key, the previous build's lookup answers the earlier one's task, brief included, to the other poster's next create with that key.

Tests

  • New tests/unit/test_task_inbox.py::test_another_posters_idempotency_key_stores_its_own_task: failed before the fix (B got created=false and A's task id), passes after; also checks the same poster's retry still dedups.
  • New tests/integration/test_task_inbox.py::test_a_poster_reusing_another_posters_key_gets_its_own_task: two minted service-account tokens post one key over HTTP; the second gets created=true, its own task, and none of the first one's title or brief; its own retry dedups.
  • New integration tests in tests/integration/test_task_create_dedup_live_ch.py: test_another_posters_create_with_the_key_is_not_dropped_by_its_token (the second poster's row lands on its first insert and reads back whole) and test_this_builds_retry_finds_the_task_an_old_builds_create_stored (a cross-build retry by one poster finds its task). The previous build's stand-in create now posts as the subject this build stamps and inserts under that build's exact key token.
  • Removed test_an_old_builds_delivery_after_this_builds_posts_a_second_event and test_this_builds_delivery_after_an_old_builds_reports_its_own_event: they modelled a build from before the delivery's lease and token, which no longer runs beside this one.
  • tests/unit/test_task_inbox.py, test_task_watch.py, test_task_cursor_server_clock.py, test_inbox_trust_by_subject.py, test_inbox_gate_friction.py, test_sdk_tasks.py, test_docs_reference.py, test_public_copy.py, test_agent_instructions.py, test_doc_links.py pass. make format lint typecheck clean. tests/integration/test_task_create_dedup_live_ch.py runs in CI.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked the lookup, lease and token paths and the rolling-upgrade interaction by reading the code.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 14 commits November 3, 2026 22:41
The key lookup, its lease and its dedup token named only (org, inbox, key), so a
second poster reusing a key got the first poster's task back, brief included, and
its own task was never stored. All three now include the poster's server-set
subject: another poster's same key stores its own task.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ild before

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ith another

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… build does not share

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…try finds its task

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ate's is not

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…created token

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ves them

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/task-idempotency-per-poster branch from 712d0d6 to b271a5b Compare November 3, 2026 22:42
@zlareb1
zlareb1 merged commit 9aa4f75 into main Nov 4, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/task-idempotency-per-poster branch November 4, 2026 00:03
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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