fix: gmail pageToken reuse + slack bot token unhandled rejection#54
Merged
Conversation
Two daemon-startup regressions surfaced after multi-account rolled out: 1. Gmail delta ingest hit `Invalid pageToken` on every run. The pipeline stores `lastMessage.id` as the cursor and passes it back to the source on the next run; the source was treating that as Gmail's `pageToken`. They're different beasts — message IDs are short hex strings, pageTokens are opaque intra-run pagination handles. Cross-run reuse always 400s. Fix: stop using the inherited cursor as pageToken. Re-running the same `q:` is safe because the pipeline's per-message dedup step rejects already-stored messages, so a fresh full scan is idempotent (verified: 4 messages skipped via dedup on a re-run). Delta semantics come from `options.since` (computed by the ingest scheduler from the last successful job), which still works. 2. Slack User adapter logged an unhandled `account_inactive` rejection when the workspace's bot token was deactivated. The bot client's own auth.test was wrapped in try/catch, but the Bolt App was being constructed with the bad bot token before validation, and its internal auth.test fired an uncaught promise. Fix: validate the bot token via `botClient.auth.test()` BEFORE handing it to Bolt. On failure, drop the bot client and fall back to the user token for Bolt's Socket Mode connection. Same user- facing behavior (agent posts as user), just no more stack trace at startup. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
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
Two daemon-startup regressions that surfaced after #53 merged:
Gmail
Invalid pageTokenon every delta runThe pipeline stores
lastMessage.idas the cursor and passes it back to the source on the next run; the Gmail source was treating that as Gmail'spageToken. They're different beasts — message IDs are short hex strings, pageTokens are opaque intra-run pagination handles. Cross-run reuse always 400s withInvalid pageToken.Fix: stop using the inherited cursor as
pageTokenin src/ingest/sources/gmail.ts. Re-running the sameq:is safe because the pipeline's per-message dedup step rejects already-stored messages, so a fresh full scan is idempotent (verified: 4 messages skipped via dedup on a re-run). Delta semantics come fromoptions.since(computed by the ingest scheduler from the last successful job), which still works.Slack User adapter
account_inactiveunhandled rejectionWhen the workspace's bot token was deactivated, the bot client's own
auth.test()was wrapped in try/catch, but the Bolt App was being constructed with the bad bot token before validation. Bolt's internalauth.testfired an uncaught promise.Fix: validate the bot token via
botClient.auth.test()before handing it to Bolt in src/daemon/channels/slack-user.ts. On failure, drop the bot client and fall back to the user token for Bolt's Socket Mode connection. Same user-facing behavior (agent posts as user), just no more stack trace at startup.Test plan
🤖 Generated with Claude Code