Make HTN planning budget configurable via cvar#4616
Conversation
📝 WalkthroughWalkthroughThis PR converts the NPC HTN planner's wall-clock planning budget from a hardcoded value into a runtime-configurable parameter. A new ChangesHTN Budget Runtime Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Well done! This is a clean, coherent refactor that elegantly moves configuration out of hardcoded values into a live-adjustable CVar system. The separation of concerns—contract definition, wrapper class, and integration—is well structured and easy to follow. Great attention to adding supporting documentation and clear dependency flow. 🚥 Pre-merge checks | ✅ 6 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Content.Server/NPC/HTN/HTNSystem.cs (1)
30-34: 💤 Low valueClean, well-scoped CVar wiring — nicely done. The
invokeImmediately: trueargument meansSetMaxTimeruns duringInitialize, before the first_planQueue.Process()inUpdateNPC, so there's no window where planning runs at the stale placeholder budget. Thefloat→doublewidening intoSetMaxTime(double)is also fine.Optional only: the
0.004on Line 33 is a placeholder that's immediately overwritten by the subscription and duplicates the0.004fdefault inCCVars.NPCHTNPlanBudget. If the CVar default ever changes, this literal will silently drift (harmlessly, but confusingly). Not blocking — feel free to leave it given the explanatory comment.Also applies to: 51-54
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Content.Server/NPC/HTN/HTNSystem.cs` around lines 30 - 34, The AdjustableJobQueue is constructed with a hardcoded 0.004 placeholder that is immediately overwritten by the CVar subscription in Initialize (via SetMaxTime invoked with invokeImmediately:true), which can confuse future readers; update the constructor call for _planQueue (symbol: AdjustableJobQueue _planQueue) to use the same default backing value as CCVars.NPCHTNPlanBudget (or otherwise derive the initial value from that CVar) so the literal isn’t duplicated and the initial state matches SetMaxTime, and ensure the Initialize subscription still uses invokeImmediately:true for SetMaxTime.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Content.Server/NPC/HTN/HTNSystem.cs`:
- Around line 30-34: The AdjustableJobQueue is constructed with a hardcoded
0.004 placeholder that is immediately overwritten by the CVar subscription in
Initialize (via SetMaxTime invoked with invokeImmediately:true), which can
confuse future readers; update the constructor call for _planQueue (symbol:
AdjustableJobQueue _planQueue) to use the same default backing value as
CCVars.NPCHTNPlanBudget (or otherwise derive the initial value from that CVar)
so the literal isn’t duplicated and the initial state matches SetMaxTime, and
ensure the Initialize subscription still uses invokeImmediately:true for
SetMaxTime.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 0dfb4b31-882d-4c8b-ba9c-ee2be94ea9e0
📒 Files selected for processing (3)
Content.Server/NPC/HTN/HTNSystem.csContent.Server/_Starlight/NPC/HTN/AdjustableJobQueue.csContent.Shared/CCVar/CCVars.NPC.cs
| // Starlight start | ||
| /// <summary> | ||
| /// Per-tick wall-clock budget (seconds) the HTN planner is allowed to spend running plan jobs. | ||
| /// Lower it to cap NPC planning cost under load. Was a hardcoded 0.004 (4ms) in HTNSystem. | ||
| /// </summary> | ||
| public static readonly CVarDef<float> NPCHTNPlanBudget = | ||
| CVarDef.Create("npc.htn_plan_budget", 0.004f, CVar.SERVERONLY); | ||
| // Starlight end |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Short description
Make HTN planning budget configurable via cvar
Why we need to add this
Media (Video/Screenshots)
Checks
Changelog