Skip to content

fix(agent): prevent concurrent webhook trace overwrites - #19026

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
T1mn:fix/agent-webhook-trace-atomic
Sep 1, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
T1mn:fix/agent-webhook-trace-atomic

Conversation

@T1mn

@T1mn T1mn commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #18883.

  • protect webhook trace read-modify-write updates with a Redis WATCH transaction
  • keep event timestamps monotonic across transaction retries so incremental polling does not skip late commits
  • preserve the existing trace format and 10-minute TTL
  • add regression tests for overlapping runs and concurrent event ordering

Testing

  • focused webhook trace and polling tests on Linux/arm64
  • concurrent regressions repeated 50 times
  • GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go vet ./internal/handler
  • git diff --check

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 30, 2026
@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 235a1d65-78cb-4b41-af0b-3eb6924ebc4e

📥 Commits

Reviewing files that changed from the base of the PR and between 50883d2 and 54ed2b8.

📒 Files selected for processing (2)
  • internal/handler/agent_webhook.go
  • internal/handler/agent_webhook_trace_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Webhook trace persistence now uses Redis optimistic transactions. Trace records include StartTS, retain a 10-minute TTL, retry transaction conflicts, and return persistence errors. Tests cover sequential and concurrent appends.

Changes

Webhook trace persistence

Layer / File(s) Summary
Trace record timestamp
internal/handler/agent_webhook_trace.go
webhookTraceRun now stores StartTS as start_ts.
Transactional Redis persistence
internal/handler/agent_webhook.go
Trace updates use Redis WATCH transactions. The helper applies a 10-minute TTL, retries conflicts up to 100 times, and returns Redis and serialization errors.
Persistence and concurrency validation
internal/handler/agent_webhook_trace_test.go
Tests call the Redis-client helper directly, check errors and TTLs, and validate 32 concurrent appends and strictly increasing event timestamps.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: 🔵 Low · up to 54ed2

The PR prevents concurrent webhook trace updates from overwriting one another while preserving existing polling behavior, format, and retention. A bounded risk remains that interrupted or repeatedly failed updates could duplicate or omit trace events, so the change is mergeable with explicit owner awareness of best-effort trace integrity.

Sequence Diagram(s)

sequenceDiagram
  participant WebhookHandler
  participant appendWebhookTraceWithClient
  participant Redis
  WebhookHandler->>appendWebhookTraceWithClient: append trace event
  appendWebhookTraceWithClient->>Redis: WATCH trace key and read data
  Redis-->>appendWebhookTraceWithClient: existing trace data
  appendWebhookTraceWithClient->>Redis: write JSON with 10-minute TTL
  Redis-->>appendWebhookTraceWithClient: transaction result or conflict
Loading

Suggested reviewers: jinhai-cn

Poem

A rabbit checked the Redis trace
Each event found its ordered place
Conflicts caused a careful retry
Thirty-two runs passed by
Timestamps kept their pace

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing concurrent webhook trace overwrites.
Description check ✅ Passed The description includes the required Summary section and clearly explains the problem, implementation, preserved behavior, regression tests, and validation performed.

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.

@T1mn
T1mn force-pushed the fix/agent-webhook-trace-atomic branch from 50883d2 to 54ed2b8 Compare August 30, 2026 21:00
@JinHai-CN
JinHai-CN requested a review from yuzhichang August 31, 2026 08:51
@yuzhichang
yuzhichang merged commit 8cbe55c into infiniflow:main Sep 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants