Skip to content

feat(flags): add staff toggle for minimal_flag_called_events - #69492

Merged
haacked merged 3 commits into
masterfrom
haacked/staff-tool-improvement
Jul 13, 2026
Merged

feat(flags): add staff toggle for minimal_flag_called_events#69492
haacked merged 3 commits into
masterfrom
haacked/staff-tool-improvement

Conversation

@haacked

@haacked haacked commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

There was no way to flip TeamFeatureFlagsConfig.minimal_flag_called_events for a specific team without a raw ORM write. The model has no serializer, viewset, or admin registration, so staff had no path to enable the slim $feature_flag_called event shape for a team once its SDKs support it, short of a one-off database update.

image

Changes

  • New staff-only endpoint (FeatureFlagsStaffTeamConfigViewSet) for batch-reading and single-team writing of minimal_flag_called_events, following the same pattern as the existing cache tools (staff_cache.py / staff_teams.py): unscoped ViewSet, IsStaffUser gated, structured audit logging.
  • The write updates the DB then kicks off a metadata cache refresh, since /flags and /decide read this value out of Redis, not the database.
  • Added a switch to the existing Flags staff tools team table so staff can toggle this per team right next to the cache tools, instead of on a separate page.
  • Updated the model's docstring to name this new staff API as a sanctioned writer, alongside the existing ones.
  • Writes are single-team only, by design. This setting is meant to be flipped one team at a time after confirming that team's SDK versions actually support the slim event shape, so there's no bulk-enable action.

How did you test this code?

  • Added backend tests in test_staff_team_config_api.py covering permission gating, batch read behavior (dedup, unknown ids, the id cap), the write path (DB update plus cache refresh enqueue), and the not-found and missing-row cases.
  • Extended featureFlagsStaffToolsLogic.test.ts with cases for the batch load, a successful toggle, the failure toast path, and the double-submit guard.
  • Manually verified in a local dev environment: loaded /feature_flags/staff, searched for a team, toggled the switch on and off, and confirmed the DB value updated, the metadata cache refresh task fired (checked via logs), and the switch reflected the persisted value after a page reload.
  • Ran hogli ci:preflight before pushing.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

No existing docs reference this page or model, so nothing to update.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Bundle size — 🔺 +1.6 KiB (+0.0%)

Uncompressed size of every built .js bundle, compared against the base branch.

Total: 64.34 MiB · 🔺 +1.6 KiB (+0.0%)

File Size Δ vs base
posthog-app/_parent/products/feature_flags/frontend/staff/FeatureFlagsStaffToolsScene.js 12.1 KiB 🔺 +1.6 KiB (+14.7%)

Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report

Eager graph — within budget

How much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy import() / React.lazy chunks are not counted.

Root Eager (shipped) Δ vs base Budget
entry (logged-out pages, app bootstrap)
src/index.tsx
1.21 MiB · 22 files no change ███░░░░░░░ 28.1% of 4.29 MiB
authenticated shell (every logged-in page)
src/scenes/AuthenticatedShell.tsx
8.11 MiB · 2,973 files 🔺 +790 B (+0.0%) █████████░ 87.6% of 9.25 MiB

🟢 node_modules/monaco-editor/ stays out of src/index.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 node_modules/monaco-editor/ stays out of src/scenes/AuthenticatedShell.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx

Largest files eagerly shipped from src/index.tsx
Size File
126.8 KiB ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js
24.6 KiB ../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js
6.3 KiB ../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
4.5 KiB ../node_modules/.pnpm/@jspm+core@2.1.0/node_modules/@jspm/core/nodelibs/browser/process.js
3.9 KiB ../node_modules/.pnpm/scheduler@0.23.2/node_modules/scheduler/cjs/scheduler.production.min.js
1.4 KiB ../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
1.3 KiB src/RootErrorBoundary.tsx
912 B ../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js
789 B src/scenes/ChunkLoadErrorBoundary.tsx
668 B src/index.tsx
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
Size File
278.6 KiB ../node_modules/.pnpm/posthog-js@1.399.2/node_modules/posthog-js/dist/rrweb.js
267.7 KiB ../node_modules/.pnpm/@posthog+icons@0.38.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js
234.9 KiB src/taxonomy/core-filter-definitions-by-group.json
221.5 KiB ../node_modules/.pnpm/posthog-js@1.399.2/node_modules/posthog-js/dist/module.js
164.0 KiB src/queries/validators.js
154.3 KiB ../node_modules/.pnpm/re2js@0.4.1/node_modules/re2js/build/index.esm.js
126.8 KiB ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js
105.9 KiB src/lib/api.ts
93.3 KiB ../node_modules/.pnpm/prosemirror-view@1.40.1/node_modules/prosemirror-view/dist/index.js
90.6 KiB ../node_modules/.pnpm/@tiptap+core@3.20.6_@tiptap+pm@3.20.6/node_modules/@tiptap/core/dist/index.js

Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479

⚠️ Dist folder size — 🔺 +17.6 KiB (+0.0%)

Total size of the built frontend/dist folder (all assets), compared against the base branch.

Total: 1278.76 MiB · 🔺 +17.6 KiB (+0.0%)

ℹ️ MCP UI apps size — 31 app(s), 16373.5 KB JS

Built size of each MCP UI app (main.js + styles.css).

App JS CSS
debug 598.2 KB 179.2 KB
action 456.5 KB 179.2 KB
action-list 563.0 KB 179.2 KB
cohort 455.4 KB 179.2 KB
cohort-list 562.0 KB 179.2 KB
email-template 455.3 KB 179.2 KB
error-details 471.1 KB 179.2 KB
error-issue 456.1 KB 179.2 KB
error-issue-list 562.9 KB 179.2 KB
experiment 560.1 KB 179.2 KB
experiment-list 563.8 KB 179.2 KB
experiment-results 561.8 KB 179.2 KB
feature-flag 565.8 KB 179.2 KB
feature-flag-list 569.5 KB 179.2 KB
feature-flag-testing 459.4 KB 179.2 KB
insight-actors 560.8 KB 179.2 KB
invite-email-preview 454.7 KB 179.2 KB
llm-costs 558.1 KB 179.2 KB
session-recording 457.2 KB 179.2 KB
session-summary 462.5 KB 179.2 KB
survey 457.0 KB 179.2 KB
survey-global-stats 560.9 KB 179.2 KB
survey-list 563.7 KB 179.2 KB
survey-stats 560.8 KB 179.2 KB
trace-span 455.8 KB 179.2 KB
trace-span-list 562.9 KB 179.2 KB
workflow 455.8 KB 179.2 KB
workflow-list 562.4 KB 179.2 KB
query-results 743.7 KB 179.2 KB
render-ui 636.0 KB 179.2 KB
visual-review-snapshots 460.3 KB 179.2 KB

This comment was marked as outdated.

@trunk-io

trunk-io Bot commented Jul 8, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 15 changed files in this pull request and generated no new comments.

@haacked
haacked force-pushed the haacked/staff-tool-improvement branch 2 times, most recently from 6deab7a to c00ec8d Compare July 9, 2026 00:12
@haacked
haacked marked this pull request as ready for review July 9, 2026 00:14
@haacked haacked added the stamphog Request AI approval (no full review) label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🦔 Hogbox preview · ✅ ready

▶ Open the preview

🔑 Login test@posthog.com / 12345678 (demo data)
🧩 Running this PR's backend and frontend, on the PostHog :master base
🔗 Link stable across rebuilds — a re-push swaps the box underneath, the URL stays
🔒 Access tailnet only (PostHog VPN)
🛠️ Admin inspect & debug state in hogland
💤 Idle sleeps after ~30 min idle (snapshot to S3, zero node cost) and wakes on your next visit in ~30s, behind a brief "waking up" screen

commit cd5e924 · box box-e78f74b1b0dd · ready in 673s (push → usable) · build log · rebuilds on every push, torn down on close

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 9, 2026 00:14
@posthog-project-board-bot posthog-project-board-bot Bot moved this to In Review in Feature Flags Jul 9, 2026
@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "chore: update OpenAPI generated types" | Re-trigger Greptile

github-actions[bot]
github-actions Bot previously approved these changes Jul 9, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staff-only, IsStaffUser-gated endpoint that follows the existing staff_cache.py/staff_teams.py pattern, with audit logging, tests, and no schema migration (field already existed); author has strong familiarity and is on the owning team. The one unresolved bot finding (a same-team double-toggle race in the listener) is real at the code level but not reachable through the UI since the switch is disabled via disabledReason while a mutation is pending, so it isn't a practical showstopper for this low-traffic internal tool.

  • Author wrote 100% of the modified lines and has 25 merged PRs in these paths (familiarity STRONG).
  • greptile-apps[bot] reviewed the current head.
  • Greptile flagged that rapid opposite toggles for the same team while a request is in flight could drop the second intent — mitigated in practice by the switch's disabledReason/loading state blocking further clicks during the pending window, but worth a follow-up hardening pass if this tool sees heavier use.
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 328L, 9F substantive, 665L/15F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1d-complex (665L, 15F, two-areas, feat)
stamphog 2.0.0b3 .stamphog/policy.yml @ fc9ea12 · reviewed head c00ec8d

@github-project-automation github-project-automation Bot moved this from In Review to Approved in Feature Flags Jul 9, 2026
@haacked
haacked enabled auto-merge (squash) July 9, 2026 00:31
@github-actions
github-actions Bot dismissed their stale review July 9, 2026 19:24

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staff-only toggle for an existing internal flag, gated by the established IsStaffUser permission (matches the existing staff_cache.py pattern), with solid test coverage and all review comments resolved; author is on the owning team with strong recent familiarity and a teammate already approved the current head.

  • Author wrote 100% of the modified lines and has 25 merged PRs in these paths (familiarity STRONG).
  • 👍 on the PR from greptile-apps[bot], hex-security-app[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 332L, 9F substantive, 669L/15F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1d-complex (669L, 15F, two-areas, feat)
stamphog 2.0.0b3 .stamphog/policy.yml @ 354525e · reviewed head 06b7143

haacked and others added 3 commits July 13, 2026 12:08
posthog.tasks.team_metadata sits under posthog.tasks, whose __init__ is a
celery autoimport aggregator that pulls in every task module. Importing it
at module level in the new staff team-config viewset meant its 4 signal
receivers only wired up when the API router was built, so a process that
never builds the router (celery, temporal, migrate, shell) would lose them.
Defer the import to call time instead.
@haacked
haacked force-pushed the haacked/staff-tool-improvement branch from 06b7143 to cd5e924 Compare July 13, 2026 19:09
@haacked
haacked merged commit ff0cedb into master Jul 13, 2026
260 checks passed
@haacked
haacked deleted the haacked/staff-tool-improvement branch July 13, 2026 19:26
@github-project-automation github-project-automation Bot moved this from Approved to Done in Feature Flags Jul 13, 2026
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-13 19:56 UTC Run
prod-us ✅ Deployed 2026-07-13 20:07 UTC Run
prod-eu ✅ Deployed 2026-07-13 20:09 UTC Run

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

Labels

feature/feature-flags Feature Tag: Feature flags stamphog Request AI approval (no full review) team/feature-flags

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants