fix(leasehold): block unrent while a termination is pending - #29
Merged
Conversation
An eviction is a landlord-initiated termination, held on the contract as terminationEffectiveDate + terminatedByRole. The unrentRegion UPDATE cleared both alongside the tenant, and rentRegion had no termination guard, so an evicted tenant could /realty unrent (erasing the eviction and taking a pro-rata refund) and immediately re-rent on a fresh full-length lease -- unilaterally cancelling an eviction that /realty terminate cancel restricts to the initiating party. Guard unrent the way extend and modify are already guarded: a scheduled termination now yields UnrentResult.Terminating, so the lease can only end via the sweep on its effective date. The guard is applied both on the read in RealtyBackendImpl (for the message) and as a WHERE predicate on the UPDATE, since serializeByRegion only locks within a single server and a scheduleTermination from another could otherwise land between the two. This covers tenant-initiated terminations too, consistent with extend and modify; a tenant who scheduled their own can cancel it first, which an evicted tenant cannot. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An eviction is a landlord-initiated termination, held on the contract as terminationEffectiveDate + terminatedByRole. The unrentRegion UPDATE cleared both alongside the tenant, and rentRegion had no termination guard, so an evicted tenant could /realty unrent (erasing the eviction and taking a pro-rata refund) and immediately re-rent on a fresh full-length lease -- unilaterally cancelling an eviction that /realty terminate cancel restricts to the initiating party.
Guard unrent the way extend and modify are already guarded: a scheduled termination now yields UnrentResult.Terminating, so the lease can only end via the sweep on its effective date. The guard is applied both on the read in RealtyBackendImpl (for the message) and as a WHERE predicate on the UPDATE, since serializeByRegion only locks within a single server and a scheduleTermination from another could otherwise land between the two.
This covers tenant-initiated terminations too, consistent with extend and modify; a tenant who scheduled their own can cancel it first, which an evicted tenant cannot.