Skip to content

feat(server): add draft residency policy - #290

Merged
davide221 merged 3 commits into
Luce-Org:mainfrom
weicj:feat-server-draft-residency-policy
Jun 2, 2026
Merged

davide221 merged 3 commits into
Luce-Org:mainfrom
weicj:feat-server-draft-residency-policy

Conversation

@weicj

@weicj weicj commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR turns the existing draft park/unpark and --lazy-draft behavior into an explicit C++ server residency policy shared by PFlash and DFlash.

On smaller or tightly split GPU setups, draft weights can remain resident after their active work is finished and compete with target restore, target shards, or the next draft load. This PR adds one shared policy surface so PFlash can release the drafter after compression and DFlash can keep its existing lazy-draft lifecycle through the same resolver.

Changes

Shared residency policy

  • Add server/src/placement/draft_residency.h as the common C++ policy layer on top of the existing draft park/unpark capability.
  • Add three policy modes:
    • auto: preserve the existing resident behavior by default, while still honoring the low-VRAM / lazy-draft hint.
    • persistent: keep draft weights loaded across requests.
    • request-scoped: release or park draft weights after the request-side draft work is complete.
  • Add --draft-residency auto|persistent|request-scoped to the server CLI/config surface.
  • Keep --lazy-draft as a compatibility alias for --draft-residency=request-scoped, so existing callers do not break while the lifecycle logic moves into the shared resolver.
  • Expose the resolved mode in /props.runtime.draft_residency.

PFlash lifecycle

  • Add a residency action to the PFlash compression request path.
  • For local Qwen3/Qwen35 PFlash, request-scoped mode releases the PFlash drafter after compression, before later target/draft restore work needs memory.
  • For remote PFlash, the same policy is carried through the IPC path so the remote drafter can be closed after compression instead of remaining unexpectedly resident.

DFlash lifecycle

  • Route DFlash decode draft through the same policy before and after generation.
  • In request-scoped mode, the decode draft is unparked before generation and parked again after generation.
  • Keep the existing lazy_draft behavior available, but express it through the same residency resolver used by PFlash.

Backend coverage

  • Qwen3 / Qwen35: support PFlash release-after-compress through the local PFlash path.
  • Qwen35-family DFlash: support request-scoped decode draft park/unpark through the shared policy.
  • The policy layer itself is backend-neutral and lives under server/src/placement/, so future draft-producing paths can reuse it without adding another lifecycle flag.

Notes

  • Added unit coverage for policy parsing, PFlash/DFlash residency resolution, default config behavior, and /props reporting.
  • Local CUDA test_server_unit passed with 1568 assertions, 0 failures.
  • Gemma4 draft-only park/unpark support is intentionally left for a follow-up PR because it requires extracting the existing Gemma4 draft-load path out of init().

@weicj
weicj force-pushed the feat-server-draft-residency-policy branch from b1cc5a8 to 8cef6bb Compare May 31, 2026 11:41
@weicj
weicj marked this pull request as ready for review May 31, 2026 17:24

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

1 issue found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread server/src/server/http_server.cpp Resolved
easel pushed a commit to easel/lucebox-hub that referenced this pull request May 31, 2026
Merge PR Luce-Org#291's draft residency policy and Gemma4 draft lifecycle support into the current auto-integration stack while preserving passthrough PFlash options, transitive compression overrides, status/cancellation behavior, and existing server unit coverage. PR Luce-Org#290 is represented by this superset head.
easel pushed a commit to easel/lucebox-hub that referenced this pull request May 31, 2026
Record the Luce-Org#291/Luce-Org#290 draft-residency integration, newly non-draft Luce-Org#321/Luce-Org#325 classification, validation, and retained worktree/transcript paths for the May 31 13:30 UTC run.
easel pushed a commit to easel/lucebox-hub that referenced this pull request May 31, 2026
Record the post-push Luce-Org#324 head advance and conflict resolution after integrating Luce-Org#291/Luce-Org#290.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="server/src/server/http_server.cpp">

<violation number="1" location="server/src/server/http_server.cpp:138">
P3: Duplicate `draft_residency` field initializer in both branches of the pflash if/else block. The expression `draft_residency_policy_name(config.draft_residency)` is branch-invariant and appears identically in both the `!pflash_enabled` (line 138) and `pflash_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.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

{"bsa_enabled", nullptr},
{"bsa_alpha", nullptr},
{"lm_head_fix", nullptr},
{"draft_residency", draft_residency_policy_name(config.draft_residency)},

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.

P3: Duplicate draft_residency field initializer in both branches of the pflash if/else block. The expression draft_residency_policy_name(config.draft_residency) is branch-invariant and appears identically in both the !pflash_enabled (line 138) and pflash_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
Check if this issue is valid — if so, understand the root cause and fix it. At server/src/server/http_server.cpp, line 138:

<comment>Duplicate `draft_residency` field initializer in both branches of the pflash if/else block. The expression `draft_residency_policy_name(config.draft_residency)` is branch-invariant and appears identically in both the `!pflash_enabled` (line 138) and `pflash_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.</comment>

<file context>
@@ -135,6 +135,7 @@ json build_props_body(const ServerConfig & config,
             {"bsa_enabled",  nullptr},
             {"bsa_alpha",    nullptr},
             {"lm_head_fix",  nullptr},
+            {"draft_residency", draft_residency_policy_name(config.draft_residency)},
         };
     } else {
</file context>

easel pushed a commit to easel/lucebox-hub that referenced this pull request May 31, 2026
Integrate current Luce-Org/lucebox-hub PR Luce-Org#290 head into the auto-integration patch stack.
easel pushed a commit to easel/lucebox-hub that referenced this pull request May 31, 2026
Record the exact Luce-Org#290/Luce-Org#291 merges, current Luce-Org#321/Luce-Org#325 classification, retained worktrees, and validation for the 2026-05-31 13:57 integration run.
Add the --draft-residency {auto,persistent,request-scoped} row to the
Decode (DFlash + DDTree) flag table and reword --lazy-draft as its legacy
alias, matching the CLI help in server_main.cpp. Pairs with PR Luce-Org#290.

Co-Authored-By: WOZCODE <[email protected]>
@davide221

Copy link
Copy Markdown
Contributor

lgtm

@davide221
davide221 merged commit 8a4678f into Luce-Org:main Jun 2, 2026
3 checks passed
dusterbloom added a commit to dusterbloom/lucebox-hub that referenced this pull request Jun 2, 2026
Resolve additive conflicts:
- model_backend.h: keep both CompressRequest fields (use_transitive from
  PR, residency_action from main Luce-Org#290).
- test_server_unit.cpp: keep both includes (c2_gate.h, draft_residency.h)
  and both test suites; pflash_keep_ratio default asserts 0.10 (PR shipped
  default) alongside main's draft_residency==Auto assert.
Syntax-checked test_server_unit.cpp + qwen35_backend.cpp against merged headers (rc=0).
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.

2 participants