Skip to content

Fix Google Chat workspace events subscription lifecycle - #186

Open
tbuckley wants to merge 4 commits into
mainfrom
fix-gchat-subscription
Open

Fix Google Chat workspace events subscription lifecycle#186
tbuckley wants to merge 4 commits into
mainfrom
fix-gchat-subscription

Conversation

@tbuckley

Copy link
Copy Markdown
Owner

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant