Skip to content

fix(observability): skip Laminar.initialize when already initialized - #4036

Merged
tofarr merged 1 commit into
mainfrom
fix/laminar-skip-reinit
Jul 8, 2026
Merged

tofarr merged 1 commit into
mainfrom
fix/laminar-skip-reinit

Conversation

@tofarr

@tofarr tofarr commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

HUMAN:

Laminar logs this as an error Laminar is already initialized. Skipping initialization over and over. I want it quiet.


AGENT:

Why

The lmnr SDK's Laminar.initialize() emits "Laminar is already initialized. Skipping initialization." at INFO level whenever it is called after the first successful initialization. Our maybe_init_laminar() in openhands.sdk.observability.laminar calls Laminar.initialize(...) unconditionally, and the function runs at module-import time in both agent.py and acp_agent.py. Any process that imports both modules (or imports agent.py after Laminar was initialized externally) sees the duplicate INFO line on every subsequent module load — which is what shows up as spam in our logs.

Summary

  • Guard maybe_init_laminar() with Laminar.is_initialized() (the same check lmnr uses internally) so the second-and-later invocations become silent no-ops.
  • Add test_maybe_init_laminar_skips_when_already_initialized covering the new behavior.

Issue Number

None.

How to Test

uv run pytest tests/sdk/observability/test_laminar.py -v

All 36 tests pass (35 existing + 1 new). The full SDK suite (uv run pytest tests/sdk/) — 5143 tests — also passes with no regressions.

To reproduce the original log spam locally:

  1. export LMNR_PROJECT_API_KEY=test (or any other key listed in _OBSERVABILITY_ENV_KEYS).
  2. In a single Python session: import openhands.sdk.agent.agent, then import openhands.sdk.agent.acp_agent. Before the fix the second import logs Laminar is already initialized. Skipping initialization. at INFO; after the fix it stays quiet.

Video/Screenshots

N/A — observable via stdout/log capture only; no UI changes.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Pure observability tweak. No public API change. The early-exit happens after we already import lmnr, so we pay the import cost once (same as today) and skip the re-init log thereafter. Since Laminar.initialize() is itself a no-op past the first call, the functional behavior of fresh installs is unchanged.


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:4bcd21f-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-4bcd21f-python \
  ghcr.io/openhands/agent-server:4bcd21f-python

All tags pushed for this build

ghcr.io/openhands/agent-server:4bcd21f-golang-amd64
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-golang-amd64
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-golang-amd64
ghcr.io/openhands/agent-server:4bcd21f-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:4bcd21f-golang-arm64
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-golang-arm64
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-golang-arm64
ghcr.io/openhands/agent-server:4bcd21f-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:4bcd21f-java-amd64
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-java-amd64
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-java-amd64
ghcr.io/openhands/agent-server:4bcd21f-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:4bcd21f-java-arm64
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-java-arm64
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-java-arm64
ghcr.io/openhands/agent-server:4bcd21f-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:4bcd21f-python-amd64
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-python-amd64
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-python-amd64
ghcr.io/openhands/agent-server:4bcd21f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:4bcd21f-python-arm64
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-python-arm64
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-python-arm64
ghcr.io/openhands/agent-server:4bcd21f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:4bcd21f-golang
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-golang
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-golang
ghcr.io/openhands/agent-server:4bcd21f-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:4bcd21f-java
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-java
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-java
ghcr.io/openhands/agent-server:4bcd21f-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:4bcd21f-python
ghcr.io/openhands/agent-server:4bcd21f90dbfbc4ce8f742b81404485f313c7437-python
ghcr.io/openhands/agent-server:fix-laminar-skip-reinit-python
ghcr.io/openhands/agent-server:4bcd21f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 4bcd21f-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 4bcd21f-python-amd64) are also available if needed

Calling Laminar.initialize() again after the first init logs
'Laminar is already initialized. Skipping initialization.' at INFO level
from the lmnr SDK. Since maybe_init_laminar() runs at module-import time
in both agent.py and acp_agent.py, every additional module load in the
same process emits this line.

Guard the call with Laminar.is_initialized() — the same check lmnr
itself uses internally — so the second-and-later invocations become
silent no-ops.

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

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/observability
   laminar.py1755469%39–43, 108, 175–176, 189–190, 216–217, 297–304, 319–322, 330–332, 338, 348–351, 353, 358–362, 374–375, 378–380, 384, 386–388, 403, 407, 440–442, 444–445
TOTAL35039983571% 

@tofarr
tofarr marked this pull request as ready for review July 8, 2026 18:55

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

Thank you! 🙏

@tofarr
tofarr merged commit e3bb8e4 into main Jul 8, 2026
38 checks passed
@tofarr
tofarr deleted the fix/laminar-skip-reinit branch July 8, 2026 18:59

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ QA Report: PASS

The PR achieves its goal: repeated Laminar initialization paths are now silent while Laminar still initializes successfully.

Does this PR achieve its stated goal?

Yes. I reproduced the old behavior on the parent commit with real SDK imports and LMNR_PROJECT_API_KEY=test-key: the Laminar is already initialized. Skipping initialization. message appeared in the logs. On the PR commit, the same import scenarios completed with Laminar.is_initialized() still True and no matching duplicate initialization log lines.

Phase Result
Environment Setup ✅ make build completed and installed the uv environment successfully.
CI Status ⏳ Observed 33 successful, 3 skipped, 3 pending, 0 failing checks; I did not rerun tests.
Functional Verification ✅ Real SDK import scripts reproduced the log spam before and confirmed it is gone after the PR.
Functional Verification

Test 1: Import the SDK agent modules with Laminar enabled

Step 1 — Reproduce / establish baseline without the fix:
Checked out the parent commit (4bcd21f^) and ran:

LMNR_PROJECT_API_KEY=test-key uv run python /tmp/qa_laminar_import.py

Relevant output:

STATE_BEFORE=False
IMPORT_STEP: importing openhands.sdk.agent.agent
2026-07-08 18:59:17,607::lmnr.sdk.laminar::INFO: Laminar is already initialized. Skipping initialization. (laminar.py:249)
INFO:lmnr.sdk.laminar:Laminar is already initialized. Skipping initialization.
STATE_AFTER_AGENT=True
IMPORT_STEP: importing openhands.sdk.agent.acp_agent
STATE_AFTER_ACP=True
IMPORT_STEP: done

This confirms the reported noisy behavior exists in the old code: importing the SDK agent path with Laminar enabled produces the duplicate "already initialized" message while Laminar ends initialized.

Step 2 — Apply the PR's changes:
Checked out fix/laminar-skip-reinit at 4bcd21f90dbfbc4ce8f742b81404485f313c7437.

Step 3 — Re-run with the fix in place:
Ran the same script and env var:

LMNR_PROJECT_API_KEY=test-key uv run python /tmp/qa_laminar_import.py

Relevant output:

STATE_BEFORE=False
IMPORT_STEP: importing openhands.sdk.agent.agent
STATE_AFTER_AGENT=True
IMPORT_STEP: importing openhands.sdk.agent.acp_agent
STATE_AFTER_ACP=True
IMPORT_STEP: done

This shows the fix works for the module-import path: Laminar still initializes (STATE_AFTER_* = True), but the duplicate initialization message is gone.

Test 2: Import SDK agent after Laminar was initialized externally

Step 1 — Reproduce / establish baseline without the fix:
Checked out the parent commit (4bcd21f^) and ran:

LMNR_PROJECT_API_KEY=test-key uv run python /tmp/qa_laminar_external.py

Relevant output:

STATE_BEFORE=False
STATE_AFTER_EXTERNAL_INIT=True
IMPORT_STEP: importing openhands.sdk.agent.agent
2026-07-08 18:59:46,609::lmnr.sdk.laminar::INFO: Laminar is already initialized. Skipping initialization. (laminar.py:249)
INFO:lmnr.sdk.laminar:Laminar is already initialized. Skipping initialization.
2026-07-08 18:59:46,631::lmnr.sdk.laminar::INFO: Laminar is already initialized. Skipping initialization. (laminar.py:249)
INFO:lmnr.sdk.laminar:Laminar is already initialized. Skipping initialization.
STATE_AFTER_AGENT_IMPORT=True
IMPORT_STEP: done

This confirms the externally-initialized scenario described in the PR: importing the SDK after Laminar is already initialized triggers noisy duplicate initialization logs.

Step 2 — Apply the PR's changes:
Checked out fix/laminar-skip-reinit at 4bcd21f90dbfbc4ce8f742b81404485f313c7437.

Step 3 — Re-run with the fix in place:
Ran the same script and env var:

LMNR_PROJECT_API_KEY=test-key uv run python /tmp/qa_laminar_external.py

Relevant output:

STATE_BEFORE=False
STATE_AFTER_EXTERNAL_INIT=True
IMPORT_STEP: importing openhands.sdk.agent.agent
STATE_AFTER_AGENT_IMPORT=True
IMPORT_STEP: done

This confirms the PR suppresses the duplicate re-initialization log in the external-init path without clearing or preventing Laminar initialization.

Issues Found

None.

This review was created by an AI agent (OpenHands) on behalf of the user.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants