Repository: iterative/dvc

Issue:
exp show: unexpected error - 'checkpoint_tip' when using -A option
# Bug Report

<!--
## Issue name

Issue names must follow the pattern `command: description` where the command is the dvc command that you are trying to run. The description should describe the consequence of the bug.

Example: `repro: doesn't detect input changes`
-->

## Description

<!--
A clear and concise description of what the bug is.
-->

Command `dvc exp show -A` raises the following error without any output:

```
ERROR: unexpected error - 'checkpoint_tip'
```

### Reproduce

<!--
Step list of how to reproduce the bug
-->

<!--
Example:

1. dvc init
2. Copy dataset.zip to the directory
3. dvc add dataset.zip
4. dvc run -d dataset.zip -o model ./train.sh
5. modify dataset.zip
6. dvc repro
-->

Not sure what is causing this issue. Could it be related to breaking changes moving from DVC 2 to 3?

### Expected

<!--
A clear and concise description of what you expect to happen.
-->

The command should show me an overview of all experiments I ran in the DVC project folder of the Git repository.

### Environment information

<!--
This is required to ensure that we can reproduce the bug.
-->

**Output of `dvc doctor`:**

```console
$ dvc doctor
DVC version: 3.17.0 (conda)
---------------------------
Platform: Python 3.10.6 on Linux-3.10.0-1127.8.2.el7.x86_64-x86_64-with-glibc2.17
Subprojects:
        dvc_data = 2.15.4
        dvc_objects = 1.0.1
        dvc_render = 0.5.3
        dvc_task = 0.3.0
        scmrepo = 1.3.1
Supports:
        http (aiohttp = 3.8.5, aiohttp-retry = 2.8.3),
        https (aiohttp = 3.8.5, aiohttp-retry = 2.8.3),
        s3 (s3fs = 2023.6.0, boto3 = 1.26.76)
Config:
        Global: /home/aschuh/.config/dvc
        System: /etc/xdg/dvc
Cache types: hardlink, symlink
Cache directory: xfs on /dev/sda1
Caches: local
Remotes: s3, s3
Workspace directory: xfs on /dev/sda1
Repo: dvc (subdir), git
Repo.site_cache_dir: /var/tmp/dvc/repo/8d2f5d68bb223da9776a9d6301681efd
```

**Additional Information (if any):**

<!--
Please check https://github.com/iterative/dvc/wiki/Debugging-DVC on ways to gather more information regarding the issue.

If applicable, please also provide a `--verbose` output of the command, eg: `dvc add --verbose`.
If the issue is regarding the performance, please attach the profiling information and the benchmark comparisons.
-->

`dvc exp list -A` works and does not cause this issue.


Discussion:
@aschuh-hf could you please run it with `-v`? 
Using some of the baseline commit SHAs from the `dvc exp list -A` output, I was able to pinpoint a baseline rev which, when included in the list of `--rev` arguments of `dvc exp show` (without `-A`), would cause this issue. If I only list other baseline revs, the experiments table shows as expected.

```
2023-08-31 22:52:38,067 DEBUG: v3.17.0 (conda), CPython 3.10.6 on Linux-3.10.0-1127.8.2.el7.x86_64-x86_64-with-glibc2.17
2023-08-31 22:52:38,067 DEBUG: command: /opt/conda/envs/venv/bin/dvc exp show --rev 5162b9a -v
2023-08-31 22:52:43,437 ERROR: unexpected error - 'checkpoint_tip'
Traceback (most recent call last):
  File "/opt/conda/envs/venv/lib/python3.10/site-packages/dvc/cli/__init__.py", line 209, in main
    ret = cmd.do_run()
  File "/opt/conda/envs/venv/lib/python3.10/site-packages/dvc/cli/command.py", line 26, in do_run
    return self.run()
  File "/opt/conda/envs/venv/lib/python3.10/site-packages/dvc/commands/experiments/show.py", line 179, in run
    show_experiments(
  File "/opt/conda/envs/venv/lib/python3.10/site-packages/dvc/commands/experiments/show.py", line 80, in show_experiments
    td.column("Experiment")[:] = map(prepare_exp_id, td.as_dict(merge_headers))
  File "/opt/conda/envs/venv/lib/python3.10/site-packages/dvc/commands/experiments/show.py", line 48, in prepare_exp_id
    tree = experiment_types[typ]
KeyError: 'checkpoint_tip'
```
This is probably an `exp show` bug, but can you also try doing
```
rm -r .dvc/tmp/exps/cache
```
and then retry `dvc exp show` with the flags that give you the error
After doing this, the `dvc exp show`  command from above displays a number of "Removing '*/.dvc/tmp/exps/cache/??/*' messages, but then I get the same error as before.

Resolving patch:
diff --git a/dvc/repo/experiments/show.py b/dvc/repo/experiments/show.py
--- a/dvc/repo/experiments/show.py
+++ b/dvc/repo/experiments/show.py
@@ -243,19 +243,16 @@ def _exp_range_rows(
     is_base: bool = False,
     **kwargs,
 ) -> Iterator[Tuple["CellT", ...]]:
-    for i, exp in enumerate(exp_range.revs):
+    from funcy import first
+
+    if len(exp_range.revs) > 1:
+        logger.debug("Returning tip commit for legacy checkpoint exp")
+    exp = first(exp_range.revs)
+    if exp:
         row: Dict[str, "CellT"] = {k: fill_value for k in all_headers}
         row["Experiment"] = exp.name or ""
         row["rev"] = exp.rev[:7] if Git.is_sha(exp.rev) else exp.rev
-        if len(exp_range.revs) > 1:
-            if i == 0:
-                row["typ"] = "checkpoint_tip"
-            elif i == len(exp_range.revs) - 1:
-                row["typ"] = "checkpoint_base"
-            else:
-                row["typ"] = "checkpoint_commit"
-        else:
-            row["typ"] = "branch_base" if is_base else "branch_commit"
+        row["typ"] = "branch_base" if is_base else "branch_commit"
         row["parent"] = ""
         if exp_range.executor:
             row["State"] = exp_range.executor.state.capitalize()


Test patch: