feat(role-play): add character/mod system, memory, session management…#8
feat(role-play): add character/mod system, memory, session management…#8MinimaxLanbo merged 2 commits intomainfrom
Conversation
PR #8 Code ReviewOverviewThis PR introduces a character/mod system with memory management and session-based storage. The changes include:
Issues Found1. Potential Stale Closure Issue (Medium)File: useEffect(() => {
loadChatHistory(sessionPath).then(...);
loadMemories(sessionPath).then(setMemories);
}, [sessionPath, modCollection, seedPrologue]);The Recommendation: Use a ref for 2. Race Condition in Memory Loading (Medium)File: const reads = jsonFiles.map(async (f) => {
// ... fetches
});
await Promise.all(reads);No concurrency limiting for memory file reads. With many memory files, this could cause network issues. The 3. Missing Error Propagation (Medium)File: The catch {
// silently ignore
}
return entry;Errors are silently ignored and the entry is returned as if successful. Callers have no way to know if the save actually succeeded. 4. No Input Validation on Session Path (Low)File: export function setSessionPath(path: string): void {
_sessionPath = path;
}No validation on the session path. Malicious input could potentially cause path traversal issues when combined with disk operations. 5. Module-Level Counter Not Persistent (Low)File: let _nextId = 1;
export function generateCharacterId(): string {
return `char_${Date.now()}_${_nextId++}`;
}The 6. Inline Style Usage (Low)File: <div style={{ flex: 1 }} />The project uses SCSS modules consistently. This inline style breaks consistency. 7. Missing Cleanup for Async Operations (Low)File: The debounced save effect doesn't handle component unmount during the timeout well: return () => {
if (saveTimerRef.current) clearTimeout(saveTimerRef.current);
};If 8. Unused Variable (Low)File: const sessionPath = buildSessionPath(charCollection.activeId, modCollection.activeId);
setSessionPath(sessionPath);Calling SecurityThe path sanitization in const safePath = relPath.replace(/[^a-zA-Z0-9_\-./]/g, '_').replace(/\.\./g, '');This prevents path traversal attacks. Recommendations
Positive Observations
|
8a35dd3 to
c2ee967
Compare
PR #8 Code ReviewSummaryThis PR introduces a comprehensive role-play character/mod system with memory, session management, and UI improvements. The changes add:
Issues Found1. TypeScript - Untyped Empty Catch Blocks (Medium)Several files use empty catch blocks that silently swallow errors:
Recommendation: Add logging or return meaningful values from catch blocks to aid debugging. 2. React - Missing Dependency in useEffect (Medium)In useEffect(() => {
// ... loads modCollection
if (loadedMessages.length === 0 && loadedHistory.length === 0) {
seedPrologue(); // This function uses modCollection but modCollection is not in deps
}
}, []); // Missing dependenciesThis works because 3. Memory Manager - Potential Race Condition (Low)In const reads = jsonFiles.map(async (f) => {
// individual fetches
});
await Promise.all(reads);This is fine for loading, but if files are added/deleted during the list operation, there could be inconsistencies. Not critical for typical usage. 4. characterManager - Unused Export (Low)
5. ModManager - Mutable State in Class (Low)In this.state.completed_targets.push(id);While this works, it could cause issues if the same ModManager instance is used in multiple places. Consider immutable updates or defensive copying. 6. Hardcoded API Paths (Info)API endpoints are hardcoded:
These should work for the dev server, but consider if these need to be configurable for production. Positive Observations
Security ConsiderationsNo major security concerns. The code:
Build & CompatibilityThe changes appear compatible with the existing codebase. New exports are added to lib/index.ts appropriately. Recommendations
|
… and UI improvements - Add character manager with multi-character support and emotion system - Add mod manager for configurable role-play scenarios (prologue, system prompt, tools) - Add hybrid memory system (SP injection + save_memory tool) for cross-session persistence - Add session reset API to clear all session data and restore initial state - Migrate storage from IndexedDB to disk-based persistence (~/.openroom/sessions/) - Decouple image generation tool from storage (generate only, save via file tools) - Persist suggested replies in chat history to survive page refresh - Redesign floating action buttons as horizontal bottom toolbar
c2ee967 to
2f0fc4c
Compare
PR #8 Code ReviewSummaryThis PR adds a character/mod system, memory management, and session management to the OpenRoom application. The changes include:
Issues Found1. ID Collision Risk After HMR (Medium)Files: The let _nextId = 1;
export function generateCharacterId(): string {
return `char_${Date.now()}_${_nextId++}`;
}Recommendation: Use a more unique identifier like 2. Missing batchConcurrent Usage (Medium)File: The code uses const reads = jsonFiles.map(async (f) => { ... });
await Promise.all(reads);Recommendation: Replace with 3. Missing Error Boundaries in UI Panels (Low)Files: The panel components don't handle edge cases gracefully:
4. Silent Error Handling (Low)Files: Error handling in migration functions uses empty catch blocks, making debugging difficult: } catch (e) {
console.warn('[CharacterManager] migrateOldFormat failed:', e);
}This is acceptable for migrations but could log more context. 5. Potential Memory Leak (Low)File: The module-level 6. Session Path Not Reset on Character/Mod Change (Low)File: When users switch characters or mods, the old session data isn't automatically cleared. This could lead to stale data being displayed. 7. React Performance (Low)File: Some callback functions may benefit from Security: Good
TypeScript: Good
What's Working Well
Action Items
|
e0bc427 to
c7f390c
Compare
… and UI improvements
Summary
Brief description of the changes.
Changes
Related Issues
Closes #
Checklist
pnpm run lintpassespnpm buildpasses