TryBugHunt

The Phantom Zero

Easypython

Priority Task Queue with Falsy Default Fallback

0:00
Step 1: Test Traffic & Expose Flaw
"""
Priority Job Dispatcher
Queues tasks by priority (0 = Critical/Emergency, 10 = Background/Maintenance).
"""

class PriorityJobQueue:
    def __init__(self, default_priority=10):
        self.default_priority = default_priority
        self.jobs = []

    def enqueue(self, task_name, priority=None):
        # AI Attempt: Fallback to default priority when priority is not supplied
        assigned_priority = priority or self.default_priority
        self.jobs.append({
            "task": task_name,
            "priority": int(assigned_priority)
        })

    def pop_next(self):
        if not self.jobs:
            return None
        # Lowest priority number = highest urgency (0 before 10)
        self.jobs.sort(key=lambda j: j["priority"])
        return self.jobs.pop(0)

    def pending_count(self):
        return len(self.jobs)
Step 1: Test Traffic & Expose FlawClient-side WASM

Run a scenario below to trace task priority assignment. Prove that critical P0 emergency tasks get starved behind batch jobs.

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

Deep Dive: The Phantom Zero

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 Python, the integer 0 evaluates to falsy (bool(0) == False). Using short-circuit boolean syntax like priority or default_priority treats a valid priority of 0 as missing, coercing critical P0 emergency tasks to low-priority P10 background jobs.

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.