Skip to content

refactor: sessions 交互#177

Open
Nomikfk1215 wants to merge 1 commit into1024XEngineer:mainfrom
Nomikfk1215:main
Open

refactor: sessions 交互#177
Nomikfk1215 wants to merge 1 commit into1024XEngineer:mainfrom
Nomikfk1215:main

Conversation

@Nomikfk1215
Copy link
Copy Markdown
Collaborator

No description provided.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 65.70248% with 83 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/session/store.go 65.89% 35 Missing and 9 partials ⚠️
internal/tui/model.go 68.60% 18 Missing and 9 partials ⚠️
cmd/bytemind/main.go 52.00% 6 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@xgopilot xgopilot bot left a comment

Choose a reason for hiding this comment

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

Found a few issues worth addressing before merge.

if hasToolResultPart(msg) {
continue
}
if hasNonEmptyTextPart(msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

userEffectiveInputCount only increments for non-empty text parts. User turns that contain non-text input only (for example image/file parts) are counted as zero, so IsZeroMessageSession can misclassify real sessions and let PurgeZeroMessageSessions delete them. Consider counting any meaningful non-tool-result user content, not just text.

if m.sess != nil {
excludeID = m.sess.ID
}
_, _, _ = m.store.PurgeZeroMessageSessions(m.workspace, excludeID)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loadSessionsCmd now runs purge immediately before List, and defaultSessionLimit is now unbounded (0). That means a full scan/decode pass for purge plus another full scan/decode for listing on each reload. With many sessions this will regress responsiveness. Consider either restoring a bounded list limit or combining cleanup and listing into one pass.

"- Long pasted code/text is compressed to `[Paste #N ~X lines]`.",
"- Use `[Paste]`, `[Paste #N]`, `[Paste line3]`, or `[Paste #N line3~line7]` to expand references.",
"- Restore in TUI: press `Ctrl+L` or run `/session`, choose a session, then press `Enter`.",
"- CLI-only restore: use `/resume <id>` in `bytemind chat`.",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This help line says to use /resume <id> in bytemind chat, but in this PR /resume is CLI-only while TUI restore flow is /session + Enter. The wording is currently contradictory and will mislead users.

@Nomikfk1215 Nomikfk1215 reopened this Apr 14, 2026
Copy link
Copy Markdown

@xgopilot xgopilot bot left a comment

Choose a reason for hiding this comment

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

Found two issues worth addressing: one data-loss risk in zero-message detection and one scalability regression in session loading.

if hasToolResultPart(msg) {
continue
}
if hasNonEmptyTextPart(msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

userEffectiveInputCount only increments when a user message has non-empty text parts. User turns with non-text input only (for example file/image parts) are treated as zero-input, so IsZeroMessageSession can incorrectly classify real sessions as disposable and purge them. Consider counting any meaningful non-tool-result user content, not just text parts.

if m.sess != nil {
excludeID = m.sess.ID
}
_, _, _ = m.store.PurgeZeroMessageSessions(m.workspace, excludeID)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loadSessionsCmd now purges on every load and then calls List with defaultSessionLimit = 0 (unbounded). This causes two full directory scans/decodes per reload, which can degrade responsiveness as session count grows. Consider restoring a bounded list limit or combining purge + list into a single pass.

Copy link
Copy Markdown

@xgopilot xgopilot bot left a comment

Choose a reason for hiding this comment

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

Found 2 issues worth fixing: one data-loss bug in zero-message detection and one performance regression in session loading.

if hasToolResultPart(msg) {
continue
}
if hasNonEmptyTextPart(msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

userEffectiveInputCount increments only when a user message has non-empty text parts. User turns containing only non-text input (e.g. image_ref) are treated as zero input, so IsZeroMessageSession can misclassify real sessions and PurgeZeroMessageSessions may delete them. Consider counting any meaningful non-tool-result user part, not only text.

if m.sess != nil {
excludeID = m.sess.ID
}
_, _, _ = m.store.PurgeZeroMessageSessions(m.workspace, excludeID)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loadSessionsCmd now performs PurgeZeroMessageSessions before List, and defaultSessionLimit is set to 0 (unbounded). This creates two full scans/loads on every sessions refresh, which will noticeably slow the TUI with large session stores. Consider restoring a bounded default limit or combining purge+list in a single pass.

Copy link
Copy Markdown

@xgopilot xgopilot bot left a comment

Choose a reason for hiding this comment

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

Focused review complete. I found two issues worth fixing before merge.

if hasToolResultPart(msg) {
continue
}
if hasNonEmptyTextPart(msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

userEffectiveInputCount only increments for non-empty text parts. User turns can be image-only (image_ref parts are valid and produced by the TUI), so these sessions are misclassified as zero-message and may be purged. Count meaningful non-tool-result user content beyond text.

if m.sess != nil {
excludeID = m.sess.ID
}
_, _, _ = m.store.PurgeZeroMessageSessions(m.workspace, excludeID)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loadSessionsCmd now purges immediately before List, while defaultSessionLimit is unbounded (0). This creates two full store passes on each reload (purge + list) and can noticeably degrade responsiveness with many sessions. Consider a bounded list limit or a single-pass cleanup/listing path.

Copy link
Copy Markdown

@xgopilot xgopilot bot left a comment

Choose a reason for hiding this comment

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

Consolidated review after cross-checking code-quality, performance, and security passes.

Two issues are still noteworthy: one correctness/data-loss risk in zero-message classification, and one scalability regression in session reload flow.

if hasToolResultPart(msg) {
continue
}
if hasNonEmptyTextPart(msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

userEffectiveInputCount only treats non-empty text as user input. User turns that are valid but non-text (for example image_ref) will be counted as zero, so IsZeroMessageSession can incorrectly classify and purge real sessions. Consider counting any non-tool-result user content, not just text parts.

if m.sess != nil {
excludeID = m.sess.ID
}
_, _, _ = m.store.PurgeZeroMessageSessions(m.workspace, excludeID)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loadSessionsCmd now does PurgeZeroMessageSessions immediately before List, and defaultSessionLimit is 0 (unbounded). This creates two full-store scans/loads on every refresh and can degrade responsiveness as session count grows. Consider a bounded default or a single-pass strategy that combines cleanup + listing.

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