Skip to content

feat(alerts): investigate platform-owned insight firings with the agent - #127923

Merged
trunk-io[bot] merged 8 commits into
jimmy/insight-investigation-agent-rowsfrom
jimmy/insight-investigation-adapter
Nov 3, 2026
Merged

trunk-io[bot] merged 8 commits into
jimmy/insight-investigation-agent-rowsfrom
jimmy/insight-investigation-adapter

Conversation

@jzhu13

@jzhu13 jzhu13 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • A platform-owned insight alert with the investigation agent on gets no investigation, and a gated alert sends its firing without waiting for a verdict.
  • This layer starts the agent from the platform. It builds on the agent's platform path in #127922.

Changes

  • A firing of an owned alert follows the insight stack's investigation rules. A parallel-run check never decides, so it never pays for an agent run.
  • A gated alert holds the firing's delivery until the verdict, for up to 90 minutes.
  • A firing past the episode budget is muted when the firing's last verdict suppresses it.
  • After each chunk's record, a claim task writes the investigation row and starts the agent on the AI queue with ABANDON, behind a patch. The task never blocks the next record or admission round.
  • A skipped check of a firing alert asks for no investigation.
  • A refused claim releases the held firing by the firing's last verdict.
  • A failed investigation decision leaves the firing to go out uninvestigated, rather than erroring the check.

How did you test this code?

Test rationale: the source-cycle cases catch a parallel run asking for an agent, a gated firing sent early, a muted firing still delivered, and a refused claim that never releases its hold. They extend the existing owned-check tests.

Ran the alerts and alerts platform suites locally, and repo-wide mypy. Not run: a workflow run against a Temporal server.

Release status

  • No feature flag controls this change

Docs update

  • None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

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

Skills: /writing-tests, /writing-code-comments, /writing-user-facing-copy, /stacking-prs, /reviewing-with-coderabbit, /simplify, /code-review, /writing-pr-descriptions

  • No duplicate: no open PR builds the agent's platform path.
  • Public artifact: nothing here comes from customer material.
  • CI report, comment density: each added comment states a reason (a patch marker, an ordering constraint, or a failure path), so none were cut.
  • CodeRabbit CLI: skipped. The CLI refused both runs (rate limit, then no assigned seat), so the bot's review on this PR is the CodeRabbit pass.

🤖 Generated with Claude Code

A firing of an alert the platform owns now follows the insight stack's
investigation rules. The check decides whether the firing gets an
investigation, holds a gated alert's delivery until the verdict, and mutes a
firing past the budget whose last verdict suppresses it. Only an owned check
decides, so a parallel run never pays for an agent run.

After the record, a new claim activity writes the investigation row and the
evaluate workflow starts the agent on the AI queue, behind a patch. A refused
claim releases the held firing by the firing's last verdict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jzhu13 jzhu13 self-assigned this Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 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.

⚠️ Comment density — 4% of added code lines are comments (16 of 457)

This section warns when comments are more than 3% of the code lines a PR adds, and alerts above 6%. Before agent-assisted PRs, the typical share was about 2%. Only full-line comments count. Docstrings, generated files, snapshots, migrations, and workflow files are left out.

Comments that restate the code, record how the change came about, or narrate the next line add noise for the next reader. Keep the comments that explain a reason the code cannot show, and remove the rest. See .agents/skills/writing-code-comments/SKILL.md for the house rules.

Files with the most added comment lines:

File Comment lines Added lines
products/alerts/backend/temporal/platform_evaluate.py 5 62
products/alerts/backend/platform_investigation.py 3 122
products/alerts/backend/platform_investigation_detail.py 3 49
products/alerts/backend/platform_source_cycle.py 2 9
products/alerts_platform/backend/logic/delivery_holds.py 2 40
products/alerts_platform/backend/tests/test_delivery_evaluation.py 1 54

This check does not block merging. It updates on every push and clears when the share drops.

⚠️ Backend coverage — 87.0% of changed backend lines covered — 46 uncovered

🧪 Backend test coverage

Patch coverage — changed backend lines (products + core): █████████████████░░░ 87.0% (311 / 357)

File Patch Uncovered changed lines
products/alerts/backend/temporal/platform_evaluate.py 48.6% 174–175, 358, 360, 434, 785, 788–790, 795–796, 803, 806–807, 810–811, 818, 820
products/alerts_platform/backend/facade/api.py 50.0% 89, 100
products/alerts/backend/platform_investigation_detail.py 71.9% 23–27, 32, 37, 54–55
products/alerts_platform/backend/facade/testing.py 72.7% 82, 105, 110
products/alerts/backend/facade/investigations.py 73.3% 23, 28, 33, 46
products/alerts/backend/investigation_release.py 88.9% 95–96, 99, 105–106, 109
products/alerts/backend/platform_investigation.py 92.5% 157, 197, 201, 227

🤖 Agents: add a test only if an uncovered line exposes a realistic regression that existing tests miss. Otherwise explain why no new test is needed under "How did you test this code?". Gap list: the patch-coverage artifact on this run (gh run download 355140927939397 -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
data_tools ████████████░░░░░░░░ 60.9% 95 / 156
warehouse_sources_queue █████████████░░░░░░░ 65.2% 2,161 / 3,314
demo █████████████░░░░░░░ 65.7% 1,803 / 2,743
batch_exports ████████████████░░░░ 82.2% 23,567 / 28,654
engineering_analytics █████████████████░░░ 84.9% 11,699 / 13,779
commands █████████████████░░░ 85.4% 1,621 / 1,898
ml_inference █████████████████░░░ 86.3% 524 / 607
mcp_analytics █████████████████░░░ 86.3% 5,803 / 6,722
posthog_ai ██████████████████░░ 87.9% 4,303 / 4,895
apm ██████████████████░░ 88.2% 1,973 / 2,236
notebooks ██████████████████░░ 88.5% 15,356 / 17,347
mcp_registry ██████████████████░░ 89.0% 1,596 / 1,794
webmcp ██████████████████░░ 89.3% 292 / 327
dashboards ██████████████████░░ 89.4% 8,048 / 9,003
product_tours ██████████████████░░ 89.7% 1,355 / 1,510
warehouse_suggestions ██████████████████░░ 89.9% 3,707 / 4,124
cohorts ██████████████████░░ 90.1% 8,996 / 9,990
signals ██████████████████░░ 90.5% 99,655 / 110,121
today ██████████████████░░ 90.6% 3,495 / 3,859
visual_review ██████████████████░░ 90.7% 9,852 / 10,863
managed_warehouse ██████████████████░░ 91.2% 12,686 / 13,914
canvas ██████████████████░░ 91.2% 8,203 / 8,994
tasks ██████████████████░░ 91.3% 82,102 / 89,969
data_warehouse ██████████████████░░ 91.3% 15,700 / 17,201
autoresearch ██████████████████░░ 91.5% 11,717 / 12,805
data_modeling ██████████████████░░ 91.5% 11,198 / 12,233
cdp ██████████████████░░ 91.5% 10,432 / 11,396
metrics ██████████████████░░ 91.7% 11,234 / 12,253
slack_app ██████████████████░░ 91.8% 21,946 / 23,913
wizard ██████████████████░░ 91.8% 6,868 / 7,479
streamlit_apps ██████████████████░░ 91.9% 3,139 / 3,415
business_knowledge ██████████████████░░ 92.0% 10,505 / 11,423
review_hog ██████████████████░░ 92.3% 17,768 / 19,256
conversations ██████████████████░░ 92.3% 31,158 / 33,746
error_tracking ███████████████████░ 92.5% 20,487 / 22,146
authorization ███████████████████░ 92.5% 544 / 588
alerts_platform ███████████████████░ 92.6% 8,487 / 9,170
stamphog ███████████████████░ 92.6% 8,871 / 9,584
early_access_features ███████████████████░ 92.6% 1,339 / 1,446
notifications ███████████████████░ 92.8% 1,218 / 1,312
alerts ███████████████████░ 92.9% 11,312 / 12,176
aeo ███████████████████░ 93.0% 2,150 / 2,312
surveys ███████████████████░ 93.3% 7,248 / 7,772
ai_training ███████████████████░ 93.3% 598 / 641
web_analytics ███████████████████░ 93.4% 26,448 / 28,325
ai_gateway ███████████████████░ 93.6% 787 / 841
messaging ███████████████████░ 93.7% 6,756 / 7,214
approvals ███████████████████░ 93.7% 5,004 / 5,341
cross_project_dashboards ███████████████████░ 93.7% 862 / 920
marketing_analytics ███████████████████░ 93.7% 21,955 / 23,420
context_layer ███████████████████░ 93.8% 3,984 / 4,247
exports ███████████████████░ 93.8% 4,314 / 4,597
workflows ███████████████████░ 93.8% 27,397 / 29,194
mcp_store ███████████████████░ 93.9% 9,188 / 9,784
ai_observability ███████████████████░ 93.9% 32,676 / 34,793
billing_alerts ███████████████████░ 94.0% 2,322 / 2,470
customer_analytics ███████████████████░ 94.0% 29,900 / 31,794
managed_migrations ███████████████████░ 94.1% 1,877 / 1,994
replay_vision ███████████████████░ 94.4% 33,326 / 35,317
legal_documents ███████████████████░ 94.4% 2,313 / 2,451
logs ███████████████████░ 94.5% 19,432 / 20,567
experiments ███████████████████░ 94.7% 43,959 / 46,433
reminders ███████████████████░ 94.8% 782 / 825
actions ███████████████████░ 94.9% 997 / 1,051
endpoints ███████████████████░ 94.9% 9,566 / 10,077
growth ███████████████████░ 95.0% 11,563 / 12,176
annotations ███████████████████░ 95.1% 1,097 / 1,153
skills ███████████████████░ 95.2% 7,633 / 8,018
uptime_monitoring ███████████████████░ 95.3% 306 / 321
access_control ███████████████████░ 95.5% 8,358 / 8,753
subscriptions ███████████████████░ 95.6% 13,645 / 14,275
data_catalog ███████████████████░ 95.7% 4,715 / 4,928
product_analytics ███████████████████░ 95.8% 30,289 / 31,620
feature_flags ███████████████████░ 95.8% 29,654 / 30,953
revenue_analytics ███████████████████░ 95.9% 1,877 / 1,958
data_quality ███████████████████░ 96.0% 8,561 / 8,915
tracing ███████████████████░ 96.5% 4,564 / 4,729
warehouse_sources ███████████████████░ 96.5% 492,991 / 510,624
account_audits ███████████████████░ 96.7% 770 / 796
security ███████████████████░ 96.8% 1,597 / 1,650
pulse ███████████████████░ 97.3% 2,036 / 2,093
analytics_platform ████████████████████ 97.9% 2,862 / 2,922
groups ████████████████████ 98.3% 1,864 / 1,897
field_notes ████████████████████ 99.4% 172 / 173

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.

@posthog posthog 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.

PostHog Review · Standard · reviewed bf93cb0: 2 Should fix.

This is the only automatic review while this pull request is a draft. Comment @posthog review to review new changes sooner. Otherwise, a review of the new changes runs when you mark it ready for review.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

@jzhu13
jzhu13 marked this pull request as ready for review November 3, 2026 02:51
@parameterai

parameterai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Risk: No findings

This delta fixes the timezone differential in the hold-release staleness check by normalizing both the Postgres firing start and the ClickHouse episode start to aware UTC datetimes before comparing, and adds a regression test that feeds a zoneless episode start through the real comparison path. No new behavior or security surface is introduced beyond the comparison helper.

Sentinel reviewed c10005e · Review settings

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team November 3, 2026 02:52
jzhu13 and others added 2 commits November 2, 2026 18:56
…ght-investigation-adapter

# Conflicts:
#	products/alerts/backend/platform_investigation.py
… record loop

A skipped check of a firing alert keeps its state without evaluating, so it
no longer asks for an agent run. Investigation claims now run as tasks after
each chunk's record, awaited before the run returns, so a slow claim no longer
holds back the next record or admission round.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@posthog posthog 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.

PostHog Review · Standard · reviewed 2208bae: 1 Must fix.

jzhu13 and others added 2 commits November 2, 2026 19:33
…has ended

A held evaluation can be released after a later one resolved the firing it
held, and nothing orders the two sends, so its trigger opened an incident no
resolve followed. Delivery now sends a released hold's incident trigger only
while its group is still in the firing the held evaluation saw. The message
still goes out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jzhu13 jzhu13 added the stamphog Request AI approval (no full review) label Nov 3, 2026

@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.

Not approved — this change needs a human reviewer.

Re-add the stamphog label to request another review once you have addressed this.

Owning-team authorship and STRONG familiarity provide assurance for the risky write path, but @PostHog's substantive incident-ordering concern remains unresolved. Address that thread with episode-aware delivery coordination and get @PostHog/team-apm to review the fix before re-requesting.

  • Author wrote 100% of the modified lines and has 25 merged PRs in these paths (familiarity STRONG).
  • @PostHog, products/alerts/backend/platform_investigation.py: the held-trigger versus recovery-resolve ordering concern remains unfixed. with_investigation holds the original delivery, while platform_source_cycle.py::_incident_actions independently generates the recovery resolve; delivery_holds.py returns the stored trigger on release without checking whether its episode recovered. Coordinate the held trigger and its episode's resolve, add a recovery-before-verdict regression test, and request review from @PostHog/team-apm before re-requesting.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 276L, 4F substantive, 404L/5F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1d-complex (404L, 5F, single-area, feat)
stamphog 2.7.0 .stamphog/policy.yml @ 7d60245 · reviewed head 7d60245

@stamphog stamphog Bot removed the stamphog Request AI approval (no full review) label Nov 3, 2026
@jzhu13 jzhu13 added the stamphog Request AI approval (no full review) label Nov 3, 2026

@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.

Not approved — this change needs a human reviewer.

Re-add the stamphog label to request another review once you have addressed this.

Owning-team authorship, strong familiarity, and current-head assurance cover the risky changes, but @parameterai's substantive concern remains unfixed. Address the timestamp comparison in delivery_holds.py and its regression coverage, then request review from @PostHog/team-apm before re-requesting.

  • Author wrote 100% of the modified lines and has 42 merged PRs in these paths (familiarity STRONG).
  • PostHog Review (Standard) reviewed the current head: no findings.
  • @parameterai on products/alerts_platform/backend/logic/delivery_holds.py:183–212, reiterated by @parameterai[bot]: the current staleness comparison still compares timezone-aware PostgreSQL firing timestamps against unnormalized ClickHouse episode timestamps. The announcement reader passes those timestamps through unchanged, while delivery/dispatch.py explicitly normalizes naive ClickHouse timestamps elsewhere. Consequently, a still-current held firing can lose its incident trigger in delivery/evaluation.py, silently preventing PagerDuty notification. Normalize timestamps before comparison and add a test using a naive announcement timestamp before re-requesting.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 325L, 6F substantive, 499L/8F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1d-complex (499L, 8F, single-area, feat)
stamphog 2.7.0 .stamphog/policy.yml @ 2775218 · reviewed head 2775218

@stamphog stamphog Bot removed the stamphog Request AI approval (no full review) label Nov 3, 2026
ClickHouse can return a history row's episode start without a zone, and a
naive time never equals the aware one Postgres stores, so every held trigger
looked stale and was dropped. Both sides are now compared in UTC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jzhu13 jzhu13 added the stamphog Request AI approval (no full review) label Nov 3, 2026

@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.

Approved.

The changes enter investigation and delivery write paths, with assurance from the owning-team author, STRONG familiarity, and a current-head review reporting no findings. No concrete unresolved review concern or other refusal ground is present.

  • Author wrote 100% of the modified lines and has 42 merged PRs in these paths (familiarity STRONG).
  • PostHog Review (Standard) reviewed the current head: no findings.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 335L, 6F substantive, 522L/8F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1d-complex (522L, 8F, single-area, feat)
stamphog 2.7.0 .stamphog/policy.yml @ c10005e · reviewed head c10005e

@jzhu13
jzhu13 removed this pull request from stack #127927 November 3, 2026 05:07
@jzhu13
jzhu13 added this pull request to stack #127948 November 3, 2026 05:08
@trunk-io

trunk-io Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request is queued for merge as part of 127925, which will merge 127922, 127923, 127925.

@trunk-io
trunk-io Bot merged commit a69149d into master Nov 3, 2026
303 checks passed
@trunk-io
trunk-io Bot deleted the jimmy/insight-investigation-adapter branch November 3, 2026 22:34
@trunk-io

trunk-io Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request was merged into master as part of stacked PR 127925.

@deployment-status-posthog

deployment-status-posthog Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-11-03 23:11 UTC Run
prod-us ✅ Deployed 2026-11-03 23:34 UTC Run
prod-eu ✅ Deployed 2026-11-03 23:32 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