111 lines
42 KiB
JSON
111 lines
42 KiB
JSON
{
|
|
"run_id": "20260831T121823Z",
|
|
"created_at": "2026-08-31T12:18:23.136973+00:00",
|
|
"runtime": {
|
|
"name": "vllm-metal",
|
|
"kind": "openai",
|
|
"base_url": "http://127.0.0.1:8001",
|
|
"model": "qwen3.8-27b-nvfp4"
|
|
},
|
|
"host": {
|
|
"platform": "macOS-15.6-arm64-arm-64bit",
|
|
"machine": "arm64",
|
|
"python": "3.12.8"
|
|
},
|
|
"package_versions": {
|
|
"vllm": "0.28.0+cpu",
|
|
"vllm-metal": "0.4.0.dev20260831112704",
|
|
"mlx": "0.32.0",
|
|
"mlx-lm": "0.31.3",
|
|
"mlx-vlm": "0.6.4"
|
|
},
|
|
"settings": {
|
|
"temperature": 0,
|
|
"seed": 42,
|
|
"max_tokens": 3072,
|
|
"context_tokens": 8192,
|
|
"raw_completion": false,
|
|
"chat_template": true,
|
|
"thinking": false,
|
|
"ollama_speculative_drafting": false
|
|
},
|
|
"warmup": {
|
|
"task": "warmup",
|
|
"runtime": "vllm-metal",
|
|
"model": "qwen3.8-27b-nvfp4",
|
|
"started_at": "2026-08-31T12:10:51.048391+00:00",
|
|
"prompt_chars": 27,
|
|
"max_tokens": 8,
|
|
"ttft_s": 0.38219533301889896,
|
|
"total_s": 0.41809329099487513,
|
|
"prompt_tokens": 41,
|
|
"output_tokens": 2,
|
|
"decode_tps": 55.71347543886622,
|
|
"finish_reason": "stop",
|
|
"output_chars": 5,
|
|
"output_sha256": "c2e3ac47f4a325469c1a2d5f117e463ec943c721986d5d9f09ac4540b7d80526",
|
|
"output": "READY",
|
|
"error": null
|
|
},
|
|
"tasks": {
|
|
"python_async_cache": "Act as a senior Python engineer. Implement a production-ready, single-file Python 3.12 module\ncontaining a generic AsyncTTLCache[K, V]. Requirements: weighted LRU capacity; per-entry TTL based\non time.monotonic; single-flight get_or_create so concurrent misses for one key invoke the async\nfactory exactly once; cancellation of one waiter must not cancel the shared factory; exceptions are\nnever cached; invalidating a key while its factory is running must prevent stale publication; never\nhold the cache lock while awaiting user code; clear(), invalidate(), and immutable hit/miss/eviction\nstatistics. Include concise pytest-asyncio tests covering races, cancellation, expiry, weighted\ncapacity, factory failure, and invalidation during creation. Use only the standard library plus\npytest. Output only the complete module, without Markdown fences or prose.",
|
|
"php_idempotent_transfer": "Act as a senior Laravel 12 engineer. Produce one self-contained PHP file that demonstrates an\nidempotent money-transfer service and its PHPUnit tests. Store money as integer cents. Requirements:\nvalidate positive amount and distinct accounts; use a database transaction; lock both account rows\nin deterministic ID order; reject insufficient funds; use a unique client idempotency key so retries\nreturn the original transfer; retry deadlocks without duplicating effects; persist an outbox event\nin the same transaction; and prove with tests that duplicate and competing requests preserve\nbalances, create one transfer, and create one outbox event. Include minimal model/table assumptions\nas comments.\nOutput only valid PHP, without Markdown fences or prose.",
|
|
"typescript_dag_scheduler": "Act as a senior TypeScript engineer. Implement a strict-mode, dependency-free DAG task scheduler in\none TypeScript file. Each task has an ID, dependency IDs, and an async run(signal) function.\nRequirements: validate unknown dependencies and duplicate IDs; report an explicit cycle path; stable\ninput-order scheduling; configurable maximum concurrency; AbortSignal support; fail fast after the\nfirst error while awaiting already-running tasks; never start dependents of failed tasks; return a\nMap of typed results on success; and avoid unhandled promise rejections. Include a compact test\nharness covering a diamond graph, concurrency enforcement, stable order, cycle detection, external\ncancellation, and rejection. Output only TypeScript, without Markdown fences or prose."
|
|
},
|
|
"results": [
|
|
{
|
|
"task": "python_async_cache",
|
|
"runtime": "vllm-metal",
|
|
"model": "qwen3.8-27b-nvfp4",
|
|
"started_at": "2026-08-31T12:10:51.466896+00:00",
|
|
"prompt_chars": 857,
|
|
"max_tokens": 3072,
|
|
"ttft_s": 1.0361592500121333,
|
|
"total_s": 133.43742824997753,
|
|
"prompt_tokens": 211,
|
|
"output_tokens": 3072,
|
|
"decode_tps": 23.20219453486358,
|
|
"finish_reason": "length",
|
|
"output_chars": 14058,
|
|
"output_sha256": "a18e80f1852ecc0c70b987f244870b8a2dc20db8ad42505280162a4b17dbd057",
|
|
"output": "from __future__ import annotations\n\nimport asyncio\nimport time\nfrom dataclasses import dataclass, field\nfrom typing import (\n Any,\n Awaitable,\n Callable,\n Generic,\n Hashable,\n Optional,\n TypeVar,\n)\n\nK = TypeVar(\"K\", bound=Hashable)\nV = TypeVar(\"V\")\n\n\n@dataclass(frozen=True)\nclass CacheStats:\n hits: int\n misses: int\n evictions: int\n\n\n@dataclass\nclass _Entry:\n value: V\n expires_at: float\n weight: int\n last_access: float\n\n\nclass _Inflight:\n __slots__ = (\"task\", \"cancelled\")\n\n def __init__(self, task: \"asyncio.Task[V]\") -> None:\n self.task = task\n self.cancelled = False\n\n\nclass AsyncTTLCache(Generic[K, V]):\n \"\"\"\n A generic async TTL cache with weighted LRU eviction, per-entry TTL,\n single-flight get_or_create, and safe cancellation semantics.\n\n - Weighted LRU: each entry has a weight; total weight <= capacity.\n - TTL: per-entry expiration based on time.monotonic.\n - Single-flight: concurrent get_or_create for the same key share one factory call.\n - Cancellation: cancelling one waiter does not cancel the shared factory.\n - Exceptions are never cached.\n - Invalidation during creation prevents stale publication.\n - The cache lock is never held while awaiting user code.\n \"\"\"\n\n def __init__(\n self,\n capacity: int,\n default_ttl: float,\n *,\n weight_fn: Optional[Callable[[V], int]] = None,\n ) -> None:\n if capacity <= 0:\n raise ValueError(\"capacity must be positive\")\n if default_ttl <= 0:\n raise ValueError(\"default_ttl must be positive\")\n\n self._capacity = capacity\n self._default_ttl = default_ttl\n self._weight_fn = weight_fn or (lambda _v: 1)\n\n # LRU order: most recently used at front (index 0)\n self._entries: dict[K, _Entry] = {}\n self._lru_order: list[K] = [] # index 0 = MRU, last = LRU\n self._total_weight: int = 0\n\n # Single-flight tracking\n self._inflight: dict[K, _Inflight] = {}\n\n # Statistics\n self._hits: int = 0\n self._misses: int = 0\n self._evictions: int = 0\n\n self._lock = asyncio.Lock()\n\n @property\n def stats(self) -> CacheStats:\n return CacheStats(\n hits=self._hits,\n misses=self._misses,\n evictions=self._evictions,\n )\n\n def clear(self) -> None:\n \"\"\"Clear all entries and cancel any in-flight factories.\"\"\"\n self._entries.clear()\n self._lru_order.clear()\n self._total_weight = 0\n for key in list(self._inflight.keys()):\n inflight = self._inflight.pop(key)\n if not inflight.task.done():\n inflight.cancelled = True\n inflight.task.cancel()\n\n def invalidate(self, key: K) -> None:\n \"\"\"\n Invalidate a key. If a factory is in-flight for this key,\n mark it as cancelled so its result is not published.\n \"\"\"\n self._entries.pop(key, None)\n if key in self._lru_order:\n self._lru_order.remove(key)\n # Adjust weight\n entry = self._entries.get(key)\n if entry is None and key in self._lru_order:\n pass # already removed\n # Recompute weight if entry was removed\n # Actually we need to track weight separately\n # Let's restructure: store weight in entry and recompute on removal\n # For simplicity, we track _total_weight and adjust on removal\n # But we already popped from _entries, so we need the weight before popping.\n # Let's fix: get weight before popping.\n # Actually, let's restructure invalidate to handle weight properly.\n # We'll fix this in the implementation below.\n\n inflight = self._inflight.get(key)\n if inflight is not None:\n inflight.cancelled = True\n if not inflight.task.done():\n inflight.task.cancel()\n\n def _remove_key(self, key: K) -> None:\n \"\"\"Remove a key from entries and LRU order, adjusting total weight.\"\"\"\n entry = self._entries.pop(key, None)\n if entry is not None:\n self._total_weight -= entry.weight\n if key in self._lru_order:\n self._lru_order.remove(key)\n\n def invalidate(self, key: K) -> None: # noqa: F811\n \"\"\"\n Invalidate a key. If a factory is in-flight for this key,\n mark it as cancelled so its result is not published.\n \"\"\"\n self._remove_key(key)\n inflight = self._inflight.get(key)\n if inflight is not None:\n inflight.cancelled = True\n if not inflight.task.done():\n inflight.task.cancel()\n\n def _evict_lru(self, needed_weight: int) -> None:\n \"\"\"Evict LRU entries until total_weight + needed_weight <= capacity.\"\"\"\n while self._total_weight + needed_weight > self._capacity:\n if not self._lru_order:\n break\n lru_key = self._lru_order[-1]\n entry = self._entries.get(lru_key)\n if entry is None:\n self._lru_order.pop()\n continue\n self._remove_key(lru_key)\n self._evictions += 1\n\n def _touch(self, key: K) -> None:\n \"\"\"Move key to MRU position.\"\"\"\n if key in self._lru_order:\n self._lru_order.remove(key)\n self._lru_order.insert(0, key)\n\n async def get(self, key: K) -> Optional[V]:\n \"\"\"\n Get a value from the cache. Returns None if not present or expired.\n Does not trigger factory creation.\n \"\"\"\n async with self._lock:\n entry = self._entries.get(key)\n if entry is None:\n self._misses += 1\n return None\n now = time.monotonic()\n if now >= entry.expires_at:\n # Expired\n self._remove_key(key)\n self._misses += 1\n return None\n # Hit\n self._hits += 1\n entry.last_access = now\n self._touch(key)\n return entry.value\n\n async def get_or_create(\n self,\n key: K,\n factory: Callable[[], Awaitable[V]],\n *,\n ttl: Optional[float] = None,\n weight: Optional[int] = None,\n ) -> V:\n \"\"\"\n Get a value from the cache, or create it using the async factory.\n Single-flight: concurrent calls for the same key share one factory invocation.\n Exceptions from the factory are never cached.\n \"\"\"\n effective_ttl = ttl if ttl is not None else self._default_ttl\n if effective_ttl <= 0:\n raise ValueError(\"ttl must be positive\")\n\n # First, check if we already have a valid entry\n async with self._lock:\n entry = self._entries.get(key)\n if entry is not None:\n now = time.monotonic()\n if now < entry.expires_at:\n self._hits += 1\n entry.last_access = now\n self._touch(key)\n return entry.value\n else:\n # Expired, remove it\n self._remove_key(key)\n self._misses += 1\n\n # Check if there's an in-flight factory\n inflight = self._inflight.get(key)\n if inflight is not None and not inflight.cancelled:\n # Wait for the existing factory\n pass # We'll wait outside the lock\n else:\n # No valid entry and no active in-flight (or it was cancelled)\n # We need to start a new factory\n self._misses += 1\n # Create the task outside the lock\n task = asyncio.ensure_future(factory())\n inflight = _Inflight(task)\n self._inflight[key] = inflight\n # Release lock, then await\n # We need to break out of the lock context\n # Let's restructure: use a flag\n break_out = True\n else:\n break_out = False\n\n # If we found an existing in-flight, wait for it\n if not break_out:\n assert inflight is not None\n try:\n value = await inflight.task\n except asyncio.CancelledError:\n # Our task was cancelled, but the shared factory may still be running\n # We should not propagate cancellation to the factory\n # Re-raise to indicate our caller was cancelled\n raise\n except Exception:\n # Factory failed; do not cache\n self._inflight.pop(key, None)\n raise\n else:\n # Factory succeeded\n self._inflight.pop(key, None)\n # Check if it was invalidated during creation\n if inflight.cancelled:\n # Do not publish\n return await self.get_or_create(\n key, factory, ttl=ttl, weight=weight\n )\n # Publish the result\n async with self._lock:\n # Re-check: maybe another task already published\n existing = self._entries.get(key)\n if existing is not None:\n now = time.monotonic()\n if now < existing.expires_at:\n self._hits += 1\n existing.last_access = now\n self._touch(key)\n return existing.value\n else:\n self._remove_key(key)\n\n # Check if invalidated\n if inflight.cancelled:\n # Do not publish\n pass\n else:\n # Insert into cache\n effective_weight = weight if weight is not None else self._weight_fn(value)\n if effective_weight <= 0:\n raise ValueError(\"weight must be positive\")\n if effective_weight > self._capacity:\n raise ValueError(\n f\"weight {effective_weight} exceeds capacity {self._capacity}\"\n )\n\n now = time.monotonic()\n new_entry = _Entry(\n value=value,\n expires_at=now + effective_ttl,\n weight=effective_weight,\n last_access=now,\n )\n self._evict_lru(effective_weight)\n self._entries[key] = new_entry\n self._lru_order.insert(0, key)\n self._total_weight += effective_weight\n return value\n # If invalidated, fall through to retry\n return await self.get_or_create(key, factory, ttl=ttl, weight=weight)\n\n # We need to start a new factory\n assert inflight is not None\n try:\n value = await inflight.task\n except asyncio.CancelledError:\n # Our task was cancelled\n # The shared factory may still be running\n # Do not cancel the shared factory\n raise\n except Exception:\n # Factory failed; do not cache\n async with self._lock:\n self._inflight.pop(key, None)\n raise\n else:\n # Factory succeeded\n async with self._lock:\n self._inflight.pop(key, None)\n # Check if it was invalidated during creation\n if inflight.cancelled:\n # Do not publish; retry\n return await self.get_or_create(key, factory, ttl=ttl, weight=weight)\n # Publish the result\n async with self._lock:\n # Re-check: maybe another task already published\n existing = self._entries.get(key)\n if existing is not None:\n now = time.monotonic()\n if now < existing.expires_at:\n self._hits += 1\n existing.last_access = now\n self._touch(key)\n return existing.value\n else:\n self._remove_key(key)\n\n # Check if invalidated\n if inflight.cancelled:\n pass\n else:\n # Insert into cache\n effective_weight = weight if weight is not None else self._weight_fn(value)\n if effective_weight <= 0:\n raise ValueError(\"weight must be positive\")\n if effective_weight > self._capacity:\n raise ValueError(\n f\"weight {effective_weight} exceeds capacity {self._capacity}\"\n )\n\n now = time.monotonic()\n new_entry = _Entry(\n value=value,\n expires_at=now + effective_ttl,\n weight=effective_weight,\n last_access=now,\n )\n self._evict_lru(effective_weight)\n self._entries[key] = new_entry\n self._lru_order.insert(0, key)\n self._total_weight += effective_weight\n return value\n # If invalidated, fall through to retry\n return await self.get_or_create(key, factory, ttl=ttl, weight=weight)\n\n async def set(\n self,\n key: K,\n value: V,\n *,\n ttl: Optional[float] = None,\n weight: Optional[int] = None,\n ) -> None:\n \"\"\"\n Set a value in the cache. Evicts LRU entries if needed",
|
|
"error": null
|
|
},
|
|
{
|
|
"task": "php_idempotent_transfer",
|
|
"runtime": "vllm-metal",
|
|
"model": "qwen3.8-27b-nvfp4",
|
|
"started_at": "2026-08-31T12:13:04.907109+00:00",
|
|
"prompt_chars": 756,
|
|
"max_tokens": 3072,
|
|
"ttft_s": 15.930970875022467,
|
|
"total_s": 166.00547937501688,
|
|
"prompt_tokens": 182,
|
|
"output_tokens": 2840,
|
|
"decode_tps": 18.923933374068692,
|
|
"finish_reason": "stop",
|
|
"output_chars": 11403,
|
|
"output_sha256": "bb758808663b88bb3fbacc52df49598eb21aa8bc7fa0ee8466410f0ae13e8b0d",
|
|
"output": "<?php\n\ndeclare(strict_types=1);\n\nuse Illuminate\\Support\\Facades\\DB;\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Artisan;\nuse PHPUnit\\Framework\\TestCase;\n\n// Minimal model/table assumptions:\n// - accounts table: id (bigint unsigned PK), balance_cents (bigint unsigned)\n// - transfers table: id (bigint unsigned PK), idempotency_key (string unique), from_account_id (bigint unsigned), to_account_id (bigint unsigned), amount_cents (bigint unsigned), created_at (timestamp)\n// - outbox_events table: id (bigint unsigned PK), transfer_id (bigint unsigned), event_type (string), payload (json), created_at (timestamp)\n\nclass MoneyTransferService\n{\n public function transfer(string $idempotencyKey, int $fromAccountId, int $toAccountId, int $amountCents): array\n {\n // Validate positive amount\n if ($amountCents <= 0) {\n throw new InvalidArgumentException('Amount must be positive.');\n }\n\n // Validate distinct accounts\n if ($fromAccountId === $toAccountId) {\n throw new InvalidArgumentException('Source and destination accounts must be distinct.');\n }\n\n // Check if transfer already exists (idempotency)\n $existingTransfer = DB::table('transfers')\n ->where('idempotency_key', $idempotencyKey)\n ->first();\n\n if ($existingTransfer) {\n return [\n 'transfer_id' => $existingTransfer->id,\n 'idempotency_key' => $existingTransfer->idempotency_key,\n 'from_account_id' => $existingTransfer->from_account_id,\n 'to_account_id' => $existingTransfer->to_account_id,\n 'amount_cents' => $existingTransfer->amount_cents,\n 'status' => 'duplicate',\n ];\n }\n\n // Retry loop for deadlocks\n $maxRetries = 5;\n $attempt = 0;\n\n while (true) {\n $attempt++;\n try {\n $result = DB::transaction(function () use ($idempotencyKey, $fromAccountId, $toAccountId, $amountCents) {\n // Lock both account rows in deterministic ID order\n $minId = min($fromAccountId, $toAccountId);\n $maxId = max($fromAccountId, $toAccountId);\n\n $accounts = DB::table('accounts')\n ->whereIn('id', [$minId, $maxId])\n ->orderBy('id')\n ->lockForUpdate()\n ->get();\n\n if ($accounts->count() !== 2) {\n throw new RuntimeException('One or both accounts do not exist.');\n }\n\n $fromAccount = $accounts->firstWhere('id', $fromAccountId);\n $toAccount = $accounts->firstWhere('id', $toAccountId);\n\n // Reject insufficient funds\n if ($fromAccount->balance_cents < $amountCents) {\n throw new RuntimeException('Insufficient funds.');\n }\n\n // Perform transfer\n DB::table('accounts')\n ->where('id', $fromAccountId)\n ->decrement('balance_cents', $amountCents);\n\n DB::table('accounts')\n ->where('id', $toAccountId)\n ->increment('balance_cents', $amountCents);\n\n // Insert transfer\n $transferId = DB::table('transfers')->insertGetId([\n 'idempotency_key' => $idempotencyKey,\n 'from_account_id' => $fromAccountId,\n 'to_account_id' => $toAccountId,\n 'amount_cents' => $amountCents,\n 'created_at' => now(),\n ]);\n\n // Persist outbox event in the same transaction\n DB::table('outbox_events')->insert([\n 'transfer_id' => $transferId,\n 'event_type' => 'transfer.completed',\n 'payload' => json_encode([\n 'transfer_id' => $transferId,\n 'from_account_id' => $fromAccountId,\n 'to_account_id' => $toAccountId,\n 'amount_cents' => $amountCents,\n ]),\n 'created_at' => now(),\n ]);\n\n return [\n 'transfer_id' => $transferId,\n 'idempotency_key' => $idempotencyKey,\n 'from_account_id' => $fromAccountId,\n 'to_account_id' => $toAccountId,\n 'amount_cents' => $amountCents,\n 'status' => 'created',\n ];\n });\n\n return $result;\n\n } catch (Illuminate\\Database\\QueryException $e) {\n // Detect deadlock (MySQL error 1213)\n if ($e->getCode() === 1213 || str_contains($e->getMessage(), 'Deadlock')) {\n if ($attempt >= $maxRetries) {\n throw new RuntimeException('Transfer failed after maximum retries due to deadlock.', 0, $e);\n }\n usleep(100000 * $attempt); // Exponential backoff\n continue;\n }\n throw $e;\n }\n }\n }\n}\n\nclass MoneyTransferServiceTest extends TestCase\n{\n private MoneyTransferService $service;\n\n protected function setUp(): void\n {\n parent::setUp();\n\n // Create test database schema\n Schema::dropIfExists('accounts');\n Schema::dropIfExists('transfers');\n Schema::dropIfExists('outbox_events');\n\n Schema::create('accounts', function (Blueprint $table) {\n $table->id();\n $table->unsignedBigInteger('balance_cents')->default(0);\n });\n\n Schema::create('transfers', function (Blueprint $table) {\n $table->id();\n $table->string('idempotency_key')->unique();\n $table->unsignedBigInteger('from_account_id');\n $table->unsignedBigInteger('to_account_id');\n $table->unsignedBigInteger('amount_cents');\n $table->timestamp('created_at');\n });\n\n Schema::create('outbox_events', function (Blueprint $table) {\n $table->id();\n $table->unsignedBigInteger('transfer_id');\n $table->string('event_type');\n $table->json('payload');\n $table->timestamp('created_at');\n });\n\n $this->service = new MoneyTransferService();\n }\n\n public function test_transfer_moves_funds_correctly(): void\n {\n // Setup: Account 1 has 10000 cents, Account 2 has 0 cents\n DB::table('accounts')->insert([\n ['id' => 1, 'balance_cents' => 10000],\n ['id' => 2, 'balance_cents' => 0],\n ]);\n\n $result = $this->service->transfer('key-1', 1, 2, 5000);\n\n $this->assertSame('created', $result['status']);\n $this->assertSame(5000, $result['amount_cents']);\n\n $account1 = DB::table('accounts')->where('id', 1)->first();\n $account2 = DB::table('accounts')->where('id', 2)->first();\n\n $this->assertSame(5000, $account1->balance_cents);\n $this->assertSame(5000, $account2->balance_cents);\n\n $transferCount = DB::table('transfers')->count();\n $this->assertSame(1, $transferCount);\n\n $outboxCount = DB::table('outbox_events')->count();\n $this->assertSame(1, $outboxCount);\n }\n\n public function test_duplicate_request_returns_original_transfer(): void\n {\n // Setup: Account 1 has 10000 cents, Account 2 has 0 cents\n DB::table('accounts')->insert([\n ['id' => 1, 'balance_cents' => 10000],\n ['id' => 2, 'balance_cents' => 0],\n ]);\n\n $firstResult = $this->service->transfer('key-dup', 1, 2, 3000);\n $this->assertSame('created', $firstResult['status']);\n\n $secondResult = $this->service->transfer('key-dup', 1, 2, 3000);\n $this->assertSame('duplicate', $secondResult['status']);\n $this->assertSame($firstResult['transfer_id'], $secondResult['transfer_id']);\n\n // Balances should only reflect one transfer\n $account1 = DB::table('accounts')->where('id', 1)->first();\n $account2 = DB::table('accounts')->where('id', 2)->first();\n\n $this->assertSame(7000, $account1->balance_cents);\n $this->assertSame(3000, $account2->balance_cents);\n\n $transferCount = DB::table('transfers')->count();\n $this->assertSame(1, $transferCount);\n\n $outboxCount = DB::table('outbox_events')->count();\n $this->assertSame(1, $outboxCount);\n }\n\n public function test_competing_requests_preserve_balances_and_create_one_transfer(): void\n {\n // Setup: Account 1 has 10000 cents, Account 2 has 0 cents\n DB::table('accounts')->insert([\n ['id' => 1, 'balance_cents' => 10000],\n ['id' => 2, 'balance_cents' => 0],\n ]);\n\n // Simulate competing requests with same idempotency key\n $results = [];\n for ($i = 0; $i < 5; $i++) {\n $results[] = $this->service->transfer('key-compete', 1, 2, 2000);\n }\n\n // All should return the same transfer ID\n $transferIds = array_unique(array_column($results, 'transfer_id'));\n $this->assertCount(1, $transferIds);\n\n // Only one transfer should be created\n $transferCount = DB::table('transfers')->count();\n $this->assertSame(1, $transferCount);\n\n // Only one outbox event\n $outboxCount = DB::table('outbox_events')->count();\n $this->assertSame(1, $outboxCount);\n\n // Balances should reflect only one transfer of 2000\n $account1 = DB::table('accounts')->where('id', 1)->first();\n $account2 = DB::table('accounts')->where('id', 2)->first();\n\n $this->assertSame(8000, $account1->balance_cents);\n $this->assertSame(2000, $account2->balance_cents);\n }\n\n public function test_rejects_insufficient_funds(): void\n {\n DB::table('accounts')->insert([\n ['id' => 1, 'balance_cents' => 1000],\n ['id' => 2, 'balance_cents' => 0],\n ]);\n\n $this->expectException(RuntimeException::class);\n $this->expectExceptionMessage('Insufficient funds.');\n\n $this->service->transfer('key-insufficient', 1, 2, 5000);\n }\n\n public function test_rejects_non_positive_amount(): void\n {\n DB::table('accounts')->insert([\n ['id' => 1, 'balance_cents' => 10000],\n ['id' => 2, 'balance_cents' => 0],\n ]);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Amount must be positive.');\n\n $this->service->transfer('key-zero', 1, 2, 0);\n }\n\n public function test_rejects_same_account(): void\n {\n DB::table('accounts')->insert([\n ['id' => 1, 'balance_cents' => 10000],\n ]);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Source and destination accounts must be distinct.');\n\n $this->service->transfer('key-same', 1, 1, 1000);\n }\n}",
|
|
"error": null
|
|
},
|
|
{
|
|
"task": "typescript_dag_scheduler",
|
|
"runtime": "vllm-metal",
|
|
"model": "qwen3.8-27b-nvfp4",
|
|
"started_at": "2026-08-31T12:15:50.913910+00:00",
|
|
"prompt_chars": 773,
|
|
"max_tokens": 3072,
|
|
"ttft_s": 1.4814700839924626,
|
|
"total_s": 152.22010587499244,
|
|
"prompt_tokens": 183,
|
|
"output_tokens": 3072,
|
|
"decode_tps": 20.379645761550783,
|
|
"finish_reason": "length",
|
|
"output_chars": 10869,
|
|
"output_sha256": "f700d51c471a59acfcf85016d416f0c5354662552fea44b48f56d80c3afdcb59",
|
|
"output": "type TaskResult<T> = { ok: true; value: T } | { ok: false; error: unknown };\n\ninterface Task<T> {\n id: string;\n deps: readonly string[];\n run: (signal: AbortSignal) => Promise<T>;\n}\n\ninterface SchedulerOptions {\n maxConcurrency?: number;\n signal?: AbortSignal;\n}\n\nclass SchedulerError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SchedulerError\";\n }\n}\n\nclass CycleError extends SchedulerError {\n readonly path: readonly string[];\n constructor(path: readonly string[]) {\n super(`Dependency cycle detected: ${path.join(\" -> \")}`);\n this.name = \"CycleError\";\n this.path = path;\n }\n}\n\nclass DuplicateIdError extends SchedulerError {\n constructor(id: string) {\n super(`Duplicate task ID: ${id}`);\n this.name = \"DuplicateIdError\";\n }\n}\n\nclass UnknownDependencyError extends SchedulerError {\n constructor(taskId: string, depId: string) {\n super(`Task \"${taskId}\" depends on unknown task \"${depId}\"`);\n this.name = \"UnknownDependencyError\";\n }\n}\n\nclass CancellationError extends SchedulerError {\n constructor() {\n super(\"Scheduler aborted\");\n this.name = \"CancellationError\";\n }\n}\n\nclass TaskFailureError extends SchedulerError {\n readonly taskId: string;\n readonly cause: unknown;\n constructor(taskId: string, cause: unknown) {\n super(`Task \"${taskId}\" failed`);\n this.name = \"TaskFailureError\";\n this.taskId = taskId;\n this.cause = cause;\n }\n}\n\nfunction isAbortSignal(value: unknown): value is AbortSignal {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"aborted\" in value &&\n \"addEventListener\" in value &&\n \"removeEventListener\" in value\n );\n}\n\nfunction createCombinedSignal(external: AbortSignal | undefined): {\n signal: AbortSignal;\n cancel: () => void;\n} {\n const controller = new AbortController();\n const onExternalAbort = () => controller.abort(external?.reason);\n if (external) {\n if (external.aborted) {\n controller.abort(external.reason);\n } else {\n external.addEventListener(\"abort\", onExternalAbort, { once: true });\n }\n }\n const cancel = () => {\n if (external) {\n external.removeEventListener(\"abort\", onExternalAbort);\n }\n if (!controller.signal.aborted) {\n controller.abort(new CancellationError());\n }\n };\n return { signal: controller.signal, cancel };\n}\n\nfunction topologicalOrder<T>(\n tasks: readonly Task<T>[],\n idToTask: Map<string, Task<T>>\n): string[] {\n const inDegree = new Map<string, number>();\n const dependents = new Map<string, string[]>();\n\n for (const task of tasks) {\n inDegree.set(task.id, 0);\n dependents.set(task.id, []);\n }\n\n for (const task of tasks) {\n for (const dep of task.deps) {\n inDegree.set(task.id, (inDegree.get(task.id) ?? 0) + 1);\n const list = dependents.get(dep);\n if (list) {\n list.push(task.id);\n }\n }\n }\n\n const queue: string[] = [];\n for (const task of tasks) {\n if ((inDegree.get(task.id) ?? 0) === 0) {\n queue.push(task.id);\n }\n }\n\n const order: string[] = [];\n let head = 0;\n while (head < queue.length) {\n const id = queue[head++];\n order.push(id);\n const next = dependents.get(id) ?? [];\n for (const dependent of next) {\n const remaining = (inDegree.get(dependent) ?? 0) - 1;\n inDegree.set(dependent, remaining);\n if (remaining === 0) {\n queue.push(dependent);\n }\n }\n }\n\n if (order.length !== tasks.length) {\n const visited = new Set<string>();\n const inStack = new Set<string>();\n const path: string[] = [];\n let cyclePath: string[] | undefined;\n\n const dfs = (id: string): void => {\n if (cyclePath !== undefined) return;\n if (inStack.has(id)) {\n const start = path.indexOf(id);\n cyclePath = [...path.slice(start), id];\n return;\n }\n if (visited.has(id)) return;\n visited.add(id);\n inStack.add(id);\n path.push(id);\n const task = idToTask.get(id);\n if (task) {\n for (const dep of task.deps) {\n if (idToTask.has(dep)) {\n dfs(dep);\n if (cyclePath !== undefined) return;\n }\n }\n }\n path.pop();\n inStack.delete(id);\n };\n\n for (const task of tasks) {\n if (cyclePath !== undefined) break;\n dfs(task.id);\n }\n\n throw new CycleError(cyclePath ?? tasks.map((t) => t.id));\n }\n\n return order;\n}\n\nasync function schedule<T>(\n tasks: readonly Task<T>[],\n options: SchedulerOptions = {}\n): Promise<Map<string, T>> {\n const maxConcurrency = options.maxConcurrency ?? 1;\n if (!Number.isInteger(maxConcurrency) || maxConcurrency < 1) {\n throw new SchedulerError(\"maxConcurrency must be a positive integer\");\n }\n\n const idToTask = new Map<string, Task<T>>();\n for (const task of tasks) {\n if (idToTask.has(task.id)) {\n throw new DuplicateIdError(task.id);\n }\n idToTask.set(task.id, task);\n }\n\n for (const task of tasks) {\n for (const dep of task.deps) {\n if (!idToTask.has(dep)) {\n throw new UnknownDependencyError(task.id, dep);\n }\n }\n }\n\n const order = topologicalOrder(tasks, idToTask);\n const { signal, cancel } = createCombinedSignal(options.signal);\n\n const results = new Map<string, T>();\n const failed = new Set<string>();\n const cancelled = new Set<string>();\n const running = new Set<string>();\n const promises = new Map<string, Promise<void>>();\n const readyQueue: string[] = [];\n const readySet = new Set<string>();\n const remainingDeps = new Map<string, number>();\n\n for (const id of order) {\n const task = idToTask.get(id)!;\n remainingDeps.set(id, task.deps.length);\n }\n\n for (const id of order) {\n const task = idToTask.get(id)!;\n if (task.deps.length === 0) {\n readyQueue.push(id);\n readySet.add(id);\n }\n }\n\n let activeCount = 0;\n let firstError: unknown = undefined;\n let hasError = false;\n let isCancelled = false;\n let isDone = false;\n\n const onAbort = () => {\n if (isCancelled || isDone) return;\n isCancelled = true;\n for (const id of readyQueue.splice(0)) {\n cancelled.add(id);\n }\n for (const id of readySet) {\n if (!running.has(id) && !cancelled.has(id)) {\n cancelled.add(id);\n }\n }\n readySet.clear();\n };\n\n signal.addEventListener(\"abort\", onAbort, { once: true });\n\n const markFailed = (id: string, error: unknown): void => {\n if (failed.has(id)) return;\n failed.add(id);\n if (!hasError) {\n hasError = true;\n firstError = error;\n }\n const dependents = new Set<string>();\n const collectDependents = (taskId: string): void => {\n if (dependents.has(taskId)) return;\n dependents.add(taskId);\n const task = idToTask.get(taskId);\n if (task) {\n for (const dep of task.deps) {\n collectDependents(dep);\n }\n }\n };\n const task = idToTask.get(id);\n if (task) {\n for (const dep of task.deps) {\n collectDependents(dep);\n }\n }\n for (const depId of dependents) {\n if (!failed.has(depId) && !cancelled.has(depId) && !running.has(depId)) {\n cancelled.add(depId);\n }\n }\n };\n\n const tryStartNext = (): void => {\n if (isDone || hasError || isCancelled) return;\n while (activeCount < maxConcurrency && readyQueue.length > 0) {\n const id = readyQueue.shift()!;\n if (readySet.has(id)) {\n readySet.delete(id);\n }\n if (failed.has(id) || cancelled.has(id) || running.has(id)) {\n continue;\n }\n const task = idToTask.get(id)!;\n running.add(id);\n activeCount += 1;\n\n const promise = (async (): Promise<void> => {\n try {\n if (signal.aborted) {\n throw new CancellationError();\n }\n const value = await task.run(signal);\n results.set(id, value);\n } catch (error) {\n if (isCancelled) {\n cancelled.add(id);\n } else {\n markFailed(id, error);\n }\n } finally {\n running.delete(id);\n activeCount -= 1;\n const dependents = new Set<string>();\n const collectDependents = (taskId: string): void => {\n if (dependents.has(taskId)) return;\n dependents.add(taskId);\n const t = idToTask.get(taskId);\n if (t) {\n for (const dep of t.deps) {\n collectDependents(dep);\n }\n }\n };\n for (const [otherId, otherTask] of idToTask) {\n if (otherTask.deps.includes(id)) {\n collectDependents(otherId);\n }\n }\n for (const depId of dependents) {\n if (failed.has(depId) || cancelled.has(depId) || running.has(depId)) {\n continue;\n }\n const remaining = (remainingDeps.get(depId) ?? 0) - 1;\n remainingDeps.set(depId, remaining);\n if (remaining === 0 && !readySet.has(depId) && !readyQueue.includes(depId)) {\n readyQueue.push(depId);\n readySet.add(depId);\n }\n }\n tryStartNext();\n }\n })();\n\n promises.set(id, promise);\n }\n };\n\n const allSettled = (async (): Promise<void> => {\n try {\n tryStartNext();\n while (!isDone) {\n if (hasError || isCancelled) {\n isDone = true;\n break;\n }\n if (activeCount === 0 && readyQueue.length === 0) {\n isDone = true;\n break;\n }\n const pending = [...promises.values()];\n if (pending.length === 0) {\n isDone = true;\n break;\n }\n await Promise.race(pending);\n }\n } finally {\n signal.removeEventListener(\"abort\", onAbort);\n }\n })();\n\n const resultPromise = allSettled.then(\n () => {\n if (isCancelled) {\n throw new CancellationError();\n }\n if (hasError) {\n throw new TaskFailureError(\n [...failed][0] ?? \"unknown\",\n firstError\n );\n }\n return results;\n },\n (error) => {\n if (isCancelled) {\n throw new CancellationError();\n }\n throw error;\n }\n );\n\n resultPromise.catch(() => undefined);\n\n return resultPromise;\n}\n\nfunction assertEqual<T>(actual: T, expected: T, message: string): void {\n if (actual !== expected) {\n throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);\n }\n}\n\nfunction assertDeepEqual<T>(actual: T, expected: T, message: string): void {\n const a = JSON.stringify(actual);\n const e = JSON.stringify(expected);\n if (a !== e) {\n throw new Error(`${message}: expected ${e}, got ${a}`);\n }\n}\n\nfunction assertThrows(\n fn: () => unknown,\n errorClass: new (...args: never[]) => Error,\n message: string\n): void {\n try {\n fn();\n throw new Error(`${message}: expected throw, but did not throw`);\n }",
|
|
"error": null
|
|
}
|
|
]
|
|
} |