feat(edge): Edge broker-client + 薄 adapter 契约 + session 记账 (PR4)#191
Open
raysonmeng wants to merge 1 commit into
Open
feat(edge): Edge broker-client + 薄 adapter 契约 + session 记账 (PR4)#191raysonmeng wants to merge 1 commit into
raysonmeng wants to merge 1 commit into
Conversation
按 spec §5/§8.2 落地 Edge 层连接 broker 的客户端 + 适配器契约 + session 记账,消费 PR3 broker。 - src/broker-client.ts:BrokerClient —— Edge 连 broker 的 WS 客户端。connect(PSK 鉴权)/ subscribe/publish/onEvent/close。**A 类韧性地基(§8.2)**:断线指数退避自动重连、重连后重订 全部 topic、离线本地排队(有界 drop-oldest)flush,业务 session 不 flap。**单飞 socket**(connect 幂等、openSocket 建新前拆旧);transient pre-welcome 关闭不 reject(后台重连解析同一 promise); 坏 token 不无限重连;inbound 非对象帧守卫。 - src/session-ledger.ts:SessionLedger(Edge-local,§2.5) —— (workspace,agentType)→lastSessionId 记账 + new/resumed 判定 + previousSessionId(供 adapter 调 agent 原生 --resume)。 - src/agent-adapter.ts:AgentAdapter 接口(§5.2/附录D:register/onCompletion/receiveIntoSession) —— 薄适配器契约声明,真实 Claude/Codex adapter 实现留后续 PR。 测试:broker-client(unit FakeWs 驱动重连/幂等/离线排队有界/坏token/malformed帧 + 集成真 broker connect/auth/跨client扇出/坏token拒绝)、session-ledger。full check exit 0:1743 pass / 0 fail。 Cross-review:轮 1 thorough 抓出并修复 HIGH——connect 无重入守卫致多 socket 并存/泄漏/事件重复 (重写为幂等单飞 socket + 移除 reject-then-secretly-reconnect 矛盾契约 + outbox 上限);轮 2/轮 3 lean 0 source defect 收敛(顺手加固 client malformed-frame guard + onclose 同一性守卫;轮3 抓出我 忘 build:plugin 致 bundle codeHash drift —— 已重建对齐 + check 复验 exit 0)。 Backlog:connect 无超时(韧性=持续重试,接线 PR fire-and-forget 或加超时);session-ledger 读改写 非原子(Edge-local 单 agent 无并发);AgentAdapter 真实现/cwd→room 自动 join 后续 PR。 --- feat(edge): Edge broker-client + thin adapter contract + session accounting (PR4) Land the Edge layer that connects a local agent to the broker (§5/§8.2), consuming PR3. BrokerClient: PSK-authenticated WS client with A-class resilience (exponential-backoff reconnect, re-subscribe, bounded offline outbox flush, single in-flight socket, idempotent connect). SessionLedger: §2.5 (workspace,agentType)→lastSessionId accounting + new/resumed. AgentAdapter: §5.2 thin contract (register/onCompletion/receiveIntoSession). Converged after 1 thorough + 2 lean adversarial rounds (fixed a HIGH connect-reentrancy socket leak). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要 / Summary
PR4:落地 Edge 层——把本地 agent 连到 broker 的客户端 + 薄适配器契约 + session 记账(§5/§8.2),消费 PR3 broker。
改动 / Changes
src/broker-client.tsBrokerClient:PSK 鉴权的 WS 客户端。A 类韧性地基(§8.2):指数退避重连 + 重连重订 + 离线本地排队(有界)flush + 单飞 socket(connect 幂等、建新前拆旧) + 坏 token 不重连 + inbound 帧守卫src/session-ledger.tsSessionLedger(Edge-local,§2.5):(workspace,agentType)→lastSessionId + new/resumed 判定 + previousSessionId(供 adapter 调 agent 原生--resume)src/agent-adapter.tsAgentAdapter接口(§5.2/附录D:register/onCompletion/receiveIntoSession)——薄契约声明,真实 Claude/Codex adapter 后续 PR测试计划 / Test plan
bun run checkexit 0 → 1743 pass / 0 fail、typecheck 干净、bundle 同步、codeHash 对齐Cross-review
connect()无重入守卫致多 socket 并存/泄漏/事件重复(verifier 实跑:3 socket/2 OPEN/事件投递 2 次/close 后泄漏 1)。根因:建新 socket 前不取消 reconnectTimer/不关旧 ws,且 pre-welcome 关闭时既 reject 又后台重连(矛盾契约诱导 retry)。→ 重写为幂等 connect + 单飞 socket(openSocket 先拆旧)+ transient 关闭不 reject + outbox 上限。build:plugin致 bundle codeHash drift → 已重建对齐 + check 复验 exit 0。Backlog
connect()无超时(韧性=持续重试;接线 PR fire-and-forget 或加超时);SessionLedger 读改写非原子(Edge-local 单 agent 无并发);AgentAdapter 真实现 + cwd→room 自动 join = 后续 PR(PR5)。🤖 Generated with Claude Code