Skip to content

fix(pi): name why an agent run aborted - #1249

Open
Gilbert09 wants to merge 1 commit into
mainfrom
posthog/pi-abort-reason
Open

fix(pi): name why an agent run aborted#1249
Gilbert09 wants to merge 1 commit into
mainfrom
posthog/pi-abort-reason

Conversation

@Gilbert09

Copy link
Copy Markdown
Member

Problem

Both pi entry points — piBackend.run and runPiTask, the one the orchestrator
drives — fire a single agent aborted event from several unrelated terminal
paths:

  • a YARA security termination,
  • a run that made no tool call at all,
  • a run that left its own plan open,
  • a rate limit,
  • a generic gateway error.

The event carried only duration_* and model, so all five arrived as the same
unlabelled abort. In the current data for the data-source setup flow, agent aborted shows up with an empty reason dimension, alongside an equal number of
tasks failed as no-report — the same runs, seen from the queue's side. A task
agent that died can be counted but not diagnosed, and one of the five causes is a
security termination on the one step that handles live credentials.

The linear sequence's own agent aborted has carried a reason all along; only
the pi harness omits it.

Why

Came out of reading the telemetry for the wizard's data-source setup task. This
does not change the funnel — it makes the handful of runs that end this way
attributable, so the next read of that telemetry can tell a security stop from a
rate limit instead of guessing.

Changes

  • captureAborted takes the AgentErrorType the path is about to return and
    stamps it as reason. The discriminator was already in hand at every call
    site — each returns that type on the next line. It is a closed enum, so no
    free text reaches telemetry.
  • Both entry points classified a thrown message with the same two needles,
    inline and after the capture, which is why the type was not available to the
    event. That moves to runErrorType in completion.ts, beside
    completionFailure, and is unit-tested there.

No behaviour changes for the user: every path returns exactly the same
AgentResult as before.

Related but not the same fix: #1109
touches these two lines to add an abort_kind that separates a pi run-incomplete
event from the linear [ABORT] one. It is a constant per site, so it does not
say which pi path fired. The two are complementary.

Test plan

  • runErrorType unit tests added to the existing completion.test.ts.
  • vitest run src/lib/agent/runner/harness/pi — 127 tests pass.
  • tsc --noEmit introduces no new errors in the harness; prettier and eslint
    clean on the touched files.

Created with PostHog Desktop

Both pi entry points fire one `agent aborted` event from several unrelated
terminal paths: a security termination, a run that made no tool call, a run
that left its own plan open, a rate limit, and a generic gateway error. The
event carried only duration and model, so every one of those arrived as the
same unlabelled abort. The linear sequence's own `agent aborted` has carried a
`reason` all along.

The discriminator was already in hand at every call site — each one returns an
`AgentErrorType` on the next line — so `captureAborted` now takes it and stamps
it on the event. The value is a closed enum, so no free text reaches telemetry.

The two entry points classified a thrown message with the same two needles,
inline and *after* the capture, which is why the type was not available to the
event. That classification moves to `runErrorType` in `completion.ts`, next to
`completionFailure`, and is unit-tested there.

Generated-By: PostHog Desktop
Task-Id: 0af1c1f6-2aab-4807-8e24-86b2a9eb18fd
@Gilbert09
Gilbert09 requested a review from a team as a code owner September 12, 2026 11:57
Copilot AI lite review requested due to automatic review settings September 12, 2026 11:57

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a Context Mill branch:

  • /wizard-ci all context-mill:my-branch

Add context-mill:<branch> to any command above to pin the Context Mill branch. It defaults to main.

Results will be posted here when complete.

@Gilbert09 Gilbert09 added the stamphog Auto-merge stamp for automated PRs label Sep 12, 2026 — with PostHog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Auto-merge stamp for automated PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants