abhigyanpatwari/GitNexus · error · SandboxError

benchmark index metadata is malformed: {metadata_path}

Error message

benchmark index metadata is malformed: {metadata_path}

What it means

Raised by isolated_gitnexus_registry_mount when the (already-validated regular, non-symlink) metadata file cannot be parsed as JSON. The bytes are read via _bounded_regular_bytes (2 MiB cap) and json.loads is attempted; a JSONDecodeError is wrapped as a SandboxError pointing at the metadata path. This guards the registry mount against a corrupt or truncated index descriptor.

Source

Thrown at eval/workflow_bench/runner.py:348

    """Repo-local prompt roots that must remain immutable during a session."""

    return tuple(worktree / ".claude" / "skills" / name for name in EVALUATED_ARM_SKILLS.get(arm, ()))


def isolated_gitnexus_registry_mount(worktree: Path, parent: Path) -> ReadOnlyMount:
    """Create a one-clone registry that cannot route MCP to any host repo."""

    metadata_path = worktree / ".gitnexus" / "gitnexus.json"
    if not metadata_path.exists():
        metadata_path = worktree / ".gitnexus" / "meta.json"
    mode = metadata_path.lstat().st_mode
    if stat.S_ISLNK(mode) or not stat.S_ISREG(mode):
        raise SandboxError(f"benchmark index metadata must be regular and non-symlink: {metadata_path}")
    raw = _bounded_regular_bytes(metadata_path, limit=2 * 1024 * 1024)
    try:
        metadata = json.loads(raw)
    except json.JSONDecodeError as exc:
        raise SandboxError(f"benchmark index metadata is malformed: {metadata_path}") from exc
    if not isinstance(metadata, dict):
        raise SandboxError(f"benchmark index metadata must be an object: {metadata_path}")
    indexed_at = metadata.get("indexedAt")
    last_commit = metadata.get("lastCommit")
    if not isinstance(indexed_at, str) or not indexed_at or not isinstance(last_commit, str) or not last_commit:
        raise SandboxError("benchmark index metadata is missing indexedAt or lastCommit")

    parent = parent.expanduser().absolute()
    registry = Path(tempfile.mkdtemp(prefix="wfbench-registry-", dir=parent))
    registry.chmod(0o700)
    entry: dict[str, Any] = {
        "name": "benchmark-target",
        "path": SANDBOX_WORKSPACE,
        "storagePath": f"{SANDBOX_WORKSPACE}/.gitnexus",
        "indexedAt": indexed_at,
        "lastCommit": last_commit,
    }
    for field in ("remoteUrl", "stats", "branch"):

View on GitHub (pinned to d540b00184)

Solutions

  1. Validate the file directly: `python3 -c "import json,sys; json.load(open('<worktree>/.gitnexus/gitnexus.json'))"` and read the parse error.
  2. If corrupt/truncated, delete it and regenerate: `node .gitnexus/run.cjs analyze --index-only`.
  3. Confirm the indexer completed successfully (exit 0) before running the harness.
  4. If hand-edited, reformat as strict JSON and re-validate.

Example fix

// before — truncated/corrupt JSON in the index metadata file
{ "indexedAt": "2026-07-12T00:00:00Z", "lastCommit": "ab
// after — regenerate a complete, valid descriptor
rm <worktree>/.gitnexus/gitnexus.json
node .gitnexus/run.cjs analyze --index-only
Defensive patterns

Strategy: validation

Validate before calling

import json
from pathlib import Path

def metadata_parses(path: Path) -> bool:
    try:
        json.loads(path.read_bytes())
        return True
    except json.JSONDecodeError:
        return False

assert metadata_parses(mp), f'{mp} is not valid JSON'

Try / catch

from .proposer_sandbox import SandboxError

try:
    mount = isolated_gitnexus_registry_mount(worktree, parent)
except SandboxError as exc:
    if 'malformed' in str(exc):
        # corrupt/truncated JSON; regenerate the index
        raise
    raise

Prevention

When it happens

Trigger: metadata_path passed _bounded_regular_bytes but json.loads(raw) raised json.JSONDecodeError — the file exists and is regular but its contents are not valid JSON (truncated, hand-edited, or written by a crashing indexer).

Common situations: A previous indexing run was killed mid-write leaving a truncated .gitnexus/gitnexus.json; the file was hand-edited and broke syntax; a different/older indexer wrote a non-JSON format; encoding issues (BOM, mixed encoding) make json.loads fail.

Understand the failure class

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/c3451cd1e3660b80. Report an issue: GitHub.