Skip to content

feat(aio): activity-log prompt lifecycle events into the history tab - #73436

Merged
jurajmajerik merged 2 commits into
masterfrom
ai-observability/prompt-lifecycle-activity-log
Jul 24, 2026
Merged

feat(aio): activity-log prompt lifecycle events into the history tab#73436
jurajmajerik merged 2 commits into
masterfrom
ai-observability/prompt-lifecycle-activity-log

Conversation

@jurajmajerik

Copy link
Copy Markdown
Contributor

Problem

The prompt History tab only shows label events (create/move/remove). Publishing a version, archiving a prompt, or duplicating one leaves no trace, so the tab is not a full audit trail.

Changes

Log prompt lifecycle events under a new LLMPrompt activity scope and show them in the History tab together with the label events:

  • created: logged when a prompt is created. When it was created by duplicating another prompt, the entry records which one.
  • published: logged with the version movement (v1 to v2) and the version description.
  • archived: logged with how many versions were archived. The archive endpoint now passes the acting user through, it had no user before.
  • duplicated: the source prompt also gets an entry recording where the copy went, so both prompts have a complete history.

Frontend: new describer for the lifecycle entries, and the History tab now queries both scopes (LLMPrompt + LLMPromptLabel) in one request. The entries share the same item_id key as the label events, so they merge into one stream.

Design notes:

  • The logging is done with explicit log_activity calls from the service functions, not by adding ModelActivityMixin to LLMPrompt. Each LLMPrompt row is a version, so the mixin would log a generic "created" for every version row instead of meaningful lifecycle events.
  • Impersonation status comes from the request-scoped activity storage, the same source the mixin path uses. This keeps the service function signatures clean.

How did you test this code?

Added one flow test that runs create, publish, label, duplicate, archive through the API and checks three things no existing test covers: that each lifecycle action writes an entry with the right scope, key and payload, that the publish entry carries the version movement the describer renders, and that the two-scope query the History tab issues returns the merged stream. The last part guards against the "unknown scope silently returns an empty list" failure that bit the labels work earlier.

Also ran: the full test_llm_prompt.py file (112 passed), repo-wide mypy, frontend TypeScript check, and the prompts jest suite. I did not manually test the UI.

Automatic notifications

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

Docs update

No docs change needed, the History tab behavior is additive and not separately documented.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude Code implemented this from a handover doc that mapped the four frontend registration points a new activity scope needs. Skills invoked: /improving-drf-endpoints (viewset touch), /writing-tests (test gate). Considered ModelActivityMixin + signal receiver and rejected it (see design notes); the explicit-call approach also avoids the setup-receiver CI baseline.

@jurajmajerik jurajmajerik self-assigned this Jul 24, 2026
@jurajmajerik
jurajmajerik marked this pull request as ready for review July 24, 2026 07:39
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

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

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

Total: 64.39 MiB · 🔺 +5.0 KiB (+0.0%)

File Size Δ vs base
render-query/src/render-query/render-query.js 21.26 MiB 🔺 +1.7 KiB (+0.0%)
exporter/src/lib/components/ActivityLog/describers.js 130.7 KiB 🔺 +1.6 KiB (+1.3%)
posthog-app/src/lib/components/ActivityLog/describers.js 132.8 KiB 🔺 +1.6 KiB (+1.3%)

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.24 MiB · 22 files no change ███░░░░░░░ 27.5% of 4.51 MiB
authenticated shell (every logged-in page)
src/scenes/AuthenticatedShell.tsx
8.07 MiB · 3,010 files 🔺 +37 B (+0.0%) ████████░░ 83.0% of 9.71 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
762 B src/index.tsx
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
Size File
281.5 KiB ../node_modules/.pnpm/posthog-js@1.407.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
236.0 KiB src/taxonomy/core-filter-definitions-by-group.json
226.1 KiB ../node_modules/.pnpm/posthog-js@1.407.2/node_modules/posthog-js/dist/module.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.8 KiB src/lib/api.ts
94.0 KiB ../packages/quill/packages/quill/dist/index.js
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

Toolbar bundle — eager 2.18 MiB within budget

What the toolbar ships to customer pages, measured from the esbuild output (minified, post-tree-shake). The eager set is the entry plus everything statically imported from it — fetched before any feature runs; deferred chunks load lazily. The eager guardrail is 5.72 MiB. Each output file must also stay below 10 MB, where CloudFront stops compressing it. The module boundary is enforced separately by check-toolbar-graph.

Metric Size Δ vs base Budget
Eager (shipped)
entry + static imports
2.18 MiB · 17 files no change ████░░░░░░ 38.1% of 5.72 MiB
Deferred (lazy) 2.07 MiB · 33 files no change n/a — loads on demand
Loader dist/toolbar.js 1.1 KiB no change █░░░░░░░░░ 5.8% of 19.5 KiB
Largest eagerly-shipped chunks
Size File
713.8 KiB dist/toolbar/toolbar-app-HLTHZTTF.css
545.0 KiB dist/toolbar/chunk-chunk-UJDK5OYX.js
484.2 KiB dist/toolbar/chunk-chunk-FFAAFRZ5.js
133.6 KiB dist/toolbar/chunk-chunk-LFULHWXM.js
131.8 KiB dist/toolbar/chunk-chunk-T5KY5WYR.js
71.0 KiB dist/toolbar/toolbar-app-3HDXC5F6.js
69.0 KiB dist/toolbar/chunk-chunk-27JL52RE.js
35.6 KiB dist/toolbar/chunk-chunk-G7TJFD3T.js
20.9 KiB dist/toolbar/chunk-chunk-PJWUEIPT.js
12.2 KiB dist/toolbar/chunk-chunk-PIK3PADE.js

Posted automatically by check-toolbar-size · sizes are toolbar output bytes (shipped, post-tree-shake) from the esbuild metafile

Dist folder size — 🔺 +22.9 KiB (+0.0%)

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

Total: 1352.23 MiB · 🔺 +22.9 KiB (+0.0%)

Playwright — all passed

All tests passed.

View test results →

⚠️ Backend coverage — 97.0% of changed backend lines covered — 1 uncovered

🧪 Backend test coverage

Patch coverage — changed backend lines (products + core): ███████████████████░ 97.0% (47 / 48)

File Patch Uncovered changed lines
products/ai_observability/backend/activity_logging.py 75.0% 58

🤖 Agents: add a test covering the lines above, or note why under "How did you test this code?". Machine-readable gap list: the patch-coverage artifact on this run (gh run download 30080056371 -n patch-coverage), or the coverage-data block at the end of this comment.

Per-product line coverage (touched products)
Product Coverage Lines
platform_features ██░░░░░░░░░░░░░░░░░░ 12.1% 7 / 58
batch_exports ████████░░░░░░░░░░░░ 39.6% 8,412 / 21,249
demo ███████████░░░░░░░░░ 56.2% 1,497 / 2,663
warehouse_sources_queue ████████████░░░░░░░░ 59.2% 148 / 250
tasks ██████████████░░░░░░ 69.4% 30,050 / 43,291
data_tools ██████████████░░░░░░ 70.0% 63 / 90
ai_gateway ███████████████░░░░░ 75.0% 9 / 12
signals ████████████████░░░░ 80.0% 22,090 / 27,597
cdp ████████████████░░░░ 81.0% 3,144 / 3,881
data_modeling █████████████████░░░ 82.7% 5,547 / 6,708
wizard █████████████████░░░ 84.8% 935 / 1,102
notebooks █████████████████░░░ 85.3% 7,275 / 8,531
agent_platform █████████████████░░░ 86.4% 3,807 / 4,405
actions █████████████████░░░ 86.6% 717 / 828
cohorts ██████████████████░░ 87.8% 4,488 / 5,114
product_tours ██████████████████░░ 87.9% 1,303 / 1,482
exports ██████████████████░░ 88.4% 6,949 / 7,861
data_warehouse ██████████████████░░ 88.9% 11,887 / 13,378
business_knowledge ██████████████████░░ 89.0% 4,391 / 4,936
conversations ██████████████████░░ 89.3% 16,869 / 18,883
engineering_analytics ██████████████████░░ 89.4% 6,386 / 7,145
visual_review ██████████████████░░ 89.4% 5,818 / 6,505
dashboards ██████████████████░░ 89.5% 5,989 / 6,693
error_tracking ██████████████████░░ 89.7% 10,166 / 11,334
alerts ██████████████████░░ 90.0% 4,056 / 4,508
early_access_features ██████████████████░░ 90.1% 1,031 / 1,144
mcp_analytics ██████████████████░░ 90.1% 2,763 / 3,065
streamlit_apps ██████████████████░░ 90.4% 2,501 / 2,767
links ██████████████████░░ 90.6% 183 / 202
slack_app ██████████████████░░ 90.7% 9,028 / 9,951
marketing_analytics ██████████████████░░ 91.0% 11,792 / 12,964
stamphog ██████████████████░░ 91.1% 4,056 / 4,450
mcp_store ██████████████████░░ 91.9% 4,257 / 4,634
product_analytics ███████████████████░ 92.6% 5,850 / 6,320
notifications ███████████████████░ 92.6% 1,011 / 1,092
ai_observability ███████████████████░ 92.8% 15,043 / 16,217
surveys ███████████████████░ 93.0% 5,730 / 6,163
managed_migrations ███████████████████░ 93.1% 1,424 / 1,530
web_analytics ███████████████████░ 93.1% 14,426 / 15,492
posthog_ai ███████████████████░ 93.2% 1,326 / 1,422
approvals ███████████████████░ 93.3% 3,437 / 3,682
reminders ███████████████████░ 93.4% 468 / 501
workflows ███████████████████░ 93.6% 6,390 / 6,826
legal_documents ███████████████████░ 94.1% 1,568 / 1,667
endpoints ███████████████████░ 94.1% 8,640 / 9,177
messaging ███████████████████░ 94.3% 2,682 / 2,845
tracing ███████████████████░ 94.5% 2,670 / 2,826
review_hog ███████████████████░ 94.7% 6,814 / 7,199
skills ███████████████████░ 94.7% 3,300 / 3,483
logs ███████████████████░ 95.4% 10,012 / 10,498
experiments ███████████████████░ 95.7% 25,036 / 26,159
growth ███████████████████░ 96.1% 3,245 / 3,376
annotations ███████████████████░ 96.2% 732 / 761
replay_vision ███████████████████░ 96.2% 15,260 / 15,864
revenue_analytics ███████████████████░ 96.3% 1,887 / 1,960
feature_flags ███████████████████░ 96.5% 17,110 / 17,734
user_interviews ███████████████████░ 96.5% 2,638 / 2,734
access_control ███████████████████░ 96.9% 870 / 898
customer_analytics ███████████████████░ 97.1% 9,047 / 9,317
warehouse_sources ███████████████████░ 97.1% 330,460 / 340,224
data_catalog ███████████████████░ 97.4% 2,367 / 2,429
analytics_platform ████████████████████ 98.0% 2,153 / 2,197
metrics ████████████████████ 98.2% 2,491 / 2,536
pulse ████████████████████ 98.4% 2,017 / 2,049
live_debugger ████████████████████ 99.2% 613 / 618
field_notes ████████████████████ 99.4% 158 / 159

Report-only. Patch coverage = changed backend lines covered vs origin/master. Sorted lowest first.
Known gaps: lines covered only by Temporal tests show as uncovered; core line numbers may drift if master changed the same file.

@github-actions
github-actions Bot requested a deployment to preview-pr-73436 July 24, 2026 07:40 In progress
@github-actions

github-actions Bot commented Jul 24, 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 1303edf · box box-caeb2b5ff345 · ready in 840s (push → usable) · build log · rebuilds on every push, torn down on close

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team July 24, 2026 07:40
@pr-assigner-resolver-posthog

Copy link
Copy Markdown

👀 Auto-assigned reviewers

These soft owners were skipped because they only have minor changes here. Nothing blocks merge, so self-assign if you'd like a look:

  • @PostHog/team-platform-features (posthog/models/owners.yaml)

Soft owners come from each directory's owners.yaml and each product's product.yaml (resolved nearest-file-wins). The locator after each owner is the file that decided it. Generated files and lockfiles are ignored when deciding ownership.

Comment thread posthog/api/services/llm_prompt.py
@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(aio): activity-log prompt lifecycle..." | Re-trigger Greptile

Comment thread posthog/api/test/test_llm_prompt.py

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additive activity-log feature with no schema/migration or access-control regression: the scope field is a plain CharField, and the activity-log endpoint's team-scoped (not per-resource) authorization is pre-existing and applies identically to every scope already. The one security finding was raised and resolved on-thread by the same agent reviewer (hex-security-app) after confirming this isn't a new bypass, and the test-correctness concern from Graphite was factually incorrect (verified against prompt_activity_item_id, which returns short names unhashed) and correctly rebutted by the author.

  • Author wrote 25% of the modified lines and has 267 merged PRs in these paths (familiarity MODERATE).
  • hex-security-app[bot] reviewed the current head.
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 190L, 10F substantive, 258L/12F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1d-complex (258L, 12F, cross-cutting, feat)
stamphog 2.0.0b3 .stamphog/policy.yml @ 080c246 · reviewed head 1303edf

@jurajmajerik
jurajmajerik enabled auto-merge (squash) July 24, 2026 08:54
@jurajmajerik
jurajmajerik merged commit c43608d into master Jul 24, 2026
445 of 447 checks passed
@jurajmajerik
jurajmajerik deleted the ai-observability/prompt-lifecycle-activity-log branch July 24, 2026 09:14
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-24 09:50 UTC Run
prod-us ✅ Deployed 2026-07-24 10:13 UTC Run
prod-eu ✅ Deployed 2026-07-24 10:12 UTC Run

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

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant