Skip to content

feat: add task polling fail error log#3473

Open
feitianbubu wants to merge 1 commit intoQuantumNous:mainfrom
feitianbubu:pr/6983768377d6839e30cdcccdda675335ff83085f
Open

feat: add task polling fail error log#3473
feitianbubu wants to merge 1 commit intoQuantumNous:mainfrom
feitianbubu:pr/6983768377d6839e30cdcccdda675335ff83085f

Conversation

@feitianbubu
Copy link
Copy Markdown
Contributor

@feitianbubu feitianbubu commented Mar 28, 2026

任务轮询失败记录错误日志

Summary by CodeRabbit

  • New Features
    • Enhanced error logging for task polling failures with improved diagnostic information including failure reasons and execution timing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Walkthrough

A new error billing log recording function is introduced that automatically logs task failures during polling when a task transitions to failure status. The function extracts failure details, computes task duration, and records structured error logs with task and channel metadata.

Changes

Cohort / File(s) Summary
Error Logging
service/task_polling.go
Added recordTaskPollingErrorLog function that records error billing logs when tasks fail during polling, capturing task identifiers, timing metrics, failure reasons, and channel information.

Sequence Diagram

sequenceDiagram
    participant TP as Task Polling Service
    participant TM as Task Model
    participant BL as Billing Log System
    
    TP->>TM: UpdateWithStatus (transition to failure)
    TM-->>TP: Returns Task with TaskStatusFailure
    
    TP->>TP: Check if status == TaskStatusFailure
    
    alt Error Logging Enabled
        TP->>TP: recordTaskPollingErrorLog(ctx, channel, task)
        TP->>TP: Extract task finish time & duration
        TP->>TP: Build error content from FailReason
        TP->>TP: Construct metadata (task ID, channel ID, stage)
        TP->>BL: RecordTaskBillingLog(error details)
        BL-->>TP: Log recorded
        TP->>TP: Emit info log
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop and a skip, when tasks do fail,
We log their woes without travail,
With timing tracked and reasons clear,
The billing logs now hold them dear! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add task polling fail error log' directly matches the main change: adding error logging for task polling failures.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@service/task_polling.go`:
- Around line 535-547: The call to model.RecordTaskBillingLog is passing
nonexistent fields UseTime and Properties on RecordTaskBillingLogParams; remove
those fields and instead include use_time and properties data into the Other map
passed to model.RecordTaskBillingLog (e.g., add keys like "use_time":
useTimeSeconds and "task_properties": task.Properties into the existing other
variable) so the struct matches RecordTaskBillingLogParams and the extra data is
preserved via Other.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94dc1d1d-93e9-4baa-8ac6-3c67f627cd61

📥 Commits

Reviewing files that changed from the base of the PR and between fbf235d and ae0ce85.

📒 Files selected for processing (1)
  • service/task_polling.go

Comment on lines +535 to +547
model.RecordTaskBillingLog(model.RecordTaskBillingLogParams{
UserId: task.UserId,
LogType: model.LogTypeError,
Content: content,
ChannelId: task.ChannelId,
ModelName: taskModelName(task),
Quota: 0,
TokenId: task.PrivateData.TokenId,
Group: task.Group,
UseTime: useTimeSeconds,
Properties: &task.Properties,
Other: other,
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Compilation error: UseTime and Properties fields do not exist in RecordTaskBillingLogParams.

The struct RecordTaskBillingLogParams (defined in model/log.go) only has 9 fields: UserId, LogType, Content, ChannelId, ModelName, Quota, TokenId, Group, and Other. The fields UseTime and Properties passed here do not exist and will cause a build failure.

If you need to include use_time and task properties in the log, add them to the other map instead.

🐛 Proposed fix to remove invalid fields and add data to `other` map
 	other := map[string]interface{}{
 		"task_id":       task.TaskID,
 		"channel_id":    task.ChannelId,
 		"channel_name":  channelName,
 		"channel_type":  channelType,
 		"failure_stage": "task_polling",
+		"use_time":      useTimeSeconds,
 		"admin_info": map[string]interface{}{
 			"use_channel": []string{fmt.Sprintf("%d", task.ChannelId)},
 		},
 	}

 	model.RecordTaskBillingLog(model.RecordTaskBillingLogParams{
 		UserId:    task.UserId,
 		LogType:   model.LogTypeError,
 		Content:   content,
 		ChannelId: task.ChannelId,
 		ModelName: taskModelName(task),
 		Quota:     0,
 		TokenId:   task.PrivateData.TokenId,
 		Group:     task.Group,
-		UseTime:    useTimeSeconds,
-		Properties: &task.Properties,
 		Other:     other,
 	})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@service/task_polling.go` around lines 535 - 547, The call to
model.RecordTaskBillingLog is passing nonexistent fields UseTime and Properties
on RecordTaskBillingLogParams; remove those fields and instead include use_time
and properties data into the Other map passed to model.RecordTaskBillingLog
(e.g., add keys like "use_time": useTimeSeconds and "task_properties":
task.Properties into the existing other variable) so the struct matches
RecordTaskBillingLogParams and the extra data is preserved via Other.

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