Skip to content

fix(profile-helper): fix session persistence, block enforcement, anon recovery + docs#4

Open
Boyuan-Zheng wants to merge 4 commits intomainfrom
boyuan
Open

fix(profile-helper): fix session persistence, block enforcement, anon recovery + docs#4
Boyuan-Zheng wants to merge 4 commits intomainfrom
boyuan

Conversation

@Boyuan-Zheng
Copy link
Contributor

画像构建系统漏洞修复(8项)

基于代码沙盘推演发现并修复了画像系统的全部关键漏洞,配套完整技术文档。


修复的问题

P0 数据丢失(最高优先级)

L1+L2:AI 超过1小时后失忆,断点续接失效

  • sessions.py 新增 save_messages / load_messages,对话历史每轮写入磁盘
  • _new_session 重建时从磁盘恢复 messages,AI 可真正续接上下文
  • profile_helper.py 的 generate() 在每轮 run_block_agent 后调用 save_messages

L5+L6:评分题出现多个,只有第一个答案被记录

  • block_agent.py 工具循环加 interactive_block_count,第2个 ask_xxx 被系统拦截
  • types.ts ChatMessage 新增 _responded_blocks: string[] 字段(Block 级标记)
  • ChatWindow.tsx handleBlockRespond 和 BlockRenderer.disabled 改为 Block 级判断

P1 重要修复

L3:匿名用户 session 过期后画像数据丢失

  • sessions.py _new_session 匿名分支新增按 sid[:8] 查找已有 profile/forum 文件

L4:collect-basic-info 全量写盘,中途断线答案全丢

  • collect-basic-info/SKILL.md 改为分批写盘(每批完成立即 write_profile)
  • 能力自评从"每轮2题"改为"每轮1题"(配合 L5 修复)

L7:一次一问无全局代码约束

  • prompts.py META_SYSTEM_PROMPT 规则1追加"系统在代码层面会拦截"说明

L8:block_agent max_iterations 硬编码20,复杂流程截断

  • block_agent.py 改为 max(10, int(os.getenv("PROFILE_HELPER_BLOCK_MAX_ITERATIONS", "30")))

P2 优化与新功能

L13:匿名用户登录后画像数据丢失

  • sessions.py 新增 _migrate_anon_to_user,get_or_create 登录时自动触发迁移

新增:对话历史查询接口

  • profile_helper.py 新增 GET /chat-history/{session_id}
  • profileHelperApi.ts 新增 getChatHistory() 函数

新增:画像完整度后端工具

  • block_agent.py 新增 check_profile_completeness 工具(正则验证 F1-F7 必填字段)

修改文件清单

后端(backend submodule,commit fecf7f0)

  • app/services/profile_helper/sessions.py
  • app/services/profile_helper/block_agent.py(新增文件)
  • app/services/profile_helper/prompts.py
  • app/api/profile_helper.py
  • libs/profile_helper/skills/collect-basic-info/SKILL.md
  • libs/profile_helper/skills/import-ai-memory/SKILL.md

前端

  • frontend/src/modules/profile-helper/types.ts
  • frontend/src/modules/profile-helper/ChatWindow.tsx
  • frontend/src/modules/profile-helper/profileHelperApi.ts

文档(新增4份)

  • docs/画像构建系统_完整流程分析_v1.md
  • docs/画像系统_沙盘推演_逻辑漏洞分析_v1.md
  • docs/画像系统_技术修改方案与新架构_v1.md
  • docs/画像系统_修改日志_v1.md

验证

全部修改已通过 Python linter 检查和功能验证(messages 持久化链路、completeness check、block_agent 导入、前端 TypeScript 类型检查)。

向后完全兼容,无破坏性 API 变更。

… config

Migrate profile helper module: new blocks (ActionsBlock, ChartBlock, ChoiceBlock,
RatingBlock, TextInputBlock, CopyableBlock, BlockRenderer), profile components
(ScientistCard, ScientistMatchSection, ScientistScatter, profile sections), types.ts

Update ChatWindow, ProfilePanel, ProfilePage, ScaleTestPage, scales data,
scoring utils, and profile-helper.css

Add vite proxy rule for /api/auth routing to localhost:8001 (auth service)

Add DEPLOY_ARCH.md and full docs suite: product overview, product design,
implementation plan, execution plan, profile page migration plan

Made-with: Cursor
… anon profile recovery

Frontend changes:
- types.ts: add _responded_blocks (string[]) field to ChatMessage for block-level response tracking
- ChatWindow.tsx: handleBlockRespond now accepts blockId param; marks individual blocks as responded instead of entire message; BlockRenderer disabled/responded logic updated to block-level
- profileHelperApi.ts: add getChatHistory() function for GET /chat-history/{session_id}

Backend submodule update (fecf7f0):
- sessions.py: message history disk persistence (save_messages/load_messages)
- sessions.py: anonymous profile recovery by session id prefix
- sessions.py: _migrate_anon_to_user for login-time profile migration
- block_agent.py: single interactive block per turn enforcement
- block_agent.py: check_profile_completeness tool (F1-F7 validation)
- block_agent.py: max_iterations configurable via env var (default 30)
- profile_helper.py: GET /chat-history/{session_id} endpoint
- prompts.py: reinforce one-question-per-turn with code-level notice
- collect-basic-info/SKILL.md: 1 rating per round; incremental write_profile per batch

Docs (new):
- docs/画像构建系统_完整流程分析_v1.md
- docs/画像系统_沙盘推演_逻辑漏洞分析_v1.md
- docs/画像系统_技术修改方案与新架构_v1.md
- docs/画像系统_修改日志_v1.md

Made-with: Cursor
… for CI visibility

Commit fecf7f0 exists on Boyuan-Zheng/Resonnet:boyuan but not yet on TashanGKD/Resonnet.
When maintainer merges backend changes to TashanGKD/Resonnet, revert this to TashanGKD/Resonnet.git

Made-with: Cursor
deploy.yml:
- Replace broad 'location /' snippet with scoped 'location ^~ /VITE_BASE_PATH/'
  so tashan.chat's nginx only intercepts /topic-lab/ traffic, not the whole site
- Read VITE_BASE_PATH from .env (default /topic-lab/) to keep it config-driven
- Add redirect: GET /topic-lab -> 302 /topic-lab/
- Drop separate /api/ snippet (internal container nginx handles all API routing)
- Rename snippet file to topiclab-main.conf

frontend/nginx.conf:
- Fix double-api path bug: /topic-lab/api/api/v1/ -> /topic-lab/api/v1/

frontend/nginx.conf.template:
- Fix double-api path bug: __BASE_PATH__api/api/v1/ -> __BASE_PATH__api/v1/
- Add missing /topics and /topics/ API routes (align with nginx.conf)

Made-with: Cursor
@FZR95 FZR95 force-pushed the main branch 2 times, most recently from 68ecd39 to b6969c3 Compare March 20, 2026 12:11
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