Skip to content

chore(discord): clear the stored bot-token copies once the env resolver is live (TASK-124) - #1891

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task124-clear-stored-bot-token
Sep 25, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task124-clear-stored-bot-token

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

What this is

The data half of TASK-124, cut from main (cce68b58) and deliberately separate from #1889, which stopped the read and the write. This removes the stored copies.

Three live discord_integrations rows carry a 72-char botToken that Discord has already revoked — 401 against GET /users/@me, measured read-only from inside the backend pod. #1889 routed every read through resolveDiscordBotToken() (env first, the stored copy only as a fallback) and stopped writing it, so the copies are unreachable. This deletes them rather than leaving a revoked credential at rest for a future code path to find.

Why it is a separate step, and why it runs last

The pre-#1889 build still read the stored copy on two paths with no env fallback (discordService.ts fetchMessages and getChannels). Clearing before that image was replaced would have broken those paths on the old build. Order: merge → deploy → acceptance read → this script. The script's header states the order so a future operator cannot run it early by accident.

Scope: one collection

  • Clears discord_integrations.botToken only, and only where it holds a non-empty string. Absent, null and '' are not copies of a credential, and '' is exactly what the dead discordController path used to write.
  • $unset, not $set: '' — leaving the field behind is the failure this field already demonstrated once.
  • Integration.config.botToken is a different store in a different collection, never written by any writer (measured live: absent on all three rows), and still the resolver's fallback read. It is counted and logged, never touched. A non-zero count is worth seeing: it would mean some row's authority is a config field rather than the env.
  • Default is a dry run; --apply writes. Idempotent: a second run finds nothing.
  • Logs each distinct copy as sha256[:12] (n chars) — enough to tell the copies apart in a log or a ticket, never the token.

Witnesses (6)

witness what it pins
counts only non-empty copies as candidates 6 rows, 3 copies: null / '' / absent are out of scope
writes nothing without --apply a dry run that writes would be the whole defect
removes the field rather than blanking it per-row $exists on the rows that had a copy — a $set: '' update passes every "no copy left" query while leaving a field behind
is idempotent second --apply reports 0 candidates / 0 cleared
reports the other store and never writes it Integration.config.botToken survives the clear
identifies each copy without reproducing it digest shape, distinct per copy, and the tokens are absent from the log

Mutation ledger — 5 arms, all red, each naming its own witness

arm mutation result
M1 the dry-run early return removed (always writes) 1 red — writes nothing without --apply
M2 $unset → $set: { botToken: '' } 1 red — removes the field rather than blanking it
M3 filter weakened to { $exists: true } 6 red — every path, because the filter drives them all
M4 the Integration.config count forced to 0 1 red — reports the other store
M5 the digest replaced by the token itself 1 red — identifies each copy without reproducing it

Base and restored: 6 passed / 6. No survivors to disclose.

Full tier

  • jest __tests__/unit/scripts/ — 20 suites / 165 tests / 0 failures.
  • eslint on both touched files under the gated .ts override — 0 problems.
  • Backend-only ⇒ no package version slot.
  • The script keeps its require.main === module guard, so unguardedScriptImporters stays green.

Not in this PR

No change to resolveDiscordBotToken, no change to any read path, no webhookUrl encryption (a later piece), and no change to Integration.config.

…er is live (TASK-124)

The data half of TASK-124, deliberately separate from #1889 (`cce68b58`), which
stopped reading and writing the copy. This removes it: three live rows carry a
72-char token Discord revoked (401 against GET /users/@me, measured read-only
from inside the backend pod).

Ordering is the reason it is separate: the pre-#1889 build still read the stored
copy on two paths with no env fallback, so clearing it before that image was
replaced would have broken those paths. Merge -> deploy -> acceptance read ->
this script.

Dry run by default; `--apply` writes. Idempotent. Scope is one collection:
`discord_integrations.botToken`. `Integration.config.botToken` is a different
store, never written, and still the resolver's fallback read, so it is reported
and never touched.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit c696e03 Sep 25, 2026
14 checks passed
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