feat(hooks): workspace events subscription hook#36302
feat(hooks): workspace events subscription hook#36302JoshuaLelon wants to merge 4 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR adds a Google Workspace Events subscription hook that wires real-time Calendar, Drive, and Chat changes into OpenClaw's agent hook system via the Key issues found:
Confidence Score: 3/5
Last reviewed commit: b908f48 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b908f48174
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
60cc62e to
e3e6dba
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3e6dba2c6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0fcdd5fe06
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| defaultRuntime.log(`Starting gws ${args.join(" ")}`); | ||
|
|
||
| let shuttingDown = false; | ||
| let child = spawnGwsEventsSubscribe(runtimeConfig); |
There was a problem hiding this comment.
Replace gateway watcher spawner in CLI run loop
runWsEventsService calls spawnGwsEventsSubscribe, but that helper is wired for gateway mode and always schedules a 5s restart timer on child exit unless the watcher module’s own global shuttingDown flag is set. In the CLI path, SIGINT/SIGTERM only flips a local shuttingDown, so an intentional stop of openclaw webhooks events run still leaves the gateway timer alive, delaying clean process exit (and potentially racing with the CLI restart loop). Use a CLI-specific spawner (or share shutdown state) so manual shutdown does not queue watcher restarts.
Useful? React with 👍 / 👎.
- Fix restart-loop: respawned child now gets exit handler via attachExitHandler pattern - Fix ?? vs || in buildEventSummary so empty string falls back to 'unknown' - Add stopWsEventsWatcher() call to gateway shutdown handler - Add hooks.workspaceEvents.model startup validation (mirrors gmail model check) - Factor out resolveHooksModel helper shared by gmail and ws-events
82b504e to
9adcf03
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9adcf031f1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| setTimeout(() => { | ||
| if (shuttingDown || !currentConfig) { | ||
| return; | ||
| } | ||
| watcherProcess = spawnGwsEventsSubscribe(currentConfig); |
There was a problem hiding this comment.
Clear pending restart timer before respawning watcher
The exit handler schedules an unconditional 5s restart timer, but that timer is never cancelled when stopWsEventsWatcher() runs. If gws crashes, then a config reload triggers stop/start before the 5s elapses, startWsEventsWatcher() resets shuttingDown and currentConfig, so the stale timer also spawns another child process; this creates duplicate subscriptions and leaves one process untracked by watcherProcess on later shutdowns.
Useful? React with 👍 / 👎.
Summary
gws events +subscribe, giving agents real-time awareness of Calendar changes, Drive file updates, Chat messages, etc.openclaw webhooks events setupandopenclaw webhooks events runCLI commandsChanges
New files (8):
src/hooks/ws-events.ts— runtime config types, resolver, arg buildersrc/hooks/ws-events-bridge.ts— CloudEvent NDJSON → hook payload transformsrc/hooks/ws-events-watcher.ts— process lifecycle (spawn, restart, stop)src/hooks/ws-events-watcher-lifecycle.ts— thin wrapper with env skip + loggingsrc/hooks/ws-events-ops.ts— setup + run command implementationssrc/hooks/ws-events.test.ts— 13 tests for config resolver + arg buildersrc/hooks/ws-events-bridge.test.ts— 13 tests for CloudEvent transform + NDJSON handlerdocs/automation/workspace-events.md— documentationModified files (8):
src/config/types.hooks.ts—HooksWorkspaceEventsConfigtypesrc/config/zod-schema.hooks.ts—HooksWorkspaceEventsSchemasrc/config/zod-schema.ts— wire schema into parent hooks objectsrc/gateway/hooks-mapping.ts—"workspace-events"preset + allowUnsafeExternalContentsrc/gateway/config-reload-plan.ts—restartWsEventsWatcherplan field + reload rulesrc/gateway/server-startup.ts— start watcher on bootsrc/gateway/server-reload-handlers.ts— handle watcher restart on config changesrc/cli/webhooks-cli.ts—events setup+events runsubcommandsDependencies
postToHookUrl,ensureDependency("gws", ...), and the NDJSON bridge patternTest plan
pnpm build— no type errorspnpm check— lint/format cleanopenclaw webhooks events setup --target '//chat.googleapis.com/spaces/X' --event-types 'google.workspace.chat.message.v1.created' --project P🤖 Generated with Claude Code