Skip to content

🐛 修复 PayloadType 缺失 Heartbeat 类型#81

Merged
shoucandanghehe merged 1 commit into
masterfrom
fix-payloadtype-heartbeat
Mar 1, 2026
Merged

🐛 修复 PayloadType 缺失 Heartbeat 类型#81
shoucandanghehe merged 1 commit into
masterfrom
fix-payloadtype-heartbeat

Conversation

@shoucandanghehe
Copy link
Copy Markdown
Member

问题

PayloadType 未包含 Heartbeat 类型,导致 receive_payload() 收到服务器发送的心跳请求时(op=1),无法正确反序列化为 Heartbeat 实例。

结果是 _loop() 中的 Heartbeat 分支永远不可达:

elif isinstance(payload, Heartbeat):
    # 当接受到心跳payload时...
    await self._heartbeat(ws, bot)

修复

Heartbeat 添加到 PayloadType 的 Union 类型中。

 PayloadType: TypeAlias = (
     Annotated[
-        Dispatch | Reconnect | InvalidSession | Hello | HeartbeatAck,
+        Dispatch | Heartbeat | Reconnect | InvalidSession | Hello | HeartbeatAck,
         Field(discriminator="opcode"),
     ]
     | Payload
 )

验证

  • 运行 ruff check 通过
  • 运行 ruff format --check 通过

将 Heartbeat 类型添加到 PayloadType Union 中,使 _loop() 方法中的 Heartbeat 分支可以正确处理服务器发送的心跳请求。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.78%. Comparing base (9c5dabe) to head (3800739).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #81   +/-   ##
=======================================
  Coverage   74.78%   74.78%           
=======================================
  Files          38       38           
  Lines        7067     7067           
  Branches      372      372           
=======================================
  Hits         5285     5285           
  Misses       1715     1715           
  Partials       67       67           
Flag Coverage Δ
unittests 74.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shoucandanghehe shoucandanghehe merged commit f69ca97 into master Mar 1, 2026
19 checks passed
@shoucandanghehe shoucandanghehe deleted the fix-payloadtype-heartbeat branch March 1, 2026 15:38
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