-
Notifications
You must be signed in to change notification settings - Fork 218
feat(server): add draft residency policy #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davide221
merged 3 commits into
Luce-Org:main
from
weicj:feat-server-draft-residency-policy
Jun 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Drafter residency policy shared by draft-style runtime paths. | ||
| // | ||
| // The policy is intentionally scoped by draft use-case. PFlash compression can | ||
| // release its drafter immediately after prompt compression, while DFlash decode | ||
| // draft may need to stay resident across requests for latency. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace dflash::common { | ||
|
|
||
| enum class DraftResidencyPolicy { | ||
| Auto, | ||
| Persistent, | ||
| RequestScoped, | ||
| }; | ||
|
|
||
| enum class DraftResidencyUse { | ||
| PFlashCompress, | ||
| DFlashDecode, | ||
| MtpDecode, | ||
| }; | ||
|
|
||
| enum class DraftResidencyAction { | ||
| KeepLoaded, | ||
| ReleaseAfterUse, | ||
| }; | ||
|
|
||
| struct DraftResidencyContext { | ||
| DraftResidencyUse use = DraftResidencyUse::PFlashCompress; | ||
| bool low_vram_hint = false; | ||
| bool has_decode_draft = false; | ||
| }; | ||
|
|
||
| inline const char * draft_residency_policy_name(DraftResidencyPolicy policy) { | ||
| switch (policy) { | ||
| case DraftResidencyPolicy::Auto: return "auto"; | ||
| case DraftResidencyPolicy::Persistent: return "persistent"; | ||
| case DraftResidencyPolicy::RequestScoped: return "request-scoped"; | ||
| } | ||
| return "auto"; | ||
| } | ||
|
|
||
| inline bool parse_draft_residency_policy(const std::string & value, | ||
| DraftResidencyPolicy & out) { | ||
| if (value == "auto") { | ||
| out = DraftResidencyPolicy::Auto; | ||
| return true; | ||
| } | ||
| if (value == "persistent") { | ||
| out = DraftResidencyPolicy::Persistent; | ||
| return true; | ||
| } | ||
| if (value == "request-scoped" || value == "request_scoped") { | ||
| out = DraftResidencyPolicy::RequestScoped; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| inline DraftResidencyAction resolve_draft_residency_action( | ||
| DraftResidencyPolicy policy, | ||
| const DraftResidencyContext & ctx) { | ||
| if (policy == DraftResidencyPolicy::Persistent) { | ||
| return DraftResidencyAction::KeepLoaded; | ||
| } | ||
| if (policy == DraftResidencyPolicy::RequestScoped) { | ||
| return DraftResidencyAction::ReleaseAfterUse; | ||
| } | ||
|
|
||
| switch (ctx.use) { | ||
| case DraftResidencyUse::PFlashCompress: | ||
| // In auto mode, only release the PFlash drafter when the operator gave | ||
| // a low-VRAM hint. That preserves the existing fast resident path while | ||
| // allowing small-card setups to make room for decode draft/target state. | ||
| return ctx.low_vram_hint | ||
| ? DraftResidencyAction::ReleaseAfterUse | ||
| : DraftResidencyAction::KeepLoaded; | ||
| case DraftResidencyUse::DFlashDecode: | ||
| // DFlash draft is latency-sensitive; keep it resident unless the | ||
| // operator explicitly opted into the low-VRAM/request-scoped path. | ||
| return (ctx.low_vram_hint && ctx.has_decode_draft) | ||
| ? DraftResidencyAction::ReleaseAfterUse | ||
| : DraftResidencyAction::KeepLoaded; | ||
| case DraftResidencyUse::MtpDecode: | ||
| // Placeholder use-case for future draft-style decode paths. Default to | ||
| // persistent until a concrete MTP residency lifecycle is wired. | ||
| return DraftResidencyAction::KeepLoaded; | ||
| } | ||
| return DraftResidencyAction::KeepLoaded; | ||
| } | ||
|
|
||
| } // namespace dflash::common |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Duplicate
draft_residencyfield initializer in both branches of the pflash if/else block. The expressiondraft_residency_policy_name(config.draft_residency)is branch-invariant and appears identically in both the!pflash_enabled(line 138) andpflash_enabled(line 164) branches. This creates a maintenance risk — any future change to the field name or value expression must be applied in two places.Prompt for AI agents