Flux Art — AI made simple, unleash your unlimited creativity
Multi-model AI visual creation and production platform · One account and workspace · Images, video, asset management and OpenAPI
Start Creating →
Flux Art › Blog › Guides › Fence Stale Writers …

Fence Stale Writers After a Lease Expires

Anonymous community contributor (alias): Star Bridge Tracing Paper Published: Category:Guides

A live process does not necessarily still have write authority

In a batch system integrated with Flux Art, a worker may resume after a pause and still hold an old task to write to the ledger. If its lease has expired and another process has taken over, the old process cannot overwrite the record just because it has not exited. The integrator implements the lease and write generation; these are not new platform features. The risk is not two windows open at once, but an executor that lost ownership still committing data.

Keep the lease, generation, and business task distinct

A lease answers who may work now and for how long; a write generation distinguishes executors that acquired ownership in sequence; task_id identifies the remote task. Do not collapse all three into one string. On takeover, a reliable coordination or storage mechanism should issue a new increasing generation and persist the current owner. A random lock token can identify an owner but does not automatically establish takeover order; an increasing value also needs a reliable way to generate and persist it.

Test a stale write after a pause

Suppose A holds generation seven and pauses until its lease expires; B lawfully obtains generation eight and updates the local record; A then wakes and submits a result with generation seven. This is a fault-injection scenario, not a measured result. The storage endpoint should reject A's stale write and preserve evidence of the rejection. Do not let A overwrite first and rely on B to repair it later, or treat “A usually exits in time” as a concurrency guarantee.

Failure inputWhat to reject or stopEvidence to verify
A write arrives with an old generationReject overwriting the current recordStorage-side conditional update result
Lease renewal failsStop claiming tasks and making new submissionsCurrent ownership and failure time
Two takeovers competeAccept only the lawful new ownerCoordination record and sole valid generation
Old process previously sent a creation requestProhibit blind recreationRequest record, idempotency key, and task query
Generation record rolls back or is tampered withReject resuming formal writesPersisted generation and trusted validation record
Remote outcome remains unknownKeep unresolved; do not mark completeIndependent check result and assigned owner

Check authority where the write actually commits

Checking a lock once when a process starts cannot protect a long network wait that follows. The final write must validate current ownership, generation, and any required lease conditions at the storage endpoint in the same atomic operation or transaction, then decide whether to accept it. If the generation is checked on the client and an unconditional write follows, ownership can change between the check and write. Without valid authority, reject the formal change rather than allowing an unknown state by default.

Stop new work when lease renewal fails

If renewal fails or ownership is uncertain, the old process should stop claiming new tasks and making new submissions, and leave unfinished work for recovery. Extending a local timer, continuing a loop, or checking only a process ID does not prove valid authority. Process IDs can be reused, and machine time is not the sole basis. Design the lease mechanism for the semantics of the chosen database or coordination service; do not assemble a simple substitute without atomicity.

Local fencing cannot block an external request already sent

A write generation protects local resources that validate it, but it cannot retract a creation request already sent remotely. The new owner still needs to check existing task_id values, request records, and unknown outcomes. Follow https://flux-art.net/en/openapi/reference for Flux Art creation-request idempotency constraints; when recovering the same request, reuse the corresponding idempotency key as documented instead of inventing a new business request merely because the worker changed.

Take over recovery with evidence

A takeover record should include the old owner, old generation, reason for expiry, new generation, takeover time, and unresolved steps. If a request may have been sent but its acknowledgement was lost, verify it independently; absence of local success does not mean the remote action did not happen. Keep items that cannot be verified unknown and prevent automatic repeated side effects. Recovery can advance steps known to be safe while keeping unknown steps in a separate queue; there is no need to fabricate completion.

Test storage rejection, not just lock acquisition

Isolated tests should cover an old process resuming after a pause, a tampered generation, failed lease validation, two competing takeovers, a generation that must not roll back after restart, and an unknown result for an existing external request. Assert that stale writes do not overwrite stored content, creation is not duplicated, and rejection reasons are traceable. Killing the old process is only a supplementary action, not the sole safeguard; before production integration, also validate real storage and coordinator failure behavior.

State clearly which capabilities are local and which are product capabilities

Redis's distributed-lock documentation at https://redis.io/docs/latest/develop/clients/patterns/distributed-locks/ advises considering fencing tokens for long-running work; it supports this design direction but does not mean any lock implementation is inherently safe. Flux Art's entry point at https://flux-art.net/en can be used for asset work, while the integrator remains responsible for scheduling, persistence, and handoff. At delivery, specify which resources validate generations and which external side effects require separate checks; do not present a passing test double as production adoption.

Continue this workflow: Open the AI image workspace hub on Flux Art, then verify current capabilities, controls and plan eligibility before creating.

Open the AI image workspace →

Frequently Asked Questions

Q: Why check the write generation if there is a lease?

A: An old process may resume after its lease expires. Generation validation lets compatible storage reject stale executors, but it must be implemented correctly together with current ownership and other conditions.

Q: Can a random token tell which writer is newer?

A: A random token can identify an owner but does not inherently represent takeover order. If the design depends on ordering, generate and persist the value reliably and have the target resource validate it.

Q: Is checking the lock before every write enough?

A: If checking the lock and writing are separate actions, a takeover can happen in between. The critical check must be atomic with the actual storage change.

Q: Is killing the old process enough to make this safe?

A: Do not rely on that alone. Network isolation, pauses, or an unsuccessful termination can leave a process able to resume; storage-side rejection of stale writes is a necessary defense.

Q: Can a new process retry with a different idempotency key?

A: Do not change the key just because ownership changed. First verify the original business request and remote outcome, then recover the same request according to the API documentation.

Q: Can a generation cancel a remote task?

A: No. It constrains only resources that actually validate it; it cannot retract a request already sent remotely and is not a platform cancellation interface.

Q: Should an unknown outcome be recorded as failure?

A: No. Failure and unknown outcome differ. Preserve evidence and verify the latter to avoid accidental recreation or incorrect notifications.

Q: Can an isolated test passing justify production use?

A: Not by itself. Verify integration with the real storage, coordination service, and remote-state observation; a test double's result is not a production guarantee.