Skip to content

fix: resolve multiple bugs from code review #116#173

Merged
mengzhuo merged 1 commit intosipeed:mainfrom
is-Xiaoen:fix/code-review-bugs-116
Feb 15, 2026
Merged

fix: resolve multiple bugs from code review #116#173
mengzhuo merged 1 commit intosipeed:mainfrom
is-Xiaoen:fix/code-review-bugs-116

Conversation

@is-Xiaoen
Copy link
Contributor

Fixes four issues identified in the community code review:

  • Session persistence broken on Windows: session keys like "telegram:123456" contain ':', which is illegal in Windows filenames. filepath.Base() strips drive-letter prefixes on Windows, causing Save() to silently fail. Added sanitizeFilename() to replace invalid chars in the filename while keeping the original key in the JSON payload.

  • HTTP client with no timeout: HTTPProvider used Timeout: 0 (infinite wait), which can hang the entire agent if an API endpoint becomes unresponsive. Set a 120s safety timeout.

  • Slack AllowFrom type mismatch: SlackConfig used plain []string while every other channel uses FlexibleStringSlice, so numeric user IDs in Slack config would fail to parse.

  • Token estimation wrong for CJK: estimateTokens() divided byte length by 4, but CJK characters are 3 bytes each, causing ~3x overestimation and premature summarization. Switched to utf8.RuneCountInString() / 3 for better cross-language accuracy.

Also added unit tests for the session filename sanitization.

Ref #116

@is-Xiaoen
Copy link
Contributor Author

Fixes four issues identified in the community code review:

// Characters like ':' are valid on Linux but illegal on Windows; we replace
// them so the same key works everywhere. The original key is preserved inside
// the JSON file, so loadSessions still maps back to the right in-memory key.
func sanitizeFilename(key string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use filepath in standard library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified — now uses \ for the colon (the only char that actually appears in session keys) and \ for validation. Dropped the manual replacer. Thanks for the review!

Fixes four issues identified in the community code review:

- Session persistence broken on Windows: session keys like
  "telegram:123456" contain ':', which is illegal in Windows
  filenames. filepath.Base() strips drive-letter prefixes on Windows,
  causing Save() to silently fail. Added sanitizeFilename() to
  replace invalid chars in the filename while keeping the original
  key in the JSON payload.

- HTTP client with no timeout: HTTPProvider used Timeout: 0 (infinite
  wait), which can hang the entire agent if an API endpoint becomes
  unresponsive. Set a 120s safety timeout.

- Slack AllowFrom type mismatch: SlackConfig used plain []string
  while every other channel uses FlexibleStringSlice, so numeric
  user IDs in Slack config would fail to parse.

- Token estimation wrong for CJK: estimateTokens() divided byte
  length by 4, but CJK characters are 3 bytes each, causing ~3x
  overestimation and premature summarization. Switched to
  utf8.RuneCountInString() / 3 for better cross-language accuracy.

Also added unit tests for the session filename sanitization.

Ref sipeed#116
@is-Xiaoen is-Xiaoen force-pushed the fix/code-review-bugs-116 branch from d370ca7 to 0a88ff0 Compare February 15, 2026 01:37
@mengzhuo
Copy link
Collaborator

LGTM, thanks

@mengzhuo mengzhuo merged commit 8eb9dcd into sipeed:main Feb 15, 2026
3 checks passed
emadomedher pushed a commit to emadomedher/picoclaw that referenced this pull request Feb 17, 2026
StarWindv referenced this pull request in StarWindv/PicoClaw-shou Feb 19, 2026
fix: resolve multiple bugs from code review #116
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.

2 participants