Skip to content

chore(mcp-analytics): make remaining MCPSession backfill columns nullable#60035

Merged
gesh merged 1 commit into
masterfrom
chore/mcp-drop-dormant-session-mirror
May 27, 2026
Merged

chore(mcp-analytics): make remaining MCPSession backfill columns nullable#60035
gesh merged 1 commit into
masterfrom
chore/mcp-drop-dormant-session-mirror

Conversation

@gesh
Copy link
Copy Markdown
Member

@gesh gesh commented May 26, 2026

Problem

MCPSession's backfill-mirror columns are dormant — the live sessions list aggregates from events on the fly and never reads them, and the only writer (the backfill-mcp-sessions job) is being removed in #60039. They're on the path to deletion, but the safe first step is relaxing their NOT NULL constraints.

#60041 already did this for session_start / session_end / duration_seconds. This completes the set for the remaining four.

Changes

DROP NOT NULL on tools_used, tool_call_count, distinct_id, mcp_client_name (instant, non-destructive metadata change). The model fields stay in place for now; physically dropping the columns is a later cleanup once these constraints are relaxed and the jobs (#60039) are gone.

How did you test this code?

Agent-authored. Verified makemigrations --check reports no drift, sqlmigrate emits only the four DROP NOT NULLs, and ruff passes.

Docs update

no

🤖 Agent context

Authored with Claude Code (Opus 4.7). Part of the incremental MCP-analytics cleanup: (1) #60039 remove the dormant backfill/summarize jobs, (2) this — finish relaxing the backfill columns to nullable (mirrors #60041), (3) a later PR removes the fields + physically drops the columns. Kept small and non-destructive on purpose.

@assign-reviewers-posthog assign-reviewers-posthog Bot requested a review from a team May 26, 2026 09:38
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 26, 2026

Reviews (1): Last reviewed commit: "chore(mcp): slim dormant MCPSession mode..." | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Migration SQL Changes

Hey 👋, we've detected some migrations on this PR. Here's the SQL output for each migration, make sure they make sense:

products/mcp_analytics/backend/migrations/0006_alter_mcpsession_distinct_id_and_more.py

BEGIN;
--
-- Alter field distinct_id on mcpsession
--
ALTER TABLE "posthog_mcp_session" ALTER COLUMN "distinct_id" DROP NOT NULL;
--
-- Alter field mcp_client_name on mcpsession
--
ALTER TABLE "posthog_mcp_session" ALTER COLUMN "mcp_client_name" DROP NOT NULL;
--
-- Alter field tool_call_count on mcpsession
--
ALTER TABLE "posthog_mcp_session" ALTER COLUMN "tool_call_count" DROP NOT NULL;
--
-- Alter field tools_used on mcpsession
--
ALTER TABLE "posthog_mcp_session" ALTER COLUMN "tools_used" DROP NOT NULL;
COMMIT;

Last updated: 2026-05-27 08:28 UTC (d506ecf)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

🔍 Migration Risk Analysis

We've analyzed your migrations for potential risks.

Summary: 0 Safe | 1 Needs Review | 0 Blocked

⚠️ Needs Review

May have performance impact

mcp_analytics.0006_alter_mcpsession_distinct_id_and_more
  └─ #1 ⚠️ AlterField
     Field alteration may cause table locks or data loss (check if changing type or constraints)
     model: mcpsession, field: distinct_id, field_type: CharField
  └─ #2 ⚠️ AlterField
     Field alteration may cause table locks or data loss (check if changing type or constraints)
     model: mcpsession, field: mcp_client_name, field_type: CharField
  └─ #3 ⚠️ AlterField
     Field alteration may cause table locks or data loss (check if changing type or constraints)
     model: mcpsession, field: tool_call_count, field_type: IntegerField
  └─ #4 ⚠️ AlterField
     Field alteration may cause table locks or data loss (check if changing type or constraints)
     model: mcpsession, field: tools_used, field_type: ArrayField

Last updated: 2026-05-27 08:28 UTC (d506ecf)

@gesh gesh force-pushed the chore/mcp-drop-dormant-session-mirror branch from ce1bcf8 to e7d3ea1 Compare May 26, 2026 10:02
@gesh gesh changed the base branch from master to chore/mcp-remove-dormant-jobs May 26, 2026 10:02
@gesh gesh marked this pull request as draft May 26, 2026 10:12
@gesh gesh force-pushed the chore/mcp-remove-dormant-jobs branch from 76a85ab to 7ab495f Compare May 26, 2026 15:01
@gesh gesh force-pushed the chore/mcp-drop-dormant-session-mirror branch from e7d3ea1 to 68270c6 Compare May 26, 2026 15:04
@gesh gesh changed the title chore(mcp): slim dormant MCPSession model to intent-only fields chore(mcp): make remaining MCPSession backfill columns nullable May 26, 2026
@gesh gesh changed the base branch from chore/mcp-remove-dormant-jobs to master May 26, 2026 15:04
@gesh gesh changed the title chore(mcp): make remaining MCPSession backfill columns nullable chore(mcp-analytics): make remaining MCPSession backfill columns nullable May 26, 2026
#60041 relaxed session_start/session_end/duration_seconds to nullable;
this completes the set for the other dormant backfill-mirror columns
(tools_used, tool_call_count, distinct_id, mcp_client_name). DROP NOT NULL
is an instant, non-destructive metadata change.

These columns are written only by the (de-registered, being-removed)
backfill job; the live sessions list aggregates from events and never
reads them. Relaxing the constraints is safe prep toward removing the
columns entirely in a later cleanup — the model fields stay for now.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gesh gesh marked this pull request as ready for review May 27, 2026 08:18
@gesh gesh force-pushed the chore/mcp-drop-dormant-session-mirror branch from 68270c6 to d506ecf Compare May 27, 2026 08:18
@gesh gesh requested a review from a team May 27, 2026 08:19
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

Reviews (2): Last reviewed commit: "chore(mcp): make remaining MCPSession ba..." | Re-trigger Greptile

@gesh gesh merged commit 0105f1a into master May 27, 2026
215 checks passed
@gesh gesh deleted the chore/mcp-drop-dormant-session-mirror branch May 27, 2026 08:55
@deployment-status-posthog
Copy link
Copy Markdown

deployment-status-posthog Bot commented May 27, 2026

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-05-27 09:21 UTC Run
prod-us ✅ Deployed 2026-05-27 09:39 UTC Run
prod-eu ✅ Deployed 2026-05-27 09:40 UTC Run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants