Fix Google Chat workspace events subscription lifecycle - #186
Open
tbuckley wants to merge 4 commits into
Open
Conversation
Three bugs were keeping the adapter from receiving non-mention messages in spaces after restart: - Subscription create was storing the LRO name instead of the underlying subscription name, so every later PATCH (renew) and DELETE targeted an operation, not a subscription, and silently failed. - No authority was specified on create, so subs defaulted to app authority, leaving them invisible/unmanageable from the user OAuth the adapter uses everywhere else. - Renewal only ran on the hourly cron tick and only PATCHed; if that PATCH failed for any reason the sub was never recovered. Now: create sets `authority: 'users/me'`, polls the LRO, and stores the real subscription resource; renewal recreates the sub on any 4xx (covers 400 "exceeds max lifetime", 403, 404) and on past-expiration entries; and the adapter runs an immediate sweep on startup so it self-heals instead of waiting an hour. Also adds scripts/check-gchat-subscription.mjs for inspecting state vs. the live Workspace Events API.
When the adapter tries to recreate a subscription for a space that still has a stale app-authority sub on Google's side, the create returns 409 ALREADY_EXISTS pointing at the conflicting sub. The user OAuth can't delete app-authority subs, so use the bot's service-account ADC for the cleanup, then retry the create. This unblocks recovery for spaces whose legacy subs hit 400 "exceeds maximum lifetime" on PATCH and previously failed to recreate.
Empirically, Google caps chat-space user-authority subscription lifetimes to ~4 hours regardless of the TTL we ask for, so every PATCH renewal returns 400 "exceeds maximum allowed" and we fall through to recreate anyway. Drop the dead-weight PATCH path and just recreate when within the renewal window — simpler code, no noisy 400 logs every cron tick.
# Conflicts: # eslint.config.js
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.
Three bugs were keeping the adapter from receiving non-mention messages in spaces after restart:
Now: create sets
authority: 'users/me', polls the LRO, and stores the real subscription resource; renewal recreates the sub on any 4xx (covers 400 "exceeds max lifetime", 403, 404) and on past-expiration entries; and the adapter runs an immediate sweep on startup so it self-heals instead of waiting an hour.Also adds scripts/check-gchat-subscription.mjs for inspecting state vs. the live Workspace Events API.