Skip to content

fix(vercel): 解决 Vercel 环境下启用自动删除会话失效#474

Merged
CJackHwang merged 2 commits intoCJackHwang:devfrom
hefengfan0615:main
May 10, 2026
Merged

fix(vercel): 解决 Vercel 环境下启用自动删除会话失效#474
CJackHwang merged 2 commits intoCJackHwang:devfrom
hefengfan0615:main

Conversation

@hefengfan0615
Copy link
Copy Markdown

@hefengfan0615 hefengfan0615 commented May 10, 2026

问题描述

在 Vercel 部署环境中,"删除当前对话"功能无法正常工作。用户开启自动删除后,对话仍然不会被删除。

问题分析

在 Vercel 部署环境中,流式请求使用了一种特殊的 "prepare-release" 两阶段流程:

  1. Prepare 阶段:创建 session 并返回 session_id,但由于 Vercel 的冷启动优化,实际请求处理转移到 Node.js 端
  2. Release 阶段:流结束后 Node.js 调用 Go 端释放 lease

原来的代码问题在于:

  • 在 Prepare 阶段创建的 sessionID 没有保存到 lease 中
  • Release 时虽然会释放 lease,但没有执行删除会话的逻辑

修复内容

1. handler.go

streamLease 结构体添加 SessionID 字段,用于保存会话 ID:

type streamLease struct {
	Auth      *auth.RequestAuth
	SessionID string  // 新增
	ExpiresAt time.Time
}

2. vercel_stream.go

  • holdStreamLease 函数添加 sessionID 参数
  • releaseStreamLease 函数返回 (bool, *auth.RequestAuth, string) 三个值,包含认证信息和会话 ID
  • handleVercelStreamRelease 在释放时调用 autoDeleteRemoteSession 触发自动删除

3. vercel_prepare_test.go

  • 更新现有测试 TestStreamLeaseLifecycle 适配新签名
  • 添加新测试 TestHandleVercelStreamReleaseTriggersAutoDelete 验证 Vercel 流释放时的自动删除功能

预期效果

当用户开启"仅删除当前对话"(auto_delete_mode=single)时:

  • ✅ 在 Vercel 流式请求结束后,会正确调用 DeepSeek API 删除当前会话
  • ✅ 会话被删除后,不会出现在用户的对话历史中
  • ✅ 与非 Vercel 部署的行为保持一致

测试结果

所有相关单元测试均已通过:

测试用例 描述 状态
TestHandleVercelStreamReleaseTriggersAutoDelete 验证 Vercel 流释放时触发自动删除 ✅ 通过
TestStreamLeaseLifecycle 验证 lease 生命周期 ✅ 通过
TestChatCompletionsAutoDeleteModes 验证自动删除模式 ✅ 通过

影响范围

此修改仅影响 Vercel 流式部署

The "delete current conversation" feature was not working on Vercel
deployment because the stream flow uses a separate lease mechanism.
The session_id created during prepare phase was not preserved for
deletion when the stream ends.

Changes:
- Add SessionID field to streamLease struct to preserve session_id
- Pass session_id to holdStreamLease during prepare
- Modify releaseStreamLease to return auth and session_id
- Call autoDeleteRemoteSession in handleVercelStreamRelease when
  releasing a lease with auto-delete mode enabled

Closes #vercel-auto-delete
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

Someone is attempting to deploy a commit to the cjack's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df6859bddc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/httpapi/openai/chat/vercel_stream.go
@hefengfan0615 hefengfan0615 changed the title fix(vercel): 在 Vercel 流释放时启用自动删除会话 fix(vercel): 解决 Vercel 环境下启用自动删除会话失效 May 10, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

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

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment May 10, 2026 8:22am

@CJackHwang CJackHwang changed the base branch from main to dev May 10, 2026 08:21
@CJackHwang CJackHwang merged commit 0b05915 into CJackHwang:dev May 10, 2026
7 checks passed
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.

2 participants