Repository: xonsh/xonsh

Issue:
KeyError `locked` in latest build of xonsh
I recently updated to the latest version of xonsh and also installed a bespoke branch of ptk2. When I did, I started getting the error on startup:

```
~ $ Exception in thread Thread-10:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/xonsh/history/__amalgam__.py", line 372, in run
    files = self.files(only_unlocked=True)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/xonsh/history/__amalgam__.py", line 426, in files
    if lj["locked"] and lj["ts"][0] < boot:
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 783, in __getitem__
    rtn = self._getitem_mapping(key)
  File "/Users/jaraco/.local/pipx/venvs/xonsh/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 767, in _getitem_mapping
    offset = self.offsets[key]
KeyError: 'locked'
```

I then re-installed the latest stable version of prompt_toolkit, but the error continues.

The prompt works after the error is emitted.

I have not tried troubleshooting further.

Given that others haven't reported this issue, I suspect it's somewhat localized to my environment (and history).

## xonfig

<details>

```
~ $ xonfig
+------------------+---------------------+
| xonsh            | 0.9.19              |
| Git SHA          | 74450cb5            |
| Commit Date      | Aug 9 13:27:55 2020 |
| Python           | 3.8.5               |
| PLY              | 3.11                |
| have readline    | True                |
| prompt toolkit   | 3.0.6               |
| shell type       | prompt_toolkit      |
| pygments         | None                |
| on posix         | True                |
| on linux         | False               |
| on darwin        | True                |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | False               |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+
```

</details>

## Expected Behavior

Prompt should startup without error.




Discussion:

Resolving patch:
diff --git a/xonsh/history/json.py b/xonsh/history/json.py
--- a/xonsh/history/json.py
+++ b/xonsh/history/json.py
@@ -188,7 +188,7 @@ def files(self, only_unlocked=False):
                     files.append((os.path.getmtime(f), 0, f, cur_file_size))
                     continue
                 lj = xlj.LazyJSON(f, reopen=False)
-                if lj["locked"] and lj["ts"][0] < boot:
+                if lj.get("locked", False) and lj["ts"][0] < boot:
                     # computer was rebooted between when this history was created
                     # and now and so this history should be unlocked.
                     hist = lj.load()
@@ -197,16 +197,12 @@ def files(self, only_unlocked=False):
                     with open(f, "w", newline="\n") as fp:
                         xlj.ljdump(hist, fp, sort_keys=True)
                     lj = xlj.LazyJSON(f, reopen=False)
-                if only_unlocked and lj["locked"]:
+                if only_unlocked and lj.get("locked", False):
                     continue
                 # info: file size, closing timestamp, number of commands, filename
+                ts = lj.get("ts", (0.0, None))
                 files.append(
-                    (
-                        lj["ts"][1] or lj["ts"][0],
-                        len(lj.sizes["cmds"]) - 1,
-                        f,
-                        cur_file_size,
-                    ),
+                    (ts[1] or ts[0], len(lj.sizes["cmds"]) - 1, f, cur_file_size,),
                 )
                 lj.close()
                 if xonsh_debug:


Test patch: