Skip to content

fix: attribute PostHog events to automation actors - #265

Merged
neubig merged 3 commits into
mainfrom
agent/posthog-actor-attribution
Jul 27, 2026
Merged

fix: attribute PostHog events to automation actors#265
neubig merged 3 commits into
mainfrom
agent/posthog-actor-attribution

Conversation

@neubig

@neubig neubig commented Jul 26, 2026

Copy link
Copy Markdown
Member

Why

Automations currently emits every event under one backend-wide PostHog distinct_id, including when local automations are launched through Agent Canvas. This fragments one person's Canvas and automation activity and forces dashboards to recover identity with expensive coalesce(cloud_user_id, distinct_id) HogQL.

PostHog recommends identifying authenticated users with a unique, stable ID and retaining the same identity across their activity: https://posthog.com/docs/product-analytics/identify

Fixes #264.

Summary

  • Use the server-authoritative Cloud user ID for Cloud automation events.
  • Persist the initiating Canvas PostHog ID on local automations and runs so scheduled, webhook, and other background lifecycle events keep the same actor.
  • Require consent for the exact resolved local actor; unattributed backend events retain the installation fallback.
  • Strip browser-provided actor IDs at the Cloud trust boundary before event capture or database persistence.

Testing

  • uv run ruff format --check openhands/automation/telemetry.py tests/test_telemetry.py tests/test_router.py
  • uv run ruff check openhands/automation/telemetry.py tests/test_telemetry.py tests/test_router.py
  • uv run pyright openhands/automation/telemetry.py tests/test_telemetry.py — 0 errors
  • uv run pytest -q — 1,065 passed
  • Alembic SQLite smoke test: upgrade to head, downgrade to 011, and upgrade to head completed successfully

The tests cover Cloud and local identity selection, exact per-actor consent, manual dispatch, scheduled runs, webhook runs, API route events, background attribution, the headerless backend fallback, and rejection of spoofed Cloud browser identity.

Notes

The new columns are nullable so existing automations and runs continue to fall back safely. Browser IDs are only accepted in local mode; Cloud derives identity exclusively from authenticated server state.

The companion Agent Canvas PR identifies Cloud sessions, preserves the Canvas actor across local-backend use, and safely hands off revocation before PostHog resets identity: OpenHands/agent-canvas#1948

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Coverage

@neubig
neubig marked this pull request as ready for review July 27, 2026 13:01

@malhotra5 malhotra5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@neubig
neubig merged commit 723f251 into main Jul 27, 2026
12 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.4.0 Shipped in 1.4.0 label Jul 27, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.4.0.

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

Labels

released: 1.4.0 Shipped in 1.4.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attribute automation telemetry to Cloud and Canvas actors

2 participants