5 Commits
Author SHA1 Message Date
tidely 85b8aa5898 gpui_macos: Migrate screen capture to objc2 (#64251)
# Objective

Get rid of instances of the `block` crate, as it will not compile in a
future version of Rust. This gets rid of the `block` crate inside of
`gpui_macos`, which means were on the home stretch.

## Solution

Migrate `screen_capture.rs` completely to `objc2`. While a more targeted
fix is theoretically possible, there were enough upsides where I thought
this was worth a full migration.

Completely gets rid of the `media` crate, which had manual bindings to
`core_media`, which `objc2` can provide. Gets rid of tons of unsafe
code, and a lot of code in general.

## Testing

Tested manual sharing inside of a Zed channel

Release Notes:

- N/A
- [GPUI] Migrated macOS screen capture to `objc2`
2026-09-17 01:46:02 +00:00
Anthony Eid 04d586b80e gpui: Make ForegroundJournal aware of sleep and window visibility (#64269)
## Summary

Keep foreground-work measurements and per-window presentation
expectations valid across observed sleep/wake and visibility changes.
Simplified after review to about 530 changed lines including tests and
configuration.

## Scope

- Keep all measurement state in the foreground-local journal writer. Use
`PowerState` and `PowerTransition`; no new locks, counters, or changes
to the ring protocol.
- Work that started at or before the last power transition (or while
suspended) is dropped when it completes: task polls before small-poll
folding, and actions, inputs, draws, and presents through the same
`power_interrupted_since(start)` check. No per-activity state is added;
every measurement already carries its start time.
- Track visibility and pending frames together per window. Hiding or
sleeping clears the presentation expectation; on recovery
`Window::refresh_visibility` re-records it from the window's actual
dirty state, so the journal never guesses. Old latency associations
remain invalid.
- Repeated notifications for the same power state are ignored, so a
duplicate wake does not invalidate in-flight work.
- The journal subscribes to GPUI's existing power notifications and
rechecks native window visibility after wake. App only registers these
subscriptions (two initialization lines).
- Keep the existing one-second pending-frame deadline and
foreground-turn sealing behavior. No watchdog, recurring timer, test-app
exceptions, unfinished-hang detection, start/end ring notices, or
reader-side deduplication.
- Remove lifecycle counters. Keep measurement version 2 on reports and a
valid dirty-to-present sample count for weighting averages.

## Telemetry

- `Hang Incidents` gains `report_window_seconds` and stall percentiles
over every incident in the window (`stall_p50_ms`, `stall_p95_ms`,
`stall_max_ms`, from an `hdrhistogram`), so stall distributions no
longer depend on the censored `incidents[]` list. Reports are now sent
even when no incident occurred, so summing `report_window_seconds` gives
observed running time for incident rates.
- `Frame Duration Report` gains dirty-to-present percentiles
(`dirty_to_present_p50_ms`, `dirty_to_present_p95_ms`,
`dirty_to_present_max_ms`) alongside the existing average, and
`average_present_interval_ms` (mean frame-to-frame interval while
animating, a proxy for the display's refresh interval when normalizing
dirty-to-present).

Detection remains completion-based. This does not solve hangs that never
return or force an interval to seal when no further foreground events
arrive. Existing legacy hang logs/trace triggers are unchanged. Late or
coalesced platform notifications remain a coverage limitation.

## Validation

- `corgi test -p gpui --features profiler --lib`: **392 tests passed**.
- Focused lifecycle/wake tests also passed a 20-seed run.
- The extension-suggestion regression that failed on all three CI
platforms now passes locally after removal of the
watchdog/test-construction changes.
- `corgi check -p gpui` and `corgi check -p zed -p input_latency_ui`
passed.
- Formatting and `git diff --check` passed.
- Corgi configuration includes only the three existing GPUI image/font
fixtures needed to run its tests.

Native platform sleep/wake testing and review remain outstanding. The
README review marker remains for the human author to remove manually
after review.

Release Notes:

- Improved the accuracy of hang and frame-latency telemetry around
sleep, wake, and hidden windows.
- [GPUI] Added a `PowerTransition` interval boundary and
`measurement_version` to profiler hang reports.
2026-09-16 16:00:19 +00:00
Conrad Irwin 85ad201397 Add a filesystem watching debug window (#64065)
## Summary

Add `dev: Debug Filesystem Watching`, which opens a singleton, app-wide
debug window for local filesystem watching.

- Capture native and polling notifications before filtering/coalescing,
including lost-sync/rescan markers and watcher initialization,
registration, and removal errors.
- Show Raw Events, Watch Roots, and Scan Exclusions in separate
read-only editors with normal selection and copying.
- Record only while the window is open, retain the latest 10,000 events,
and periodically compact editor buffers so deleted text/history does not
accumulate indefinitely.
- Display local timestamps and concise event names; export full raw
details, roots, exclusions, dropped-event counts, and Zed/OS version
information as JSON.
- Declare the renderer source that `gpui_apple`'s build script reads in
Corgi's sandbox configuration.

This is diagnostic tooling, not a change to watcher behavior. It
captures local watcher-level events; it does not yet trace worktree scan
start/completion or remote filesystems. Scan exclusions are labeled
separately from OS watch roots because excluded files can still generate
notifications.

## Related issues

These reports motivate the capture tooling; this PR does not claim to
fix them:

- [#63254: Project and Git panels stop updating when the macOS FSEvents
stream limit is
reached](https://github.com/zed-industries/zed/issues/63254)
- [#63174: Atomic file replacement leaves Linux buffers
stale](https://github.com/zed-industries/zed/issues/63174)
- [#58678: Worktree stops opening files/expanding folders after a
lost-sync rescan
storm](https://github.com/zed-industries/zed/issues/58678)
- [#53480: High CPU after watcher lost sync under low file-descriptor
limits](https://github.com/zed-industries/zed/issues/53480)

## Validation

- `corgi build -p zed`
- `corgi test -p fs --lib --features test-support fs_watcher` — 19 tests
passed
- `corgi test -p fs --features test-support --test integration
watcher_diagnostics` — 2 tests passed, including real OS notification
delivery
- `cargo test -p zed watcher_debug::tests` — 7 tests passed, covering
formatting, singleton lifetime, tab layout, copying/read-only behavior,
selection preservation, compaction and retained storage, JSON metadata,
cancellation, and save failures
- Rust formatting and `git diff --check`
- Manual UI smoke testing on macOS during development

The UI tests use Cargo because the installed Corgi version omits
`CARGO_BIN_NAME` when compiling the binary test target. Normal Corgi
builds pass.

## Reviewer note

The required README review acknowledgment is intentionally left for the
author to remove manually after review.

## Suggested .rules additions

For bounded diagnostic logs backed by an editor, trimming visible rows
does not bound memory: the text buffer retains deleted text and edit
history. Periodically replace the buffer/editor while preserving
selection and scroll state, and test retained storage rather than only
visible row count.

Release Notes:

- Added `dev: Debug Filesystem Watching` to inspect local watcher
events, watch roots, and scan exclusions, and export diagnostic captures
as JSON.
2026-09-11 04:13:07 +00:00
Conrad Irwin 99f85efa71 corgi: Use globs for extra-inputs (#63558)
Corgi 0.1.43 changes how `[extra-inputs]` in `corgi.toml` is read:
entries are glob patterns rather than plain paths, and they select files
rather than directories. Handing corgi a bare directory name used to
mean "everything under here, hashed as a tree"; now it matches nothing
and reports that appending `/**` is the fix. This updates each directory
entry accordingly, and rewords the section comment to describe the new
rules.

The practical gain is that the readable set and the hashed set are now
exactly the same set of files. Each matched file is granted to the
sandbox individually and hashed under its workspace-relative path, so
adding, removing, or renaming a file that a pattern covers changes the
package's source hash even when no file's contents changed. Reading a
file that no pattern matches is denied rather than silently allowed
because it happened to sit inside a granted directory.

Three reads that corgi has been denying all along now have entries.
`eval_cli`'s build script reads `crates/zed/Cargo.toml`, `gpui_wgpu`
includes its WGSL shaders through `include_str!`, and
`zed_extension_api` includes its own `wit` tree through
`wit_bindgen::generate!`. Each of those units fails on `main` today
under `corgi check --workspace`. The last one could not be declared at
all until corgi 0.1.43, because `[extra-inputs]` is keyed by package
name and this workspace resolves three packages named
`zed_extension_api` — the member at 0.8.0 plus published 0.1.0 and 0.7.0
that extensions depend on — so the declaration reached the published
copies and failed the workspace-escape check. Corgi now applies extra
inputs only to local packages, which is safe because a registry package
is hashed as a whole directory and reads its own root freely.

`corgi_version` is pinned to 0.1.43 so everyone picks up the matching
corgi automatically; older corgi releases cannot read these entries.

Testing:

- `corgi check --workspace` passes with no failing units, which it did
not do before this change.
- `corgi build -p zed` links the binary.
- `corgi check --workspace --all-targets` goes from 16 failing units to
13. The remaining 13 are pre-existing undeclared reads in test targets
(font files under `assets/`, `test_data` fixtures and similar) that this
change does not attempt to fix.

Release Notes:

- N/A
2026-09-01 15:40:02 +00:00
Conrad IrwinandBen Kunkle 72dc742101 Support building with corgi (#63396)
[corgi](https://github.com/ConradIrwin/corgi) is a cargo-compatible
build tool that runs `build.rs` scripts and proc-macros in a sandbox (no
network, no ambient env, reads limited to a package's own `.rs` sources
unless declared). This makes Zed buildable under it. Cargo builds (dev
and release) are unaffected.

### Changes

- **`scratch` patch**: patch `scratch` to a small local copy
(`corgi-patches/scratch`) that reads `OUT_DIR` at runtime instead of
baking it in at compile time. `cxx-build` writes its shared cxxbridge
headers into `scratch::path(...)`; upstream returns a single global dir
(outside any action's `OUT_DIR`) that the sandbox can't grant, while
this patch gives each build script a private, writable dir in its own
entry. webrtc-sys is self-contained, so per-crate scratch dirs are
sufficient. Kept local rather than a cxx git fork because a git checkout
of cxx needs symlink support that Windows cargo CI lacks.
- **Dev asset loading**: add `util::dev_fs_embed!` and switch dev-mode
`rust_embed` asset sources (`assets`, `settings`, `grammars`, `agent`,
`edit_prediction_cli`) to read from the checkout at runtime, locating
the repo root by walking from the executable up to the enclosing `.git`.
This avoids baking `CARGO_MANIFEST_DIR` into the binary (corgi rejects
artifacts that embed the build-time checkout path, and it's wrong in any
other worktree). Release builds still embed via `#[derive(RustEmbed)]`.
- **Stop baking checkout paths into artifacts**: drop
`gpui::GPUI_MANIFEST_DIR`; resolve `../gpui` from `gpui_apple`'s build
script; stage the metal shader into `OUT_DIR` before compiling so the
`.metallib` records the output dir, not the checkout; resolve the repo
root at runtime in `remote` and `inspector_ui` (removing
`inspector_ui`'s `build.rs` / `ZED_REPO_DIR`).
- **corgi.toml**: declare the pinned tools (`cmake`, prebuilt libwebrtc
via `LK_CUSTOM_WEBRTC`), a release-only `ZED_COMMIT_SHA` probe, and the
non-`.rs` / cross-package reads each package performs.

### Validation

- `corgi check` + `corgi build`, dev and release, for `zed` (plus `cli`,
`remote_server`, `ep`) with a warm C++ cache — clean; built binaries
embed no checkout path.
- `corgi fmt --check`, `corgi clippy`, and `corgi test` on the changed
crates (922 tests pass).
- `cargo check -p util` locally; relying on CI for the full cargo
build/test matrix.

### Notes for the reviewer

- Per the repo rule, the first two lines of `README.md` are the
review-confirmation marker; remove them before merging (this is what
Danger is failing on).
- `remote_server` cross-compilation (linux-musl via zigbuild) is not yet
covered by `corgi.toml` — host (macOS arm64) only for now.

### Suggested .rules additions

Only if the team wants corgi guidance in `.rules` (it recurred several
times here): dev builds must not bake the checkout path into artifacts —
no `env!("CARGO_MANIFEST_DIR")` or `file!()`-derived absolute paths in
library/binary output. Resolve the repo root at runtime via
`util::dev_repo_root()` (walks to `.git`), and use `util::dev_fs_embed!`
for dev-mode `rust_embed` sources.

Release Notes:

- N/A

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
2026-08-31 17:37:00 +00:00