Skip to content

fix: preserve conversation source ownership - #5008

Closed
Israeltheminer wants to merge 1 commit into
mainfrom
fix/stable-conversation-source-ownership
Closed

Israeltheminer wants to merge 1 commit into
mainfrom
fix/stable-conversation-source-ownership

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Closes #5007

Problem

Conversation API bindings stored the service-user identity minted for one API key. Rotating an organization, team, project, or delegated-member key therefore made existing sources fail with INTEGRATION_NOT_OWNED, including deliveries queued before the rotation.

Fix

  • store a stable integration principal alongside the legacy key identity
  • backfill existing bindings from retained API-key owner records
  • fill the principal during rolling deploys for older writers
  • use the stable principal for sync, listing, delivery claim/ack/fail/retry, state reads, and assignment
  • add a real integration regression for key rotation, queued delivery claiming, and cross-principal isolation

Validation

  • Bun parser/bundler check passed for the changed TypeScript entry points
  • git diff --check passed
  • targeted Vitest files could not run because dependencies are not installed and the registry is unavailable in this environment

@Israeltheminer
Israeltheminer force-pushed the fix/stable-conversation-source-ownership branch from 4b44763 to 921ae45 Compare October 16, 2026 21:13
@Israeltheminer
Israeltheminer force-pushed the fix/stable-conversation-source-ownership branch from 921ae45 to 45fe1f6 Compare October 16, 2026 21:21
@yannickmonney

Copy link
Copy Markdown
Contributor

Thank you for the report and the patch. This PR is being closed in a cleanup of old PRs: the branch is 521 commits behind main, and its migration number (0182) is now out of sequence (the stable line is at 0224), so it cannot merge as is. The bug is real and #5007 stays open. The branch fix/stable-conversation-source-ownership (head 45fe1f6ca) stays on origin.

The approach was checked against the current code on 2026-11-02, so that a new attempt can start from what turned up:

  • The migration applies cleanly to a real Postgres, and its trigger fills the principal for rows an older image writes during a roll.
  • A delegated member key acts as the member, so its existing bindings carry owner_user_id = <member>. The backfill joins only on api_key_owners.key_user_id, which differs for member keys, so those bindings become ('user', <member>), while sourceOwnerOf in v1-conversations.ts returns ('member', <member>). After the migration such a key reads back none of its own mirrors (0 rows in the check) and would be refused with INTEGRATION_NOT_OWNED. Treating a member key as ('user', <member>) avoids it.
  • Every key of one organization, team or project now shares one principal, so two separate org-owned integrations can reach each other's mirrors, and the example under CONV-R14 ("two integrations ... refused") no longer holds for them. Whether scope-level ownership is what "the same integration" should mean needs a decision.
  • The integration lane that would prove the change end to end (checkConversationApi) has not run: the description says dependencies could not be installed.

@yannickmonney
yannickmonney deleted the fix/stable-conversation-source-ownership branch November 2, 2026 17:53
yannickmonney pushed a commit that referenced this pull request Nov 3, 2026
An API-mirrored conversation recorded the identity of the key that first
sent it and refused every other identity. A key made for a team or the
organization authenticates as a service identity of its own, so
replacing it stranded the mirrors and the replies queued for them
(INTEGRATION_NOT_OWNED), with no way to hand them over.

A mirror now belongs to the integration that created it, which is whom
the key belongs to. A person's own key and a key made for a member act
as that person. A key made for a team or the organization acts for it,
so its replacement continues the mirror, lists it and claims the replies
queued before the swap. A key of anyone else is still refused. A
project's key never reaches these routes. Two keys made for the same
team or organization are one integration and share their mirrors; the
spec rule, the API reference (EN, DE, FR) and the OpenAPI descriptions
say so.

Migration 0235 adds the owner to the bindings. It fills it from
api_key_owners, within the binding's organization, for the keys made
for a team or the organization (every other binding belongs to its
user, as it always did) and keeps a trigger that fills it for the rows
the previous image inserts during a roll. It takes the number above
both release lines.

The mirror functions take an IntegrationViewer whose owner is required,
so a caller cannot fall back to the key's own identity and strand the
mirrors again.

Builds on #5008 by Israeltheminer, which found the cause and the shape
of the fix. Three things differ from it: a member's key maps to the
person, as the backfill stores it, instead of an owner kind no row
carries, which left that key reading none of its own mirrors; the
backfill matches the key's organization; and the rotation, the roll and
the backfill are proved on a real Postgres in the conversation API lane,
which fails on the code before this change.

Fixes #5007
@yannickmonney

Copy link
Copy Markdown
Contributor

Update, now that the fix is in: it is on the stable train as "fix(platform): keep API mirror ownership across key rotation" (09fabf551, with you as the commit author; it reaches main with the next train pull request and closes #5007 then). Thank you for finding the cause and the shape of the fix.

What differs from this branch:

  • A member's key maps to the person (('user', <member>)), as the backfill stores it, instead of a member owner kind that no row carried. That was the case where a member key read back none of its own mirrors after the migration.
  • The backfill matches the key's organization as well as its key user.
  • The migration is 0235, above both release lines (this branch's 0182 was out of sequence). It keeps your trigger for the rows an older image inserts during a roll.
  • The mirror functions take an IntegrationViewer whose owner is required, so a caller cannot fall back to the key's own identity and strand the mirrors again.
  • Proof: unit tests per key kind, and rotation, older-image and backfill checks in the checkConversationApi lane on a real Postgres. The lane fails on the code before the change (a replacement key's sync answers 403 where 200 is expected). CONV-R14, the API reference (EN, DE, FR), the OpenAPI descriptions and the manual error-code row say what the rule now is.

One decision came with it: every key made for the same team or the organization is one integration and shares its mirrors, because Tale cannot tell a replacement key from a second one. Integrations that must stay apart need different teams or members. That limit is written into CONV-R14 and the API reference.

The branch fix/stable-conversation-source-ownership is now deleted on origin, so the line above that says it stays there no longer holds. Its head is still reachable as refs/pull/5008/head (45fe1f6ca).

tale-code-bot pushed a commit that referenced this pull request Nov 3, 2026
An API-mirrored conversation recorded the identity of the key that first
sent it and refused every other identity. A key made for a team or the
organization authenticates as a service identity of its own, so
replacing it stranded the mirrors and the replies queued for them
(INTEGRATION_NOT_OWNED), with no way to hand them over.

A mirror now belongs to the integration that created it, which is whom
the key belongs to. A person's own key and a key made for a member act
as that person. A key made for a team or the organization acts for it,
so its replacement continues the mirror, lists it and claims the replies
queued before the swap. A key of anyone else is still refused. A
project's key never reaches these routes. Two keys made for the same
team or organization are one integration and share their mirrors; the
spec rule, the API reference (EN, DE, FR) and the OpenAPI descriptions
say so.

Migration 0235 adds the owner to the bindings. It fills it from
api_key_owners, within the binding's organization, for the keys made
for a team or the organization (every other binding belongs to its
user, as it always did) and keeps a trigger that fills it for the rows
the previous image inserts during a roll. It takes the number above
both release lines.

The mirror functions take an IntegrationViewer whose owner is required,
so a caller cannot fall back to the key's own identity and strand the
mirrors again.

Builds on #5008 by Israeltheminer, which found the cause and the shape
of the fix. Three things differ from it: a member's key maps to the
person, as the backfill stores it, instead of an owner kind no row
carries, which left that key reading none of its own mirrors; the
backfill matches the key's organization; and the rotation, the roll and
the backfill are proved on a real Postgres in the conversation API lane,
which fails on the code before this change.

Fixes #5007
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.

preserve conversation source ownership across API key rotation

2 participants