Skip to content

fix(query-cache): ignore removed modifiers when reading cached responses - #123931

Closed
sampennington wants to merge 1 commit into
masterfrom
posthog/ignore-removed-modifiers-in-cache
Closed

sampennington wants to merge 1 commit into
masterfrom
posthog/ignore-removed-modifiers-in-cache

Conversation

@sampennington

Copy link
Copy Markdown
Contributor

Problem

When a modifier is removed from HogQLQueryModifiers, customers lose their cached query results. Every cached response stores the modifiers it ran with, and the model uses extra="forbid". So each entry written before the removal fails to parse. handle_cache_and_async_logic then counts it as a cache miss. Insights and dashboards calculate again, and stale-while-revalidate stops for these entries until they are written again.

#122489 removed useNewEventsCluster and caused this. Raised in this Slack thread.

Changes

  • Before a cached response is parsed, the runner drops modifier keys that HogQLQueryModifiers does not know. This applies to all removed modifiers, not only useNewEventsCluster. It follows the same filter that create_default_modifiers_for_team already applies to stored team modifiers.
  • Mechanical otherwise: nothing changes for entries that parse today.

#123812 fixes the same incident in a different way: it adds useNewEventsCluster back as a deprecated field. This PR is smaller, needs no schema or type regeneration, and also prevents the problem for the next removed modifier. The two can land together.

How did you test this code?

  • Ran hogli test posthog/hogql_queries/test/test_query_runner.py -k "removed_from_the_schema or schema_change_triggers or test_cache_response" in the sandbox.
  • Confirmed that the new test fails without the change in query_runner.py.
  • Not checked: a real cache read on a running stack.

Test rationale: test_a_modifier_removed_from_the_schema_keeps_the_cache_hit fails if a cached response with an unknown modifier key is treated as a miss again. The closest existing test, test_schema_change_triggers_recalculation, checks the opposite case: a response that really does not match the schema must still calculate again.

Release status

  • No feature flag controls this change

Docs update

None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Agent: PostHog Slack app (Claude Code), Claude Opus 5.5 (claude-opus-5-5)


Created with PostHog from a Slack thread

🤖 Generated with Claude Code

Every cached response stores the modifiers it ran with. HogQLQueryModifiers forbids extra fields, so removing a modifier from the schema made every entry written before the removal fail to parse and count as a cache miss. Drop modifier keys the schema does not know before parsing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Generated-By: PostHog Desktop
Task-Id: 876dcdf1-ca2f-410c-8aeb-e4649262f74b
@sampennington sampennington self-assigned this Oct 27, 2026
@trunk-io

trunk-io Bot commented Oct 27, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane

This PR is assigned to the backend Python lane. It runs backend Python tests and may merge in parallel with PRs in other lanes.

✅ Duplication (Python) — clean

New Python code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

✅ Duplication (TypeScript) — clean

New TypeScript code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

@trunk-io

trunk-io Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

View Full Report ↗︎ ⋅ Docs

Copy link
Copy Markdown
Contributor

Closing in favor of #124050. The team chose to keep recalculating entries that no longer parse, and to show the cost of a field removal before merge instead of changing how old entries are read.

@vdekrijger vdekrijger closed this Oct 27, 2026
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