feat(messaging): token K/M/B units and toolfmt multiline garble fix#470
Merged
Conversation
…oval deadlock (#462) - Fix ExecWorker.Input() TOCTOU race condition by moving nil check into spawn() - Pass session.AllowedTools to proc.Manager for security enforcement - Enforce StartupTimeout in spawn() and startProcessLocked() (was configured but unused) - Add JSONRPCFrame unified type to eliminate double unmarshal in dispatchFrame - Handle server-initiated JSON-RPC requests (approvals) previously silently dropped - Implement HandlePermissionResponse via RespondServerRequest to resolve approval deadlock - Add approval method aliases (item/commandExecution/requestApproval, item/fileChange/requestApproval) - Add messageTracker.Reset() and call on crash recovery to prevent memory leaks - Replace AppServerWorker.Wait() 2s magic timeout with doneCh-based lifecycle binding - Add 5s timeout protection for critical event sends to prevent goroutine leaks - Register command with security.RegisterCommand in InitConfig - Make personality configurable via config (default "friendly") - Switch dev config feishu worker_type to codex_cli
- Remove accidentally appended memory context from AGENTS.md - Extract defaultStartupTimeout and criticalEventSendTimeout constants - Fix sendEnvelope time.After leak with time.NewTimer + Stop() - Unify three write-mu+encode blocks into writeFrame() - Remove personality double-default (trust config layer)
…lues Token counts now display as K/M/B based on magnitude: - <1K: raw number (999) - >=1K: K suffix (76.3K, 200K) - >=1M: M suffix (1.5M, 15M) - >=1B: B suffix (2.5B) Applied to both Go backend and webchat TS frontend.
aaronwong1989
approved these changes
May 21, 2026
Contributor
aaronwong1989
left a comment
There was a problem hiding this comment.
Review Summary
This PR adds K/M/B unit support to FormatTokenCount (Go + TS) and switches dev config worker_type.
Must Fix
None.
Suggested
- Edge case: 999999 produces "1000.0K" which is confusing in UI - user expects "1M". Consider rounding up at unit boundaries in formatCompact.
Nice to Have
- PR body mentions toolfmt/firstLine() changes but diff does not include them - may have been squashed into prior commit, consider updating PR description.
Good
- Go/TS implementations aligned
- formatCompact extracted as helper function
- Test coverage for K/M/B boundaries
- Numeric separators for readability
999999 now correctly shows "1M" instead of "1000.0K". Use 999_950 thresholds to bump up at unit boundaries, and round in formatCompact to avoid stale ".0" suffixes (e.g. 9999 → "10K" not "10.0K"). Go and TS implementations updated in sync.
aaronwong1989
approved these changes
May 21, 2026
Contributor
aaronwong1989
left a comment
There was a problem hiding this comment.
✅ 审查通过
审查要点
FormatTokenCount K/M/B 单位(Go + TS)
- 🟢 使用 999,950 阈值实现单位自动晋升(K→M→B),边界处理正确:999999 → "1M",999949 → "999.9K"
- 🟢 / 中 四舍五入 + 整数判断,消除旧版 ".0" 后缀(9999 → "10K" 而非 "10.0K")
- 🟢 Go 和 TS 双端逻辑完全同步,实现一致
- 🟢 测试从 10 个用例扩展到 16 个,覆盖 K/M/B 所有单位边界
config-dev.yaml
- 🟢 worker_type 切换为 claude_code,仅影响开发环境,无风险
注意事项
- PR 描述中提到的
toolfmt multiline garble fix(firstLine helper)未出现在本次 diff 中,可能已在之前的提交中包含或已移除,建议确认是否需要单独处理。
整体变更质量高,逻辑清晰,测试充分。👍
aaronwong1989
approved these changes
May 21, 2026
Contributor
aaronwong1989
left a comment
There was a problem hiding this comment.
✅ 审查通过
审查要点
FormatTokenCount K/M/B 单位(Go + TS)
- 🟢 使用 999,950 阈值实现单位自动晋升(K→M→B),边界处理正确:999999 → "1M",999949 → "999.9K"
- 🟢 formatCompact / fmtCompact 中 math.Round(v*10)/10 四舍五入 + 整数判断,消除旧版 ".0" 后缀(9999 → "10K" 而非 "10.0K")
- 🟢 Go 和 TS 双端逻辑完全同步,实现一致
- 🟢 测试从 10 个用例扩展到 16 个,覆盖 K/M/B 所有单位边界
config-dev.yaml
- 🟢 worker_type 切换为 claude_code,仅影响开发环境,无风险
注意事项
- PR 描述中提到的 toolfmt multiline garble fix(firstLine helper)未出现在本次 diff 中,可能已在之前的提交中包含或已移除,建议确认是否需要单独处理。
整体变更质量高,逻辑清晰,测试充分。👍
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
FormatTokenCount新增 M/B 单位支持,大 token 数值自动缩写(Go + TS 双端)toolfmt提取firstLine()helper,全量防护多行内容在 Feishu tool_activity 区域的乱码问题Test plan
TestFormatTokenCount16 用例全部通过(含 M/B 边界值)TestFormatCall多行 Bash/Grep/Agent/WebSearch 用例通过make check(quality + build) 通过