Skip to content

fix(qq): auto-detect active bot account#163

Merged
sweetcornna merged 1 commit into
mainfrom
fix/qq-auto-self-id
Jul 22, 2026
Merged

fix(qq): auto-detect active bot account#163
sweetcornna merged 1 commit into
mainfrom
fix/qq-auto-self-id

Conversation

@sweetcornna

Copy link
Copy Markdown
Owner

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_ids remains a compatibility fallback and is never overwritten by unrelated UI saves.

Type

  • feat: new user-facing behavior
  • fix: bug fix or regression repair
  • refactor: internal change with no intended behavior difference
  • test: tests only
  • perf: performance optimization
  • docs: documentation only
  • chore: tooling, dependencies, or maintenance
  • ci: CI / workflow change

Scope / Packages Touched

  • corlinman-channels: OneBot identity observation, current-event mention routing, health state
  • corlinman-server/gateway: QQ status runtime identity projection
  • ui: managed read-only Bot QQ ID and scan-login refresh
  • release metadata: v1.36.1

Behavior Proof

  • I added/updated automated tests, or explained why tests are not practical.
  • I included real behavior proof when relevant: screenshot, video, logs, curl output, or before/after notes.
  • proof: sufficient

Isolated running gateway + synthetic OneBot heartbeat, without sending a QQ message:

unauth=401 auth=200
{"account_online": true, "account_qq": 246813579, "health_online": true, "health_seconds_since_event": 29, "runtime": "connected", "self_ids": [246813579]}

The same status response retained persisted fallback truth independently:

{"config_keys":{"self_ids":["10001"]},"account_qq":246813579,"self_ids":[246813579]}

CI Gate

  • py-ruffuv run ruff check .
  • py-mypy — all python/packages/*/src (621 source files)
  • py-test — 7,286 passed, 7 skipped
  • ui-typecheckpnpm -C ui typecheck
  • ui-lint — covered by successful Next production build (pre-existing warnings only)
  • ui-test — full Vitest suite passed
  • boundary-check — 2 contracts kept, 0 broken

Separate checks:

  • proto-sync — N/A, no proto changes
  • swift-mac — N/A

Module Boundaries / Proto

  • No new reverse imports across the Python layering contract.
  • No proto files touched.

Risk & Rollback

Risk: external OneBot clients with malformed or zero self_id continue 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

  • PR title follows Conventional Commits.
  • Tests added/updated; behavior proof supplied.
  • No external reviewer required for this owner area.
  • No --no-verify or hook-skipping used.

@github-actions github-actions Bot added codex:needs-review A Codex review is needed for the current PR head. codex:review-requested A Codex review was requested or should be running automatically. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. labels Jul 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +600 to +605
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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +782 to +783
if self._on_self_id is None or self_id == self._last_notified_self_id:
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@github-actions github-actions Bot added codex:reviewed Codex posted a review result or thumbs-up after the latest request. status: 👀 ready for maintainer look No automation blocker is known; a maintainer should inspect the current result. and removed codex:review-requested A Codex review was requested or should be running automatically. codex:needs-review A Codex review is needed for the current PR head. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. labels Jul 22, 2026
@sweetcornna
sweetcornna merged commit 2d51c5a into main Jul 22, 2026
11 checks passed
@sweetcornna
sweetcornna deleted the fix/qq-auto-self-id branch July 22, 2026 04:36
@github-actions github-actions Bot added the status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex:reviewed Codex posted a review result or thumbs-up after the latest request. status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. status: 👀 ready for maintainer look No automation blocker is known; a maintainer should inspect the current result.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant