Skip to content

Fix stale token winning deduplication race in LevelDB extraction#38

Merged
devxoul merged 1 commit intomainfrom
fix/slack-token-dedup-priority
Mar 5, 2026
Merged

Fix stale token winning deduplication race in LevelDB extraction#38
devxoul merged 1 commit intomainfrom
fix/slack-token-dedup-priority

Conversation

@devxoul
Copy link
Owner

@devxoul devxoul commented Mar 5, 2026

Summary

  • The dedup logic let stale tokens from old .ldb files overwrite fresh tokens when the stale entry had a team name but the fresh one didn't. Combined with unsorted .ldb file ordering, this caused intermittent auth failures after LevelDB compaction.

Changes

src/platforms/slack/token-extractor.ts

  • Change deduplicateTokens() from last-wins to first-wins for token values. A later entry can only upgrade teamName from unknown — the token value from the first (freshest) source is always preserved.
  • Sort .ldb files by modification time (newest first) so fresh tokens are encountered before stale ones during scanning.
  • Add statSync import for file mtime comparison.

src/platforms/slack/token-extractor.test.ts

  • Test that first token wins dedup and team name is upgraded from a later entry.
  • Test that .log tokens take priority over .ldb tokens for the same team.

Verified

  • bun test — 14 pass, 0 fail.
  • bun typecheck — clean.
  • bun lint — clean.

Summary by cubic

Fixes a dedup race where stale Slack tokens from old .ldb files could overwrite fresh tokens, causing intermittent auth failures after LevelDB compaction. Fresh tokens now consistently win, with file ordering favoring newest data.

  • Bug Fixes
    • Changed token dedup to first-wins for token values; later entries can only upgrade an unknown team name.
    • Sorted .ldb files by modification time (newest first) and continued to prioritize .log files to scan fresher tokens first.

Written for commit 47eae3e. Summary will update on new commits.

Changed dedup to first-wins for token values (freshest source) while
still allowing team name upgrades from later entries. Sort .ldb files
newest-first so fresh tokens are encountered before stale ones.
@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agent-messenger Ignored Ignored Mar 5, 2026 0:33am

Request Review

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@devxoul devxoul merged commit e8fc5c3 into main Mar 5, 2026
5 checks passed
@devxoul devxoul deleted the fix/slack-token-dedup-priority branch March 5, 2026 12:36
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