Skip to content

Per-org agent instances so one tenant never waits for another (follow-up to #63) #195

Backlog

Description

@OkiriGabriel

Context

#63 (PR #188) made per-org credentials safe under concurrency. Each org's keys live in a context-local view of os.environ, and an OrgGate stops one org's cached clients (GitHub, cloud SDKs, the LLM client) from being swapped while another org is using the single shared DevOpsAgent.

The cost: work for org B waits while org A's scope is open. A Slack approval or MCP call for one tenant can wait for minutes behind another tenant's incident. org_scope_waiting is logged when this happens.

The agent also stores per-run settings on itself (self.auto_apply, self.model are set at the start of every run()/execute_tool()). That's only safe because of the gate.

Proposed solution

  • Keep one DevOpsAgent (and EscalationService) per credential fingerprint: a hash of the org's resolved credentials, so orgs without their own keys share the platform instance. Use an LRU cache (e.g. 32 entries), build each instance inside the org's credential scope, and rebuild it when the fingerprint changes (a key was rotated, see [SECURITY] Credential lifecycle: validation, rotation audit trail, and secure deletion #62).
  • Route the queue worker, /slack/action, the MCP handlers and execute_approved_action to the org's instance. Once nothing shares an instance across orgs, remove the gate.
  • Pass auto_apply and model per run instead of mutating the agent.
  • Tests: two orgs' long-running scopes overlap without waiting; rotating a key yields a fresh instance; memory stays bounded.

Files

services/org_context.py, api/server.py, devops_mcp/registry.py, agent/core.py

Activity

  1. added
    enhancement
    technical-debt
    on Nov 25, 2026
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

    enhancementtechnical-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions