claude-code-hub icon indicating copy to clipboard operation
claude-code-hub copied to clipboard

希望将请求体落盘

Open SleepyKFish opened this issue 8 months ago • 2 comments

目前请求体仅在 Redis 中记录,并且设置了 TTL,过期后数据会被自动删除。建议增加一个配置开关,用于控制是否持久化保存请求体,将请求体保存到数据库或文件。

SleepyKFish avatar Mar 23 '26 06:03 SleepyKFish

Thank you for this feature suggestion.

Current Architecture Analysis:

Based on my investigation of the codebase, request bodies are currently stored only in Redis with TTL, not in the database:

  1. Redis Storage (src/lib/session-manager.ts:965-994):

    • Request messages are stored with keys like session:{sessionId}:messages or session:{sessionId}:req:{sequence}:messages
    • TTL is controlled by SESSION_TTL environment variable (default: 300 seconds / 5 minutes)
    • The STORE_SESSION_MESSAGES config controls whether content is redacted ([REDACTED]) or stored in original form
  2. Database Storage (src/drizzle/schema.ts:429-475):

    • The message_request table stores request metadata (provider_id, user_id, model, cost, tokens, session_id, status_code, etc.)
    • It does NOT currently have columns for request body or response body content

Implementation Considerations:

  1. Schema Extension: Adding request_body (JSONB) and optionally response_body (JSONB) columns to the message_request table would be the logical approach for database persistence.

  2. Configuration: A new environment variable (e.g., PERSIST_REQUEST_BODY=true/false) could control this feature independently from the existing Redis caching.

  3. Storage Size: Request bodies can be large, especially with long conversations or multi-modal content. This would significantly increase database storage requirements.

  4. Privacy: The existing STORE_SESSION_MESSAGES redaction logic in src/lib/utils/message-redaction.ts should be respected - when disabled, content should be redacted before persistence.

  5. Performance Impact: Writing large JSON blobs to PostgreSQL on every request may impact throughput. Consider async write mode (similar to existing MESSAGE_REQUEST_WRITE_MODE=async).

Related Code:

  • Session message storage: src/lib/session-manager.ts:965-994
  • Request metadata persistence: src/repository/message.ts:19-72
  • Message redaction: src/lib/utils/message-redaction.ts
  • Environment config: src/lib/config/env.schema.ts:101-109

Automated response from Claude AI

github-actions[bot] avatar Mar 23 '26 06:03 github-actions[bot]

你好,当前提供了langfuse集成,可参考官网文档完成配置接入。并交由langfuse完成请求体记录。

由于请求体体积过大,不建议保存到本地。

ding113 avatar Mar 24 '26 02:03 ding113