ISI-515: Fix hook registration timing — register hooks in register() not start()#6
Merged
henrikrexed merged 2 commits intomainfrom Apr 16, 2026
Merged
Conversation
OpenClaw snapshots typed hooks at plugin registration time. The plugin was calling registerHooks() inside the registerService start() callback, which runs ~30s after the gateway is ready, so all 15 hooks (typed via api.on plus event-stream via api.registerHook) were attached too late and never fired. Move the registerHooks() call into register() so the listeners are in place before the gateway starts processing events. Telemetry init still happens in start(), so registerHooks() now takes a lazy getTelemetry: () => TelemetryRuntime | null. Each hook reads the live runtime when it fires and no-ops if telemetry is not yet initialised (handles the brief window between register() and start()). Co-Authored-By: Paperclip <noreply@paperclip.ing>
registerHooks now returns a disposer that clears the 60s setInterval stale-session sweeper. index.ts captures it and invokes it from service.stop() so the timer is released on plugin shutdown/reload instead of leaking across lifecycles. Co-Authored-By: Paperclip <noreply@paperclip.ing>
henrikrexed
pushed a commit
that referenced
this pull request
Apr 16, 2026
Phase 1 doc refresh following PR #6 (ISI-515) and commit b668a4f (ISI-522). - README: add Plugin Lifecycle section (register/start/stop phases, lazy telemetry getter, setInterval cleanup on stop). Add "Validate your first trace" walk-through of the [otel] log markers in registration order. Add Troubleshooting section covering the "hooks register but never fire" symptom with confirmation steps. - docs/architecture.md: new Plugin Lifecycle section with phase table and lazy-getter code sample, explaining why typed hooks must register in register() and how hooks resolve telemetry after start(). - docs/getting-started.md: expand "Verify Connected Traces" with the six registration log lines and the per-message debug markers. Add a dedicated "Hooks register but never fire" troubleshooting entry linking to the architecture lifecycle section. Phase 2 (per-span/attribute/metric semconv reference table) tracked on ISI-520 and will ship in a follow-up PR. mkdocs build --strict passes. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This was referenced Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All 15 plugin hooks were registered but never fired. Root cause:
registerHooks()was called from insideregisterService.start()(async, runs ~30s after the gateway is ready), while OpenClaw snapshots typed hooks at plugin registration time.Fix
registerHooks(api, getTelemetry, config)into the synchronousregister()phase inindex.tsso the gateway sees the listeners before it boots.registerHooksinsrc/hooks.tsto take a lazygetTelemetry: () => TelemetryRuntime | nullinstead of the runtime directly, since telemetry is still initialised instart().register()andstart()).Files
index.ts— register hooks inregister(), drop the call fromstart()src/hooks.ts— acceptgetTelemetrylazy getter, look uptracer/counters/histogramsper call, buildsecurityCountersper callVerification
tsc --noEmitpasses locally.Acceptance (per ISI-515)
[otel] Root span started for session=...,[otel] Agent turn span started,[otel] Trace completed for session=...in logs.openclaw.request→openclaw.agent.turn→tool.*.Paperclip ticket: ISI-515