xai-org/x-algorithm · error · PyTypeError

shard_sources entry must be (name, fname, offset, size) for

Error message

shard_sources entry must be (name, fname, offset, size) for name {key}

What it means

PyTypeError raised by load_tensor when the fname (element 1) of a shard_sources entry cannot be extracted as a String. Each entry must be a 4-tuple (name, fname, offset, size); this specific line is the fname extraction failing.

Source

Thrown at phoenix/crates/serving/xai-recsys-engine/src/emb_table.rs:1433

        let tuple = t.downcast::<PyTuple>().map_err(|_| err0())?;
        if tuple.len() != 4 {
            return Err(err0());
        }
        let k = tuple.get_item(0)?;
        let key: String = k.extract().map_err(|_| {
            PyTypeError::new_err(format!(
                "shard_sources name {} must be a string",
                k.repr()
                    .map(|s| s.to_string())
                    .unwrap_or("<unknown>".to_string())
            ))
        })?;
        let err = || {
            PyTypeError::new_err(format!(
                "shard_sources entry must be (name, fname, offset, size) for name {key}"
            ))
        };
        let fname: String = tuple.get_item(1)?.extract().map_err(|_| err())?;
        let offset: usize = tuple.get_item(2)?.extract().map_err(|_| err())?;
        let size: usize = tuple.get_item(3)?.extract().map_err(|_| err())?;
        parsed.push((key, fname, offset, size));
    }
    let path = path.to_string();
    let urls = urls.to_string();
    let tensor_slice = tensor.as_slice_mut()?;
    py.detach(|| {
        load_tensor_into(
            &path,
            &urls,
            &parsed,
            tensor_slice,
            row_size,
            num_row_segments,
        )
        .map_err(PyOSError::new_err)
    })

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Ensure each entry is exactly (str name, str fname, int offset, int size)
  2. Verify fname is a plain Python str, not Path/None/int
  3. Check the tuple field order matches the manifest you generated

Example fix

# before
entries = [(name, offset, fname, size)]
# after
entries = [(name, str(fname), int(offset), int(size))]
Defensive patterns

Strategy: type-guard

Validate before calling

assert all(isinstance(e, tuple) and len(e) == 4 and isinstance(e[1], str) for e in shard_sources.values())

Type guard

def valid_shard_entries(srcs): return all(isinstance(e,(tuple,list)) and len(e)==4 and isinstance(e[0],str) and isinstance(e[1],str) and isinstance(e[2],int) and isinstance(e[3],int) for e in srcs)

Try / catch

except TypeError: log the offending entry's repr and types before re-raising

Prevention

When it happens

Trigger: Calling load_tensor with a shard_sources entry whose second element is not a string — e.g. a Path object in some contexts, an int, None, or the tuple having elements in the wrong order.

Common situations: Building shard_sources from JSON where fname is null or numeric; passing pathlib.Path without str(); misordered tuple fields when offset/fname are swapped.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/840fa98ff3b92ee2. Report an issue: GitHub.