Skip to content

Per-session teardown: drop delegated MCP token + connection at session end (#317 follow-up) #333

Description

@initializ-mk

Carved out of the #317 epic. Per-user tokens (#327) and connections (#329) resolve lazily and are keyed by `subject`; the auth-required gate (#330 / PR #331) parks and resumes. What's missing is the teardown end of the lifecycle — dropping a user's delegated token + connection when their session ends.

Problem

Today the delegated per-user token + connection are torn down only:

  • at server stop — `subjectConnPool.Close()` tears down the whole pool (`server.go:441`), and
  • on TTL expiry — `memSubjectTokenStore` sweeps expired tokens opportunistically.

There is no per-session-end teardown. The #317 acceptance calls for: "session end drops token + connection; new session re-consents." Without it, a subject's token + live MCP connection persist past the session that established them — up to the token TTL / process lifetime — which is both a footprint and an isolation concern (a new session should re-consent, not silently reuse the prior session's grant).

Scope

  • Thread a session id onto the invocation (work-breakdown item 1 notes this is needed) and make the delegated token cache + connection pool aware of it, or maintain a subject→session binding.
  • On session end, drop that subject/session's token (`SubjectTokenStore.Evict`) and connection (`subjectConnPool.Evict` / `Close` for that entry) — the primitives already exist; they need a lifecycle trigger.
  • A new session for the same subject with no live grant re-enters the auth-required gate (re-consents) rather than reusing a stale connection.

Decisions to make

Already in place (build on these)

Acceptance

  • Ending a session evicts that subject/session's delegated token and tears down its MCP connection.
  • A new session for the same subject with no live grant re-consents (re-enters the gate) rather than reusing the prior connection.
  • A connection cap / eviction policy bounds N-concurrent-user connection growth.
  • No delegated token persists past its session (beyond the TTL backstop).

Out of scope

Related

Epic #317 · tokens #327 · connections #329 · gate #330 (PR #331) · AARM R10 #319 · authority `design-tool-registry.md` §18.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestforge-coreAffects the forge-core library (runtime, security, types, llm, mcp, auth)

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions