TryBugHunt

AI Attempt: Stalled worker overwrites database after lock expires

Hardpython

Distributed Lease Manager Missing Monotonic Fencing Token Verification

0:00
Step 1: Test Traffic & Expose Flaw
"""
Virtual Clock Provider
Provides monotonic time for testing distributed timeouts and pauses.
"""

class VirtualClock:
    def __init__(self, start_time=1000.0):
        self.current_time = float(start_time)

    def now(self):
        return self.current_time

    def advance(self, seconds):
        self.current_time += float(seconds)
        return self.current_time
Step 1: Test Traffic & Expose FlawClient-side WASM

Run a scenario below to trace distributed worker execution. Prove that a stalled worker overwrites newer data after its lease has expired.

Choose Traffic Scenario to TestClick to simulate
Architectural Guide & Interview Notes

Deep Dive: AI Attempt: Stalled worker overwrites database after lock expires

An engineering analysis of why this AI-generated Pull Request passed isolated unit tests, how multi-tenant traffic exposes the architectural flaw, and how interviewers score your response.

The Root Cause Anti-Pattern

In distributed lock algorithms, lease timeouts cannot guarantee safety across network delays or garbage collection pauses without monotonic fencing tokens. Authorizing storage writes by reading a shared mutable instance attribute (like self.current_fence) instead of the worker's individually acquired lease token allows a stalled worker to commit under a newer worker's watermark, silently overwriting fresh data with stale output.

The Interviewer's Scoring Rubric

Candidates are assessed on whether they jump to trial-and-error editing or follow a hypothesis-driven approach. A "Strong Hire" candidate restates the data flow between modules, explains why single-client unit tests passed, crafts an adversarial probe showing cross-tenant leakage, and implements a surgical 1-line patch without breaking existing contracts.

Candidate Strategy for the Code Comprehension Round

  1. 1Map Module ContractsTrace how the gateway invokes the underlying service. Note what data is passed by reference vs. by value.
  2. 2Break It With An Adversarial ProbeSimulate concurrent or sequential traffic across multiple identities to force shared state mutation.
  3. 3Deliver a Surgical PatchMake the minimal required diff to ensure proper per-client state isolation without refactoring unnecessary files.