Skip to content

fix(server): forward plan fleet overrides for task routes#397

Merged
huan-yp merged 1 commit intomainfrom
yltx/web-fleet-override
Apr 6, 2026
Merged

fix(server): forward plan fleet overrides for task routes#397
huan-yp merged 1 commit intomainfrom
yltx/web-fleet-override

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Apr 4, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 4, 2026 16:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the task execution routes to forward “fleet overrides” from the request into the underlying combat runners, enabling the frontend to dynamically override fleet selection without modifying YAML plans.

Changes:

  • Forward fleet_id / fleet overrides into run_normal_fight.
  • Add fleet override forwarding into run_event_fight, with an explicit fleet_id precedence rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +111 to +113
request_plan = request.plan
override_fleet_id = request_plan.fleet_id if request_plan is not None else None
override_fleet = request_plan.fleet if request_plan is not None else None
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

CombatPlanRequest.fleet_id has a default of 1 (non-optional). When the client sends plan_id + a partial plan only to override fleet (or other fields), request_plan.fleet_id will still be 1, so this will unintentionally override the YAML plan’s fleet_id to 1 by passing fleet_id=override_fleet_id into run_normal_fight. Consider treating fleet overrides as “only if explicitly provided”, e.g. derive overrides from request_plan.model_fields_set / exclude_unset=True and pass fleet_id=None unless fleet_id was actually included in the request payload.

Suggested change
request_plan = request.plan
override_fleet_id = request_plan.fleet_id if request_plan is not None else None
override_fleet = request_plan.fleet if request_plan is not None else None
# 仅在请求中显式提供对应字段时才覆盖,避免 Pydantic 默认值意外覆盖 YAML 配置。
request_plan = request.plan
request_plan_fields = (
getattr(request_plan, 'model_fields_set', None)
or getattr(request_plan, '__fields_set__', set())
if request_plan is not None
else set()
)
override_fleet_id = (
request_plan.fleet_id
if request_plan is not None and 'fleet_id' in request_plan_fields
else None
)
override_fleet = (
request_plan.fleet
if request_plan is not None and 'fleet' in request_plan_fields
else None
)

Copilot uses AI. Check for mistakes.
Comment on lines +168 to +171
# 优先级: 顶层 fleet_id > plan 覆盖 fleet_id > YAML 内 fleet_id
if request.fleet_id is not None:
fleet_id = request.fleet_id
elif request_plan is not None and request_plan.fleet_id is not None:
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

Because CombatPlanRequest.fleet_id is a non-optional field with default 1, the condition request_plan is not None and request_plan.fleet_id is not None will be true whenever request.plan is present. That means sending plan_id + a partial plan (e.g. only fleet) will force fleet_id to 1 and ignore the YAML’s plan.fleet_id. To avoid accidental overrides, only treat request_plan.fleet_id as an override when it was explicitly set in the incoming JSON (e.g. check request_plan.model_fields_set or use a dict built with exclude_unset=True).

Suggested change
# 优先级: 顶层 fleet_id > plan 覆盖 fleet_id > YAML 内 fleet_id
if request.fleet_id is not None:
fleet_id = request.fleet_id
elif request_plan is not None and request_plan.fleet_id is not None:
plan_fleet_id_is_set = request_plan is not None and 'fleet_id' in request_plan.model_fields_set
# 优先级: 顶层 fleet_id > plan 显式覆盖 fleet_id > YAML 内 fleet_id
if request.fleet_id is not None:
fleet_id = request.fleet_id
elif plan_fleet_id_is_set:

Copilot uses AI. Check for mistakes.
@huan-yp huan-yp merged commit 8120556 into main Apr 6, 2026
6 checks passed
@huan-yp huan-yp deleted the yltx/web-fleet-override branch April 6, 2026 14:03
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.

3 participants