fix(agent-api):修复增加分析任务请求幂等性问题 - #44
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
服务端增加请求幂等性
在
app/agent/job_service.py中增加:Idempotency-Key,长度为 16 到 128 位。用户 ID + Idempotency-Key查找历史 job。session_id和message生成 HMAC-SHA256 请求指纹。这样可以保证:
API 层增加协议处理
在
app/agent/routes.py中:Idempotency-Key:返回400。409。existing: true。数据库结构变更
新增迁移:
f9a0b1c2d3e4_add_agent_job_idempotency.py增加:
字段允许为空,是为了兼容已经存在的历史 job。历史 job 不会被删除,也不会被强行补造幂等键。
同时更新了:
app/db.py:启动 readiness 检查。Database/inspection.py:完整性检查。Database/deep_audit.py:deep audit 结构检查。在
app/static/js/script.js中:5xx时最多重试一次。Idempotency-Key。4xx不自动重试,避免错误请求重复发送。新增请求幂等测试:
tests/unit/agent/test_job_idempotency.py覆盖:
同时更新了 API 测试、迁移静态测试、
AGENTS.md和README/开发日志.md。当前验证结果
已通过: