Skip to content

mig: enforce owner-loss latching and atomic agent transfer - #6053

Merged
danielkov merged 5 commits into
mainfrom
daniel/aim-184-feat-enforce-owner-loss-latching-and-atomic-agent-transfer
Sep 8, 2026
Merged

danielkov merged 5 commits into
mainfrom
daniel/aim-184-feat-enforce-owner-loss-latching-and-atomic-agent-transfer

Conversation

@danielkov

@danielkov danielkov commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds durable owner-loss latching and atomic human-only transfer and explicit reassignment routes for first-class agents. Owner changes preserve the agent identity and direct agent policy while transactional audit events record owner loss and ownership transitions.

Motivation

Agents must remain blocked after their human owner becomes ineligible, even if that owner later becomes eligible again, and ownership recovery must not create a pending or ownerless state.

Technical details

Authoritative owner-loss transitions

User deletion, membership deletion or inactivation, directory deactivation, explicit member removal, and declarative WorkOS membership reconciliation set the durable latch in the same database transaction as the eligibility mutation. Explicit reassignment is the only operation that clears it. WorkOS reconciliation requires a new membership identity to restore a deleted membership.

Ownership and direct policy

Transfer requires the current owner's authorization; reassignment recovers a latched agent. Both preserve direct policy grants. A latched former owner loses intrinsic policy-management authority even after membership restoration; explicit agent-write authority can still manage policy without clearing the latch.

Prerequisite

The agent-management prerequisite #6047 is merged. This PR targets main and preserves the direct policy-management APIs now merged in #6051.

@danielkov
danielkov requested review from a team as code owners September 4, 2026 01:27
@linear-code

linear-code Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

AIM-184

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b58772d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
server Minor
dashboard Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Running ultrareview automatically — This adds new public API endpoints for agent transfer/reassignment and durable owner-loss latching, touching core ownership logic across server, API design, and client SDKs — a subtle bug could break agent availability or data integrity.. I'll post findings when complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ultrareview completed in 14m 6s

All reported issues were addressed across 51 files

Linked issue analysis

Linked issue: AIM-184: feat: enforce owner-loss latching and atomic agent transfer

Status Acceptance criteria Notes
Owner deletion, inactivation, or organization-membership loss durably sets both reassignment latch fields in the authoritative mutation. The PR adds shared owner-loss latching and wires it into user deletion, membership removal, WorkOS reconciliation, and directory deactivation paths.
Owner reactivation or membership restoration does not clear the latch; only explicit reassignment clears it. The latch is cleared in the explicit reassignment update, while ordinary lifecycle restoration paths do not clear it.
Ordinary transfer and explicit reassignment atomically replace the owner with an eligible same-organization human. The PR adds separate transfer and reassignment operations, tenant-pinned replacement validation, row updates, and transactional service handling.
Transfers preserve agent identity and direct policy while leaving exactly one current owner. Owner replacement updates owner_user_id in place, and the added integration test explicitly checks preservation of direct policy.
⚠️ Authorization is limited to validated nonsupport human sessions with the required transfer predicate or evaluated agent:transfer permission. The diff shows human authorization and the owned-agent transfer predicate, but the provided excerpts do not fully demonstrate every authorization branch or nonsupport-session guard.
Owner-loss, ordinary-transfer, and explicit-reassignment audit events record the relevant ownership transition. The PR adds dedicated audit actions and ownership audit integration for loss, transfer, and reassignment.
⚠️ Lifecycle, ownership, and concurrency cases are covered by tests, including former-owner authority loss and concurrent changes. New lifecycle, ownership, and direct-policy tests are present, but the supplied diff does not clearly show complete race coverage or tests for every former-owner predicate.

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread server/internal/auth/speakeasyclient/client.go Outdated
Comment thread server/internal/auth/speakeasyclient/client.go
Comment thread server/internal/auth/identity/identity.go Outdated
Comment thread server/internal/background/activities/deprovision_organization_access.go Outdated
Comment thread server/internal/background/activities/process_workos_user_events.go Outdated
Comment thread server/internal/agentmanagement/authorize.go
Comment thread server/internal/organizations/impl.go
Comment thread server/internal/agentownership/ownership.go Outdated
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

atlas migrate lint on server/migrations

Status Step Result
1 new migration file detected 20260908210453_owner_lookup_indexes.sql
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

atlas migrate lint on clickhouse/migrations

Status Step Result
No migration files detected  
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

@blacksmith-sh

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 25 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/background/activities/deprovision_organization_access.go Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread server/internal/organizations/queries.sql Outdated
@danielkov
danielkov force-pushed the daniel/aim-182-agent-management branch from d1b8c36 to b10d4bf Compare September 8, 2026 17:43
Base automatically changed from daniel/aim-182-agent-management to main September 8, 2026 18:30
@danielkov
danielkov force-pushed the daniel/aim-184-feat-enforce-owner-loss-latching-and-atomic-agent-transfer branch from e83b401 to 7d7e263 Compare September 8, 2026 20:08
@danielkov danielkov changed the title feat: enforce owner-loss latching and atomic agent transfer mig: enforce owner-loss latching and atomic agent transfer Sep 8, 2026
@danielkov danielkov added the skip-migration-check Skips migration hygiene check if required label Sep 8, 2026
@danielkov danielkov changed the title mig: enforce owner-loss latching and atomic agent transfer feat: enforce owner-loss latching and atomic agent transfer Sep 8, 2026
@danielkov danielkov added skip-migration-check Skips migration hygiene check if required and removed skip-migration-check Skips migration hygiene check if required labels Sep 8, 2026
@danielkov danielkov changed the title feat: enforce owner-loss latching and atomic agent transfer mig: enforce owner-loss latching and atomic agent transfer Sep 8, 2026
@danielkov
danielkov enabled auto-merge September 8, 2026 20:51
@danielkov
danielkov force-pushed the daniel/aim-184-feat-enforce-owner-loss-latching-and-atomic-agent-transfer branch from 7d7e263 to b58772d Compare September 8, 2026 21:09
@danielkov
danielkov added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 5ee3df1 Sep 8, 2026
44 checks passed
@danielkov
danielkov deleted the daniel/aim-184-feat-enforce-owner-loss-latching-and-atomic-agent-transfer branch September 8, 2026 21:23
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

skip-migration-check Skips migration hygiene check if required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants