# edit_prediction: Expose \`allow_data_collection\` in settings \(\#51389\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a710669e0385c770c23a0ffc92c132bb96b38fa5)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a710669e0385c770c23a0ffc92c132bb96b38fa5

Requested commit: a710669e0385c770c23a0ffc92c132bb96b38fa5

Commit: a710669e0385c770c23a0ffc92c132bb96b38fa5

Tree: 0932b10b724f412d68d07753dd36c666f7938aab

Author: Oliver Azevedo Barnes

Committer: GitHub

## Message

````
edit_prediction: Expose `allow_data_collection` in settings (#51389)

Closes #48394

Moves the data collection preference for Zed's Edit Predictions out of
the internal KV store and into `settings.json` as a proper
`allow_data_collection` setting under `edit_predictions`.

**Migration:** Existing users' choices are preserved. When
`allow_data_collection` is absent from `settings.json`, the resolved
value falls back to the legacy KV entry
(`zed_predict_data_collection_choice`). Once the user toggles the
setting or sets it explicitly, the new setting takes precedence and the
KV entry is ignored.

**Bug fixed:** The original implementation of `toggle_data_collection`
read the raw (unresolved) settings content to determine the current
state. When `allow_data_collection` was absent from `settings.json` but
the KV store held `"true"`, the raw read returned `None → false`,
causing the first toggle click to write `Some(true)` (re-enabling)
instead of `Some(false)` (disabling). The fix reads the resolved
`is_data_collection_enabled()` value before entering the
`update_settings_file` closure.

## Manual testing

**Setting takes effect:**
1. Open settings (`cmd+,`) and add `"allow_data_collection": true` under
`edit_predictions`. Save.
2. Open a file — the data collection indicator in the editor should
reflect the enabled state.
3. Flip to `false` and confirm it updates.

**Toggle correctly disables from KV-enabled state (migration bug fix):**
1. Remove `allow_data_collection` from `settings.json`.
2. Write the legacy KV entry directly:
   ```
   sqlite3 ~/Library/Application\ Support/Zed/db/0-dev/db.sqlite \
"INSERT OR REPLACE INTO kv_store(key,value)
VALUES('zed_predict_data_collection_choice','true');"
   ```
3. Restart Zed. The data collection toggle should show as **enabled**
(reading from KV store).
4. Click the toggle once to disable. `allow_data_collection` should
appear as `false` in `settings.json` — not `true`, which was the pre-fix
behaviour.

**Upsell modal still appears for new users:**
1. Clear both KV keys and restart:
   ```
   sqlite3 ~/Library/Application\ Support/Zed/db/0-dev/db.sqlite \
"DELETE FROM kv_store WHERE key IN
('zed_predict_data_collection_choice','dismissed-edit-predict-upsell');"
   ```
2. Open any file so the status bar is visible.
3. Click the edit prediction button (bottom-right status bar) — it
should have a muted dot indicator.
4. The upsell modal should appear. Dismissing it should prevent it from
reappearing.

## Release Notes:

- `allow_data_collection` for Zed's Edit Predictions can now be set
explicitly in `settings.json` under `edit_predictions`. Existing
preferences stored in the internal database are preserved as a fallback.

---------

Co-authored-by: Ben Kunkle <ben.kunkle@gmail.com>
````

## Parents

- [2d86e3b30b735e5e04e64c6e09ba76141f02fbba](https://git.cafe/gitcafe/zed/commit/2d86e3b30b735e5e04e64c6e09ba76141f02fbba?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a710669e0385c770c23a0ffc92c132bb96b38fa5?format=markdown)
