HKUDS/DeepTutor · error · ValueError

unknown layer {layer!r}

Error message

unknown layer {layer!r}

What it means

dedup's _path_for maps a layer string to the corresponding memory file path and only accepts 'L2' and 'L3'. Any other value raises ValueError, because there is no file path for an unknown layer.

Source

Thrown at deeptutor/services/memory/consolidator/modes/dedup.py:209

    return DedupResult(
        layer=layer,
        key=key,
        iterations_run=min(iters, (i + 1) if iters else 0),
        edits_applied=total_applied,
        converged_early=converged,
    )


# ── Helpers ─────────────────────────────────────────────────────────────


def _path_for(layer: str, key: str):
    if layer == "L2":
        return paths.l2_file(key)  # type: ignore[arg-type]
    if layer == "L3":
        return paths.l3_file(key)  # type: ignore[arg-type]
    raise ValueError(f"unknown layer {layer!r}")


def _default_title(layer: str, key: str) -> str:
    if layer == "L2":
        return f"{key} memory"
    return {
        "recent": "Recent summary",
        "profile": "User profile",
        "scope": "Knowledge scope",
        "preferences": "Preferences",
    }.get(key, f"{key} memory")


def _render_with_numbers(view) -> str:
    width = max(2, len(str(len(view.lines))))
    return "\n".join(f"{line.number:>{width}}: {line.text}" for line in view.lines)

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Pass exactly 'L2' or 'L3'
  2. Validate/normalize the layer string at your entry point (strip + upper + membership check)
  3. Share a single Layer literal/enum across dedup, merge, update, and audit call sites

Example fix

# before
await run_dedup("l2", key)
# after
await run_dedup("L2", key)
Defensive patterns

Strategy: type-guard

Validate before calling

assert layer in ("L2", "L3"), f"bad layer {layer!r}"

Type guard

from typing import Literal, TypeGuard

Layer = Literal["L2", "L3"]

def is_layer(v: object) -> TypeGuard[Layer]:
    return isinstance(v, str) and v in ("L2", "L3")

Prevention

When it happens

Trigger: The dedup pipeline (_run_dedup_inner) invoking _path_for with a layer string that isn't exactly 'L2' or 'L3' — lowercase variants, 'L1', or whitespace-padded input.

Common situations: Passing user-typed or config-file layer values straight into the dedup API; casing drift after refactoring shared layer constants.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/e78141e56d84e72a. Report an issue: GitHub.