from __future__ import annotations


def merge_frontmatter_metadata(base: dict[str, object], frontmatter: dict) -> dict[str, object]:
    merged = dict(base)
    if not isinstance(frontmatter, dict):
        return merged
    for raw_key, value in frontmatter.items():
        key = str(raw_key or "").strip()
        if not key or key == "__frontmatter_parse_error__" or key in merged:
            continue
        merged[key] = value
    return merged
