Repository navigation
fix(observability): skip Laminar.initialize when already initialized - #4036
Conversation
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>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ 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.pyRelevant 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.pyRelevant 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.pyRelevant 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.pyRelevant 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.
HUMAN:
Laminar logs this as an error
Laminar is already initialized. Skipping initializationover 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. Ourmaybe_init_laminar()inopenhands.sdk.observability.laminarcallsLaminar.initialize(...)unconditionally, and the function runs at module-import time in bothagent.pyandacp_agent.py. Any process that imports both modules (or importsagent.pyafterLaminarwas initialized externally) sees the duplicate INFO line on every subsequent module load — which is what shows up as spam in our logs.Summary
maybe_init_laminar()withLaminar.is_initialized()(the same check lmnr uses internally) so the second-and-later invocations become silent no-ops.test_maybe_init_laminar_skips_when_already_initializedcovering the new behavior.Issue Number
None.
How to Test
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:
export LMNR_PROJECT_API_KEY=test(or any other key listed in_OBSERVABILITY_ENV_KEYS).import openhands.sdk.agent.agent, thenimport openhands.sdk.agent.acp_agent. Before the fix the second import logsLaminar 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
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. SinceLaminar.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
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:4bcd21f-pythonRun
All tags pushed for this build
About Multi-Architecture Support
4bcd21f-python) is a multi-arch manifest supporting both amd64 and arm644bcd21f-python-amd64) are also available if needed