gabriel / musehub public
0090_mcp_sessions.py python
50 lines 2.3 KB
Raw
sha256:e6c07a0f17d2b30516cfe406c094c493c3aeaf8ea72db9ca098d24013bcc3bb9 Merge branch 'task/wave-hub-mcp-289' into dev Opus 5.5 minor ⚠ breaking 1 day ago
1 """musehub_mcp_sessions: MCP Streamable HTTP sessions shared by every worker process (musehub#289)
2
3 Sessions lived in a per-process dict, so with several uvicorn workers a request reaching a worker that did not
4 handle ``initialize`` answered 404 "Session not found" for a live session. Each live session is now a row keyed by
5 the SHA-256 of its ID; any worker validates it with one primary-key lookup.
6
7 Revision ID: 0090
8 Revises: 0089
9
10 Additive (a new table and its index, nothing rewritten). Rollback: swap traffic back to the previous blue/green slot,
11 which is still running the previous image; that image never reads this table. Redeploying the previous image through
12 deploy.sh is NOT a rollback: its migration step runs ``alembic current`` against a revision graph that has no 0090 and
13 fails.
14 """
15 from __future__ import annotations
16
17 import sqlalchemy as sa
18 from alembic import op
19 from sqlalchemy.dialects.postgresql import JSONB
20
21 revision: str = "0090"
22 down_revision: str = "0089"
23 branch_labels = None
24 depends_on = None
25
26
27 def upgrade() -> None:
28 # Fail fast (and retry the deploy) rather than queue behind a long-running transaction.
29 op.execute("SET LOCAL lock_timeout = '5s'")
30 op.create_table(
31 "musehub_mcp_sessions",
32 sa.Column("session_key", sa.String(64), primary_key=True),
33 sa.Column("user_handle", sa.String(64), nullable=True),
34 sa.Column("is_agent", sa.Boolean(), nullable=False),
35 sa.Column("agent_name", sa.String(64), nullable=True),
36 sa.Column("protocol_version", sa.String(32), nullable=False),
37 sa.Column("client_capabilities", JSONB(), nullable=False),
38 sa.Column("client_info", JSONB(), nullable=True),
39 sa.Column("focus_owner", sa.String(64), nullable=True),
40 sa.Column("focus_slug", sa.String(64), nullable=True),
41 sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
42 sa.Column("last_seen_at", sa.DateTime(timezone=True), nullable=False),
43 sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
44 )
45 op.create_index("ix_musehub_mcp_sessions_expires_at", "musehub_mcp_sessions", ["expires_at"])
46
47
48 def downgrade() -> None:
49 op.drop_index("ix_musehub_mcp_sessions_expires_at", table_name="musehub_mcp_sessions")
50 op.drop_table("musehub_mcp_sessions")
File History 3 commits
sha256:e6c07a0f17d2b30516cfe406c094c493c3aeaf8ea72db9ca098d24013bcc3bb9 Merge branch 'task/wave-hub-mcp-289' into dev Opus 5.5 minor ⚠ 1 day ago
sha256:08c30c873257205e342a68f5d55803ff3c6dd6abd4747b5444c68e1da4b8da39 fix(mcp): bind sessions to their principal; honest cross-wo… Opus 5.5 minor ⚠ 1 day ago
sha256:5e59815d34816a1aa12717d0ac82362d6a9919e8b6e096e66ed49c47a028d76f fix(mcp): share Streamable HTTP sessions across worker proc… Opus 5.5 minor ⚠ 1 day ago