Skip to content

fix(local): attribute local automation conversations per installation - #758

Merged
neubig merged 1 commit into
mainfrom
fix/local-attribution-per-installation
Nov 14, 2026
Merged

neubig merged 1 commit into
mainfrom
fix/local-attribution-per-installation

Conversation

@neubig

@neubig neubig commented Nov 14, 2026

Copy link
Copy Markdown
Member

Why

Fixes #675.

Every local installation owns its rows as the same deterministic placeholder user, uuid5(NAMESPACE_DNS, "openhands-local-user") (auth._get_local_user). The dispatcher forwarded that ID as AUTOMATION_USER_ID on every run. The prompt, plugin and plugin-spec runners pass it as the conversation user_id, and the agent-server uses a conversation user_id verbatim as its analytics distinct_id. So every local installation reported its automation conversations as one analytics person.

Summary

  • dispatcher._execute_run: in local mode, AUTOMATION_USER_ID is now this installation's persisted analytics identity, the automation-backend:<uuid4> stored in automation_service_metadata (telemetry.get_automation_backend_distinct_id). The service already uses that identity for its own local-mode events, so a run's conversation and the service's events land on the same per-installation person. If the identity cannot be read, the variable is omitted; the shared placeholder is never sent.
  • Cloud mode is unchanged and still forwards str(automation.user_id).
  • _get_local_user() and local DB ownership are unchanged, and no migration is needed. The identity row is created on first use with INSERT ... ON CONFLICT DO NOTHING and stays the same across restarts.
  • The AUTOMATION_USER_ID docs in the three preset runners now describe the local-mode value.
  • Tests (tests/test_local_attribution_identity.py) run the real _execute_run with the real local backend and two file-backed SQLite installations. They check that the two IDs differ and neither is the placeholder, that installation A keeps its ID after a restart, that the variable is omitted when the ID cannot be read, and that a cloud run keeps the owner's user ID. The first two tests fail on main. The mock backend in test_disable_automation, which stands in for the cloud backend, now sets is_local_mode=False.

How to Test

uv run pytest tests/test_local_attribution_identity.py tests/test_disable_automation.py tests/test_observability.py

End to end (.pr/issue-675/repro_675.sh): start two independent local installations, each an agent-server 1.62.0 plus the automation service in local mode with its own SQLite DB. Dispatch a custom-tarball run in each that records AUTOMATION_USER_ID, then restart installation A and dispatch again.

Before (main 949c001) After (this PR)
before after

Out of scope, per the issue triage: the agent-server defense-in-depth change in software-agent-sdk, and cleanup of the existing shared analytics person.

This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

…shared user

Every local installation owns its rows as the same deterministic placeholder
user, and that ID was forwarded as AUTOMATION_USER_ID, which the presets pass
as the conversation user_id and the agent-server uses as the analytics
distinct id. In local mode, forward the installation's persisted analytics
identity instead, and omit the variable when it cannot be resolved. Cloud
runs still forward the owner's user ID.

Fixes #675

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR adds or changes temporary PR-specific documents under .pr/. They stay on this branch for review. After this PR merges, the next release PR removes them from main.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

Warning

Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it.

@neubig
neubig requested a review from all-hands-bot November 14, 2026 00:27
@github-actions github-actions Bot added the type: fix A bug fix label Nov 14, 2026
@neubig

neubig commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

@all-hands-bot Please review the latest head 18e718a. All CI checks are green and the branch merges cleanly with main. Before/after evidence is in the PR description.

This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

@all-hands-bot all-hands-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.

This review was posted by an AI agent (OpenHands).

Reviewed at head 18e718a7d93bfffe3e09808403c524881403d581 against the repository guidance (AGENTS.md, .agents/skills/custom-codereview-guide.md) and linked issue #675. No material findings — this is ready to merge.

Scope and ownership. Dispatch env-var forwarding and the automation service's telemetry identity belong to this repository; the change stays inside that boundary (local-mode attribution only, _get_local_user() DB ownership untouched, agent-server defense-in-depth correctly left to software-agent-sdk per the issue's triage). Issue #675 is labeled bug / ready-for-dev / priority:medium, and every acceptance criterion is met: the shared uuid5 placeholder can no longer be forwarded in local mode (overridden with the persisted automation-backend:<uuid4> identity, or omitted entirely when that cannot be read — never a fallback to the constant), cloud mode still forwards str(automation.user_id), distinct-per-installation and restart-stable identities are covered by a regression test, no migration is required, and all three preset runners' AUTOMATION_USER_ID docs now describe the local-mode value.

Correctness. The new dispatcher branch is defensive in the right direction: get_automation_backend_distinct_id (a pre-existing, unchanged helper already used for local-mode service events) fails safe to None, and None simply drops the env var — the preset runners then create the conversation without user_id rather than attributing it to a person-forming shared ID. The conversation-analytics identity now matches the distinct_id the service itself uses for local events, so run conversations and service events land on the same per-installation person, which is the intended outcome of #675. test_disable_automation's mock backend correctly becomes the cloud stand-in (is_local_mode=False); all other tests that patch get_backend already pin the mode explicitly, and the required unit-tests / backend / windows-tests checks are green on this head.

Tests and evidence. The new tests/test_local_attribution_identity.py drives the real _execute_run with the real local backend over two file-backed SQLite installations (distinct IDs, neither equals the placeholder, stable across restart, omitted when unavailable, cloud keeps the owner's user ID). I ran the focused suites locally: test_local_attribution_identity.py (3 passed), test_disable_automation.py + test_observability.py (23 passed, 8 skipped). The .pr/issue-675/ artifacts follow the repository's PR-specific-documents policy, and the PR description carries adequate design context (intent, before/after, compatibility, SHA-pinned evidence).

✅ APPROVED

@neubig
neubig merged commit 973d443 into main Nov 14, 2026
10 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.33.0 Shipped in 1.33.0 label Nov 17, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.33.0.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Local automations worldwide share one deterministic user ID, collapsing all local installs into a single PostHog person

3 participants