Skip to content

Codex/fix scheduled task observability#39

Merged
3 commits merged intomainfrom
codex/fix-scheduled-task-observability
Mar 27, 2026
Merged

Codex/fix scheduled task observability#39
3 commits merged intomainfrom
codex/fix-scheduled-task-observability

Conversation

@LinMoQC
Copy link
Copy Markdown
Owner

@LinMoQC LinMoQC commented Mar 27, 2026

Summary

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactor / code cleanup
  • CI / tooling

Related issue

Closes #

Changes

How to test

Screenshots (if applicable)

Checklist

  • My code follows the project's coding conventions
  • I have run ./lyra lint and there are no type errors
  • I have added/updated tests for the changed functionality
  • I have updated the documentation if behavior changed
  • The PR title follows Conventional Commits format (feat:, fix:, etc.)
  • I have read the CONTRIBUTING.md

LinMoQC added 3 commits March 27, 2026 12:02
…ints

- Extend retrieve_chunks with exclude_notebook_id and source_id filters
- writing-context: use retrieve_chunks + notebook ownership (404)
- related-knowledge: hybrid RAG; 404 if notebook not owned
- source suggestions: semantic retrieve within source; owner-scoped source query
- summarize fallback: order chunks by created_at desc instead of random
- send_message: parallel graph_augmented_context; global conv uses global_search RAG

Made-with: Cursor
- Unit: compose_answer prepends extra_graph_context into reference message (mock llm.chat)
- HTTP: writing-context / related-knowledge 404 + short-text path (PostgreSQL only; skip on SQLite JSONB)
- Integration: send_message passes graph to compose; global conv uses global_search (PostgreSQL only)

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lyra-note-web Ready Ready Preview, Comment Mar 27, 2026 7:47am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Summary by CodeRabbit

发布说明

  • 新增功能

    • 定时任务执行历史现在显示投递状态(邮件、笔记),包括失败原因和详细信息
    • 对话系统集成图谱增强上下文,提升知识关联质量
  • 改进

    • 知识检索支持更细粒度的过滤和排除选项
    • 后台任务日志分离存储,便于错误诊断和监控
    • 邮件发送结果包含具体错误信息,改善故障排查体验
  • 基础设施

    • Celery Beat 现已集成至本地开发、Docker 和生产部署环境

高层概览

该PR在系统中集成了Celery Beat定时任务调度器(文档、Docker配置、CLI更新),扩展了RAG检索功能以支持按笔记本/数据源过滤,为答案撰写添加了图谱增强上下文,改进了邮件投递状态追踪与错误详情记录,建立了后台任务的专用日志记录,并新增前端UI展示与双语本地化文本。

变更明细

分类 / 文件 摘要
文档与执行计划
README.md, README.zh-CN.md, docs/exec-plans/active/*
更新了本地开发与生产部署说明,新增Celery Beat服务描述;新增四份执行计划文档(定时任务邮件投递状态、错误兜底、本地启动预清理、可观测性修复)。
RAG检索能力增强
apps/api/app/agents/rag/retrieval.py
新增_uuid_or_none()规范化函数;_vector_search_fts_search均添加exclude_notebook_idsource_id关键字参数及对应的SQL过滤;retrieve_chunks接口扩展支持这两个参数的透传。
答案撰写与图谱上下文
apps/api/app/agents/writing/composer.py, apps/api/app/services/conversation_service.py
compose_answer添加extra_graph_context参数,将图谱知识作为结构化段落前置于RAG参考资料;ConversationService.send_message并发调用retrieve_chunksgraph_augmented_context,将图谱内容传递给答案生成器。
检索路由与优化
apps/api/app/domains/ai/routers/knowledge.py, apps/api/app/domains/ai/routers/suggestions.py, apps/api/app/domains/ai/routers/writing.py
将硬编码的向量搜索和SQL联接替换为retrieve_chunks统一接口;添加所有权校验(404错误处理);增加检索失败时的SQL回退逻辑。
邮件投递结果追踪
apps/api/app/providers/email.py, apps/api/app/domains/config/router.py
新增EmailSendResult数据类(okerror字段);send_email返回类型从布尔值改为结果对象;新增_format_email_exception处理异常规范化;配置测试端点适配新的返回类型。
后台任务日志与调度
apps/api/app/logging_config.py, apps/api/app/workers/tasks/scheduler.py
日志配置支持自定义日志目录与文件前缀;新增LoggerPrefixFilter实现日志隔离;scheduler新增summarize_delivery_outcome函数聚合投递状态为用户友好的摘要和问题列表;持久化投递错误到run.error_message
技能与工具调整
apps/api/app/skills/builtin/summarize.py
DB回退查询改用确定性的时间戳排序(Chunk.created_at.desc())替代随机排序。
前端投递状态展示
apps/web/src/features/tasks/task-delivery.ts, apps/web/src/features/tasks/task-history-dialog.tsx, apps/web/messages/*
新增task-delivery.ts导出投递徽章构建函数与类型定义;任务历史对话框展示投递状态徽章与详情文本;两种语言的消息文件新增5个投递相关的本地化键。
部署与容器编排
docker-compose.yml, docker-compose.prod.yml
两个Docker Compose配置文件均新增beat服务,运行celery beat命令,依赖api容器健康检查,挂载共享存储。
CLI工具扩展
packages/cli/src/commands/local.js, packages/cli/src/commands/logs.js, packages/cli/src/commands/status.js
本地启动命令新增cleanupStaleProcesses预清理旧进程/容器逻辑,在runDevTUI中新增Beat进程项;日志命令添加beat服务选项;状态命令追踪lyranote-beat-1容器。
单元与集成测试
apps/api/tests/unit/test_*.py, apps/api/tests/integration/test_*.py, apps/web/src/features/tasks/task-delivery.test.ts
新增测试:邮件提供商返回结果对象的断言、日志配置的分离文件验证、图谱上下文在答案中的出现、投递状态徽章映射、路由鉴权与404处理、对话服务RAG+图谱路径覆盖。

时序交互图

sequenceDiagram
    participant User
    participant ConvSvc as ConversationService
    participant Retrieval as RAG Retrieval
    participant GraphCtx as Graph Context
    participant Composer as Composer
    participant LLM

    User->>ConvSvc: send_message(content, notebook_id)
    par 并发检索
        ConvSvc->>Retrieval: retrieve_chunks(content, user_id, notebook_id)
        Retrieval-->>ConvSvc: chunks
    and 并发获取图谱
        ConvSvc->>GraphCtx: graph_augmented_context(content, notebook_id)
        GraphCtx-->>ConvSvc: graph_ctx
    end
    ConvSvc->>Composer: compose_answer(content, chunks, [], extra_graph_context=graph_ctx)
    Composer->>Composer: 前置图谱段落到上下文
    Composer->>LLM: chat(messages_with_graph)
    LLM-->>Composer: response
    Composer-->>ConvSvc: answer
    ConvSvc-->>User: message
Loading
sequenceDiagram
    participant Scheduler as Task Scheduler
    participant EmailProvider as Email Provider
    participant DeliveryTracker as Delivery Tracker
    participant DB as Database
    participant UI as Frontend UI

    Scheduler->>EmailProvider: send_email(config)
    alt 发送成功
        EmailProvider-->>Scheduler: EmailSendResult(ok=True)
        Scheduler->>DeliveryTracker: delivery_status["email"]="sent"
    else 发送失败
        EmailProvider-->>Scheduler: EmailSendResult(ok=False, error="...")
        Scheduler->>DeliveryTracker: delivery_status["email"]="failed"<br/>delivery_status["email_error"]="..."
    end
    Scheduler->>DeliveryTracker: summarize_delivery_outcome(delivery_status)
    DeliveryTracker-->>Scheduler: (summary, issues)
    Scheduler->>DB: save run.error_message=issues
    UI->>DB: fetch task history
    DB-->>UI: delivery_status
    UI->>UI: getTaskDeliveryBadges(delivery_status)
    UI-->>UI: render badges with tone & detail
Loading

代码审查工作量估计

🎯 4 (复杂) | ⏱️ ~60 分钟

可能相关的PR

  • PR #37:修改apps/api/app/providers/email.py的邮件发送功能,引入EmailSendResult数据类与异常格式化处理,单元测试也进行了相应适配。
  • PR #36:修改apps/api/app/providers/email.pysend_email的逻辑,处理SMTP配置校验与from_addr回退,与本PR的邮件结果追踪直接相关。
  • PR #23:修改apps/api/app/agents/writing/composer.pyapps/api/app/services/conversation_service.py,涉及提示词组装与上下文参数传递,与本PR的图谱上下文集成相同的代码路径。
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR描述仅包含未填充的模板内容,缺少具体的变更说明、测试方法和相关问题链接等实质性信息。 请补充PR描述,填入摘要、变更列表、测试步骤和相关问题链接等具体信息,以便审阅者理解改动的目的和影响范围。
Docstring Coverage ⚠️ Warning Docstring coverage is 32.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed PR标题 'Codex/fix scheduled task observability' 准确反映了主要变更内容:修复定时任务可观测性,涵盖日志配置、Celery Beat集成和Docker Compose更新等核心改动。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-scheduled-task-observability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LinMoQC LinMoQC closed this pull request by merging all changes into main in ad58f55 Mar 27, 2026
@LinMoQC LinMoQC deleted the codex/fix-scheduled-task-observability branch March 27, 2026 08:00
@coderabbitai coderabbitai bot mentioned this pull request Mar 31, 2026
12 tasks
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