Skip to content

feat(hooks): emit gateway shutdown lifecycle events#12582

Open
vincentkoc wants to merge 8 commits intoopenclaw:mainfrom
vincentkoc:vincentkoc-code/hooks-gateway-lifecycle
Open

feat(hooks): emit gateway shutdown lifecycle events#12582
vincentkoc wants to merge 8 commits intoopenclaw:mainfrom
vincentkoc:vincentkoc-code/hooks-gateway-lifecycle

Conversation

@vincentkoc
Copy link
Member

@vincentkoc vincentkoc commented Feb 9, 2026

Why

Gateway shutdown/restart is an operationally sensitive boundary where lifecycle observability is important for uptime tooling. This PR emits explicit shutdown lifecycle events so monitoring and guardrail hooks can react consistently.

Detailed Changes

  • Added internal gateway lifecycle events in close flow:
    • gateway:shutdown
    • gateway:pre-restart (when restart is expected)
  • Hook execution is best-effort and does not block shutdown path
  • Added focused tests covering gateway lifecycle event emission

Related Links and Issues

Greptile Overview

Greptile Summary

This PR adds two new internal hook emissions to the gateway shutdown flow (gateway:shutdown and conditional gateway:pre-restart) and updates the hooks documentation accordingly. It also introduces a focused unit test that mocks internal hook dispatch and asserts the emitted event contexts during a restart-oriented shutdown.

The changes plug into the existing internal hook registry (src/hooks/internal-hooks.ts) by constructing InternalHookEvents and calling triggerInternalHook(...) early in createGatewayCloseHandler, before the rest of the shutdown teardown proceeds.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • The change is narrowly scoped to emitting new internal hook events and updating docs/tests. The previously-raised issues (sessionKey misuse, shutdown hook await semantics, timer cleanup, docs wording) are already addressed in the current head SHA, and no new definite correctness regressions were identified in the modified code paths.
  • No files require special attention

@openclaw-barnacle openclaw-barnacle bot added the gateway Gateway runtime label Feb 9, 2026
@vincentkoc vincentkoc marked this pull request as ready for review February 9, 2026 10:41
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@vincentkoc
Copy link
Member Author

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@vincentkoc vincentkoc marked this pull request as draft February 9, 2026 16:44
@openclaw-barnacle openclaw-barnacle bot added the docs Improvements or additions to documentation label Feb 9, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@vincentkoc
Copy link
Member Author

@greptile updated the tests as requested. Please update PR score if OK to merge

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@vincentkoc
Copy link
Member Author

@greptile I fixed the hooks.md as requested with wording. Everything should be good to merge, please update the PR socre

@vincentkoc vincentkoc marked this pull request as ready for review February 9, 2026 19:45
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Feb 21, 2026
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: gateway:shutdown and gateway:pre-restart hook events

1 participant