Skip to content

feat(agents): capture a terminal session's tenant at creation — it cannot be recovered afterwards #16975

Description

@mrveiss

Part of #16946. Found while building presence (#16947, PR #16965).

Finding

A terminal session has no tenant, and none can be recovered after the fact. So presence reports every session as UNKNOWN_TENANT — correctly fail-closed, but it means no session can be discovered or addressed within its own tenant.

The route that looked like it might work does not exist:

  • AgentTerminalSession (services/agent_terminal/models.py) has no tenant, company, org or owner field.
  • conversation_id is used only for log linkage, everywhere it appears (session_manager.py:88, 181, 210, 244).
  • The chat-history session and conversation stores composed by ChatHistoryManager carry no user or tenant field.
  • The authenticated creator's owner is passed through SessionManager.create_session → _setup_pty_for_session → _register_pty_with_terminal_manager, but only for PTY registration, and it is never persisted on the session.

No username → organisation lookup exists either, so that may need building.

Fix

Capture the tenant at creation, while the authenticated owner is still in hand:

  1. Resolve the creating principal's organisation when the session is created.
  2. Persist it on AgentTerminalSession as an explicit field.
  3. Have the presence feed report it, falling back to UNKNOWN_TENANT only when it genuinely could not be determined.

Acceptance criteria

  • A newly created session carries the tenant of the principal who created it
  • The tenant is resolved from the authenticated principal, never from a caller-supplied value
  • Presence reports a session under its real tenant, and a session whose tenant cannot be determined stays UNKNOWN_TENANT
  • A test showing a session is discoverable within its own tenant and invisible to another
  • Sessions that already exist are handled explicitly — left UNKNOWN_TENANT, not guessed

Activity

  1. added this to the v0.9.0 milestone on Sep 18, 2026
  2. mrveiss commented on Sep 19, 2026

    @mrveiss
    OwnerAuthor

    AC verification against merged main (post #17133 vehicle merge)

    All 5 satisfied. Closed correctly.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions