Skip to content

GLM prefix restore: a refused restore's release keeps the assistant charge on its stage - #471

Merged
jonathan308 merged 4 commits into
mainfrom
fix/stage-funded-mtp-binding-release
Nov 20, 2026
Merged

jonathan308 merged 4 commits into
mainfrom
fix/stage-funded-mtp-binding-release

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 20, 2026 •

Copy link
Copy Markdown

Proposed changes

A GLM-5.3-Flash request submitted with a first-token deadline prepares its complete-prefix restore before publication, including the MTP assistant binding that CBv2GLM5NextPreparedAssistant issues from the import proof. Until that import commits, the checkpoint stage holds the binding's charge (mtpPrepaid is part of the stage's auxiliary bytes); transferCheckpointStage moves it into the request only on a successful commit.

When publication is refused (for example, the process ledger refuses the transfer's growth), applyAdoption returns false and the deadline path calls discardDeadlineRejectedRequest, which calls AdmissionV2.releaseAll(id:). The request holds no tokens, but its binding still exists and its assistant state still holds MTP leases, so retireMTPBindingLocked returned resolved.bytes(forTokens: 0), a nonzero fixed MTP charge, as retained bytes. releaseAllLocked added those bytes to ledgerBytes, which makes the release a growth. publishProcessReductionLocked assumes a release never grows, so a ledger with no headroom refused it and preconditionFailure("process charge retirement refused") trapped. The prepared assistant abandons the binding only later, after the restore's native work is fenced on the engine queue, so the release always runs first.

Change: retireMTPBindingLocked now retires a binding whose import has not committed by deactivating its context only (retireStageFunded()), with zero retained bytes. The stage keeps the charge and refunds it when the native work retires. This covers releaseAll, unreserve to zero and detachReservation. Committed imports and ordinary bindings release as before.

Before

flowchart TD
  A[Deadline admission prepares GLM prefix restore] --> B[Imported MTP binding, stage-funded, leases live]
  B --> C[Publication refused]
  C --> D[discardDeadlineRejectedRequest]
  D --> E[releaseAll: retire binding with reservedTokens 0]
  E --> F[Ledger grows by the fixed MTP charge]
  F --> G{Process ledger has headroom?}
  G -- yes --> H[Charged twice until leases die]
  G -- no --> I[preconditionFailure: trap]
Loading

After

flowchart TD
  A[Deadline admission prepares GLM prefix restore] --> B[Imported MTP binding, stage-funded, leases live]
  B --> C[Publication refused]
  C --> D[discardDeadlineRejectedRequest]
  D --> E[releaseAll: import not committed, deactivate binding only]
  E --> F[No ledger change]
  F --> G[Native work retires: leases die, stage refunds its charge once]
Loading

Tests

  • New GLM5NextCompleteCheckpointTests.refusedNativeMTPPrefixAdoptionReleasesWithoutChargeGrowth (real tiny GLM target and MTP assistant, real paged pool, admission and complete-prefix store): a producer engine donates the checkpoint; the consumer stages it and submits under a first-token deadline. Once the restore is prepared, its process owner refuses the next growth, as a ledger under memory pressure would. The test requires that the request is not admitted and not adopted, that exactly one growth was refused, that no growth follows the refusal, that the charge drains back to its pre-stage baseline, and that there is no native completion fault.
  • Without the change, the release's growth is recorded, so the test fails without stopping the test process. The red control is Red control for #471: tests without the change (do not merge) #472.
  • The existing nativeMTPProfilesResumeFromCompletePrefixExactly now builds its engines through the shared nativeMTPEngine(store:process:verification:) helper (same configuration and checks).
  • Heads: fix 2b7021a9; red control c128a264.
  • Fork Tests on 2b7021a9: run 44788822386, all 12 shards green; the new test passes in shard 9.
  • Red control Red control for #471: tests without the change (do not merge) #472 on c128a264: run 44788833159, shard 9 fails only on gate.growthAfterRefusal.isEmpty ([7859348]: the fixed MTP charge grew after the refusal).

Validation

  • swift-format (Xcode 27.2) format and lint: clean on the changed files.
  • Local tests were not run; see Fork Tests on this PR.
  • Refactor pass: the engine helper defaults its process owner, the local wrapper is gone, comments are shorter. No behaviour change.
  • Follow-ups applied: the test requires the capacityExhausted rejection, waits for retirement and a quiescent shutdown, then checks that no growth followed the refusal.
  • Known and separate (pre-existing, not on this path): on the ordinary, non-deadline path a refused restore falls back to a cold prefill while its uncommitted assistant binding may still be mapped until the restore retires. A follow-up keeps cold issuance from reusing that context.

Checklist

  • I have read the CONTRIBUTING document
  • I have run swift-format on the changed files
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed): changelog.d/glm-refused-prefix-restore-release.md

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: written with Claude Opus 5.5. The attestation box above is left for the owner.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com


Merge note (2026-11-20): merged after CI green on this head 2b7021a9 (run 44788822386) and the red control #472. Provider dev pins the same four files on sdk/provider-0.10.16-glm-release-fix (995f3a5e) in Layr-Labs/d-inference#2436. The attestation box above is left for the owner.

A request admitted under a first-token deadline prepares its GLM complete-prefix
restore, including the MTP assistant binding, before publication. Until the
import commits, the checkpoint stage holds that binding's charge. When
publication is refused, the request's release retired the binding as if the
request held the charge and added it to the ledger as growth; a ledger with no
headroom refused that growth and the release trapped.

Retiring a binding whose import has not committed now only deactivates it. The
stage keeps the charge and refunds it when the restore's native work retires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 and others added 2 commits November 20, 2026 09:54
… growth check

The regression requires the capacityExhausted rejection, waits for the
retirement and a quiescent shutdown, then requires that no growth followed the
refusal. The engine helper defaults its process owner; comments are shorter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 merged commit 4bec0c2 into main Nov 20, 2026
29 checks passed
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