Skip to content

Expose ordinary request retirement for safe background calibration - #305

Merged
Gajesh2007 merged 2 commits into
mainfrom
codex/ordinary-request-retirement
Oct 13, 2026
Merged

Gajesh2007 merged 2 commits into
mainfrom
codex/ordinary-request-retirement

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Ordinary autoregressive EngineV2.submit returns an event stream but no request-retirement acknowledgement. A watchdog can end that stream while the engine still owns the row and its KV state, so a host cannot safely hand shared capacity to foreground work after cancelling a background probe.

Add EngineV2.submitWithRetirement(_:), backed by the same submitOrdinary registration and exact stream-generation ownership acknowledgement already used by deadline admission. Preserve native work-admission checks and the native-only contract of submitWithNativeRetirement. Zero-work submissions acknowledge immediately; cancellation of the waiter does not acknowledge outstanding work.

This enables safe ordinary-Qwen startup calibration in d-inference #1446. The provider PR pins this change.

Before

flowchart TD
  A["Host submits background work"] --> B["EngineV2.submit"]
  B --> C["Event stream"]
  C --> D["Watchdog or consumer ends stream"]
  D --> E["Host has no ordinary-request retirement handle"]
  F["Engine may still own row and KV"] --> E
  classDef code fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
  classDef problem fill:#fee2e2,stroke:#dc2626,color:#7f1d1d
  class A,B,C code
  class D,E,F problem
Loading

After

flowchart TD
  A["Host submits background work"] --> B["EngineV2.submitWithRetirement"]
  B --> C["Existing submitOrdinary registration"]
  C --> D["Event stream plus exact-generation retirement handle"]
  D --> E["Terminal may arrive early"]
  E --> F["Host awaits retirement"]
  F --> G["Engine releases row and KV ownership"]
  G --> H["Host may release shared capacity"]
  classDef code fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
  classDef good fill:#dcfce7,stroke:#16a34a,color:#14532d
  class A,B,C,D,E,F code
  class G,H good
Loading

Validation

  • swift build --build-tests --jobs 4 passed.
  • With source-matched Metal resources: swift test --skip-build --no-parallel --filter 'OrdinaryRequestRetirementTests|CBv2FirstTokenDeadlineEngineTests' passed all 19 tests (three new tests and 16 existing tests).
  • The retirement regression holds the actual engine step while its watchdog terminates the consumer stream, cancels the waiter, and verifies that acknowledgement waits for real cleanup.
  • Provider integration runs real reduced-width dense and MoE Qwen models through production slot assembly with both paged and contiguous KV, before any customer job.
  • Swift format lint and local fork-diff coverage passed (1,543 changed files described; upstream merge-base validation remains with CI).
  • Independent correctness and refactor review completed with no blockers and no cleanup changes warranted; the existing ownership boundaries remain coherent.

This additive API is a request-ownership acknowledgement, not a native shutdown or physical-memory-release certificate. No release is published here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T22:45:51.616825Z ac5b135 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Gajesh2007
Gajesh2007 merged commit 5c2ff51 into main Oct 13, 2026
6 checks passed
@Gajesh2007
Gajesh2007 deleted the codex/ordinary-request-retirement branch October 13, 2026 22:51
jonathan308 added a commit that referenced this pull request Oct 14, 2026
Brings in #298 (quantized checkpoints with native inference) and #305
(ordinary request retirement) so the chain merges without conflicts.

One conflict, in PagedLayerCache.init: the chain resets the segment
dispatch statistics when the engine trace is on, and main registers the
cache in pool.quantizedAttentionCaches for quantized layers. The two are
independent; both are kept, trace reset first. Everything else merged
cleanly (PagedSegmentTransfers.swift auto-merged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
javiech1 pushed a commit to javiech1/mlx-swift-lm that referenced this pull request Oct 24, 2026
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