fix(qq): auto-detect active bot account#163
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c8781b3b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| QQ_HEALTH.update( | ||
| account_qq=self_id, | ||
| account_nickname=( | ||
| QQ_HEALTH.get("account_nickname") if previous == self_id else None | ||
| ), | ||
| account_checked_at_ms=int(time.time() * 1000), |
There was a problem hiding this comment.
Reset stale offline state when observing a new login
After a QQ account has been marked offline, this callback is the first code that runs when the re-login starts producing OneBot events again, but it only writes account_qq and leaves QQ_HEALTH["account_online"] as False. The status route's new effective_self_ids gate ignores detected ids while that flag is false, so the scan-login close refresh can keep showing the offline banner and configured fallback ID until the periodic health watcher runs (default 60s) despite live events having resumed; update the account-online state, or pass the event/heartbeat status through, together with the observed id.
Useful? React with 👍 / 👎.
| if self._on_self_id is None or self_id == self._last_notified_self_id: | ||
| return |
There was a problem hiding this comment.
Republish the same QQ id after offline clears it
When the account is kicked offline, the health watcher clears QQ_HEALTH["account_qq"]; if the operator scans back into the same QQ account, subsequent events carry the same self_id, but this de-dupe returns before calling on_self_id. In that same-account re-login path the status route has no way to restore the managed Bot QQ ID, so it can stay empty or fall back to the legacy config even after account_online recovers; reset this notified marker when account state is cleared, or allow republishing after an offline/stale transition.
Useful? React with 👍 / 👎.
Summary
Derive the active QQ Bot ID from the live OneBot event stream and present it as a runtime-managed, read-only value. Account switches stop retaining stale mention targets, while persisted
self_idsremains a compatibility fallback and is never overwritten by unrelated UI saves.Type
Scope / Packages Touched
corlinman-channels: OneBot identity observation, current-event mention routing, health statecorlinman-server/gateway: QQ status runtime identity projectionui: managed read-only Bot QQ ID and scan-login refreshBehavior Proof
proof: sufficientIsolated running gateway + synthetic OneBot heartbeat, without sending a QQ message:
The same status response retained persisted fallback truth independently:
{"config_keys":{"self_ids":["10001"]},"account_qq":246813579,"self_ids":[246813579]}CI Gate
py-ruff—uv run ruff check .py-mypy— allpython/packages/*/src(621 source files)py-test— 7,286 passed, 7 skippedui-typecheck—pnpm -C ui typecheckui-lint— covered by successful Next production build (pre-existing warnings only)ui-test— full Vitest suite passedboundary-check— 2 contracts kept, 0 brokenSeparate checks:
proto-sync— N/A, no proto changesswift-mac— N/AModule Boundaries / Proto
Risk & Rollback
Risk: external OneBot clients with malformed or zero
self_idcontinue using the persisted compatibility fallback. Valid per-event IDs are authoritative and account-offline state clears stale runtime identity.Rollback plan: revert commit
2c8781b3; persisted QQ configuration is not migrated or deleted.Ownership
Single-owner repository; no cross-team reviewer required.
Codex Review
Claude self-review is the repository's current review gate; no Codex wait is required.
Linked Issues
None.
Checklist
--no-verifyor hook-skipping used.