fix: tighten WeChat session rotation and defer snapshot refresh

Use session snapshot message counts alongside WeChat route counts so long-lived dedicated sessions rotate before Goose history bloats, and refresh snapshots asynchronously so customer replies are not blocked.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-04 12:21:14 +08:00
parent bef72b2768
commit 8c72d0c950
3 changed files with 127 additions and 8 deletions
+13
View File
@@ -2274,6 +2274,18 @@ export function createUserAuth(pool, options = {}) {
return Number(rows?.[0]?.count ?? 0);
};
const getWechatAgentSessionSnapshotMessageCount = async (agentSessionId) => {
if (!agentSessionId) return 0;
const [rows] = await pool.query(
`SELECT synced_msg_count
FROM h5_session_snapshots
WHERE agent_session_id = ?
LIMIT 1`,
[agentSessionId],
);
return Number(rows?.[0]?.synced_msg_count ?? 0);
};
const recordWechatMpMessage = async ({
appId,
openid,
@@ -2861,6 +2873,7 @@ export function createUserAuth(pool, options = {}) {
clearWechatAgentRoute,
touchWechatAgentRoute,
countWechatAgentSessionMessages,
getWechatAgentSessionSnapshotMessageCount,
recordWechatMpMessage,
finishWechatMpMessage,
insertWechatMpMessageDetail,