# Bugs in `gradio_sync3dcompare` 0.0.4 — `Sync3DCompare`

## Bug 1 — `/info` endpoint crash (broken `api_info()`)

**Symptom:** Every browser request triggers an ASGI 500 error in the server log. Gradio's
frontend fetches `/info` at startup to initialise its event queue; when `/info` returns 500,
the event system never fully initialises and all button clicks appear to hang indefinitely.

**Root cause:** `api_info()` returns:
```python
{"type": "array", "description": "..."}
```
There is no `items` key. `gradio_client.utils._json_schema_to_python_type` does:
```python
schema.get("items", [])   # returns [] (the default)
```
Then calls itself recursively on that `[]`:
```python
_json_schema_to_python_type([])   # schema is now a list, not a dict
[].get("$ref")                    # AttributeError: 'list' has no attribute 'get'
```

**Fix:** Either add `data_model = Sync3DCompareData` (see Bug 3) and remove the custom
`api_info()` so the base class auto-generates a correct schema, **or** replace the custom
`api_info()` with what the legacy version did:
```python
def api_info(self):
    schema = Sync3DCompareData.model_json_schema()
    desc = schema.pop("description", None)
    schema["additional_description"] = desc
    return schema
```

---

## Bug 2 — `postprocess` serves raw filesystem paths instead of browser-accessible URLs

**Symptom:** After inference completes and disparities appear, the 3D viewer spins
indefinitely. The browser cannot fetch the PLY files because it receives raw filesystem
paths (e.g. `/tmp/stereo_compare_.../model.ply`) that are not valid HTTP URLs.

**Root cause:** `postprocess` calls `serve_static_file(asset["path"])`. When the file has
not yet been registered in Gradio's cache (which can happen if postprocess is invoked
before the cache is fully populated), `serve_static_file` falls back to returning the raw
filesystem path. The code then assigns this path directly as the `url`:
```python
file_info = self.serve_static_file(asset["path"])
if file_info and isinstance(file_info, dict):
    asset["url"] = file_info.get("url") or file_info.get("path")  # may be /tmp/...
else:
    asset["url"] = asset["path"]  # always a raw path
```
Both branches can produce a URL that starts with `/` but is not a valid Gradio API path,
so the browser gets a 404 / no response.

**Fix:** Ensure every asset URL is a proper Gradio-served URL:
```python
file_info = self.serve_static_file(asset["path"])
url = None
if file_info and isinstance(file_info, dict):
    url = file_info.get("url")
if not url or not (url.startswith("/gradio_api/file=")
                   or url.startswith("/file=")
                   or url.startswith("http")):
    url = f"/gradio_api/file={asset['path']}"
asset["url"] = url
```

---

## Bug 3 — Missing `data_model = Sync3DCompareData`

**Symptom:** Gradio cannot validate inputs against the component schema; the base-class
`api_info()` raises `NotImplementedError` if the custom one is ever removed; flagging
and `read_from_flag` do not work correctly.

**Root cause:** The class does not declare:
```python
data_model = Sync3DCompareData
```
The legacy version of the component had this attribute. Without it:
- The base `Component.__init__` sets `self.data_model = None`
- Gradio's schema introspection and file-moving helpers skip the model entirely
- The only path to a working schema is the custom `api_info()` — which is broken (Bug 1)

**Fix:** Add the class attribute:
```python
class Sync3DCompare(Component):
    EVENTS = ["change"]
    data_model = Sync3DCompareData   # ← add this line
```
With `data_model` set, the base `api_info()` generates the correct JSON schema from
`Sync3DCompareData.model_json_schema()` automatically, fixing Bug 1 at the same time.

---

## Summary

| # | Bug | Impact | Fix |
|---|-----|--------|-----|
| 1 | `api_info()` returns schema without `items` | `/info` 500 → frontend event system broken → all clicks hang | Return proper `Sync3DCompareData` schema |
| 2 | `postprocess` assigns raw `/tmp/...` path as `url` | Browser cannot fetch PLY files → 3D viewer spins forever | Validate URL starts with `/gradio_api/file=` |
| 3 | Missing `data_model = Sync3DCompareData` | Schema/flagging broken; Bug 1 is unavoidable without a correct `api_info()` | Add `data_model = Sync3DCompareData` |
