Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ reviews:
Apply `.github/review-bot-rules/algorithmic-complexity.md` during review. For production code over scalable user data, flag nested full-collection scans, per-target rescans for batch actions, repeated sort/filter/map work in hot paths, in-memory joins that belong in the data store, and unbenchmarked algorithm choices for paths expected to handle roughly 1000 workspaces or similar records. Pass for tiny fixed-size collections, tests and benchmark harnesses, existing inefficient code not worsened, and documented bounds with measurements.
- path: "**/*.swift"
instructions: |
Apply `.github/review-bot-rules/swift-expensive-sync-load.md` during review. Flag heavy synchronous loaders (the canonical case is `RestorableAgentSessionIndex.load()`: per-record `sysctl` plus disk reads, 350ms-1.8s) added to or moved onto the main actor or interactive paths (workspace/panel/tab/window close, SwiftUI body, didSet, menu evaluation, socket handlers). Require routing through the off-main cached accessor `SharedLiveAgentIndex.shared`. Pass for the cache's own background loader and explicit cold-cache fallbacks guarded by a nil check.
Apply `.github/review-bot-rules/swift-expensive-sync-load.md` during review. Flag heavy synchronous agent-history loads added to or moved onto the main actor or interactive paths (workspace/panel/tab/window close, SwiftUI body, didSet, menu/command-palette/shortcut evaluation, socket handlers). This includes `RestorableAgentSessionIndex.load()`, agent hook/session stores, `agent-turn-diff-baselines.json`, transcripts, trajectory files, workstream/event JSONL logs, broad directory scans, per-record syscalls, and large JSON/JSONL parsing. Require routing through `SharedLiveAgentIndex.shared`, a `Task.detached`/background actor/repository parser, or another off-main cached path. Pass for the cache/background loader itself and explicit cold-cache fallbacks guarded by a nil check.
- path: "**/*.{swift,ts,tsx,js,jsx,mjs,cjs}"
instructions: |
Apply `.github/review-bot-rules/cache-substitution-correctness.md` during review. When the diff replaces a fresh authoritative read with a cached value in a persistence, history, undo, or snapshot path, require explicit handling of cold (never-loaded) and stale (older-than-source) caches, or a documented graceful-degradation rationale. Pass for transient non-persisted UI hints and documented staleness tolerance.
Expand Down Expand Up @@ -78,7 +78,7 @@ reviews:
- name: "cmux expensive synchronous load"
mode: error
instructions: |
For production Swift changes, fail when the diff adds or moves an expensive synchronous loader onto the main actor or an interactive path per `.github/review-bot-rules/swift-expensive-sync-load.md`: the canonical case is `RestorableAgentSessionIndex.load()` (per-record `sysctl` plus disk reads) on workspace/panel/tab/window close, SwiftUI body/didSet, menu or command-palette evaluation, or socket handlers. Require the off-main cached accessor `SharedLiveAgentIndex.shared`. Pass for the cache's own `Task.detached` loader, explicit cold-cache fallbacks guarded by a nil check, and existing call sites not worsened.
For production Swift changes, fail when the diff adds or moves an expensive synchronous agent-history load onto the main actor or an interactive path per `.github/review-bot-rules/swift-expensive-sync-load.md`: `RestorableAgentSessionIndex.load()`, agent hook/session stores, `agent-turn-diff-baselines.json`, transcripts, trajectory files, workstream/event JSONL logs, broad directory scans, per-record syscalls, or large JSON/JSONL parsing in workspace/panel/tab/window close, SwiftUI body/didSet, menu/command-palette/shortcut evaluation, or socket handlers. Require `SharedLiveAgentIndex.shared`, a `Task.detached`/background actor/repository parser, or another off-main cached path that returns to MainActor only for UI/process launch work. Pass for the cache/background loader itself, explicit cold-cache fallbacks guarded by a nil check, and existing call sites not worsened.
- name: "cmux cache substitution correctness"
mode: error
instructions: |
Expand Down
15 changes: 11 additions & 4 deletions .github/review-bot-rules/swift-expensive-sync-load.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Swift Expensive Synchronous Index Loads
# Swift Expensive Synchronous Agent Loads

Flag heavy synchronous disk/syscall loads on the main actor or in interactive paths.
Flag heavy synchronous agent-history disk, JSON, transcript, trajectory, or syscall loads on the main actor or in interactive paths.

Report a failure when the diff adds or moves a call to an expensive whole-corpus loader onto a latency-sensitive path in non-test Swift. The canonical case is `RestorableAgentSessionIndex.load()`, which reads every agent kind's hook-store file from disk, resolves transcripts, and runs `sysctl(KERN_PROCARGS2)` per recorded session (measured 350ms-1.8s on machines with large agent history, and it scales with agent history, not tab count). Treat any similarly heavy synchronous loader the same way: full-directory scans, per-record syscalls, or broad JSON decode of unbounded files.
Report a failure when the diff adds or moves a call to an expensive whole-corpus loader onto a latency-sensitive path in non-test Swift. The canonical case is `RestorableAgentSessionIndex.load()`, which reads every agent kind's hook-store file from disk, resolves transcripts, and runs `sysctl(KERN_PROCARGS2)` per recorded session (measured 350ms-1.8s on machines with large agent history, and it scales with agent history, not tab count).

Also fail synchronous parsing or decoding of unbounded agent-owned files on the main actor or from user-input paths. This includes agent hook/session stores, `agent-turn-diff-baselines.json`, transcript files, trajectory files, workstream/event logs, or any large JSON/JSONL file whose size grows with agent history. A single `Data(contentsOf:)`, `String(contentsOf:)`, `JSONSerialization.jsonObject`, `JSONDecoder.decode`, line scan, directory walk, or per-record `fileExists`/stat loop is enough to flag when it can run on `@MainActor`, in menu/command-palette handling, shortcut handling, socket handlers, SwiftUI render paths, close/history paths, or other immediate UI interactions.

Treat any similarly heavy synchronous loader the same way: full-directory scans, per-record syscalls, broad JSON decode of unbounded files, or parsing that scales with all agent history instead of the focused workspace/surface/session.

Interactive / main-actor paths where this must not appear:

Expand All @@ -14,14 +18,17 @@ Interactive / main-actor paths where this must not appear:
Required shape:

- Read the off-main, cached accessor instead (in cmux: `SharedLiveAgentIndex.shared`), which loads on a background task and serves a cached result.
- Move unavoidable large-file reads/parses into a non-main `Task.detached`, actor, or repository/service method with an explicit actor hop back to `@MainActor` only for UI/process launch work.
- Bound the scan to the focused workspace, surface, session, or target key as early as practical; avoid sorting or materializing the whole file when only the newest matching record is needed.
- A synchronous load is allowed only as a cold-cache fallback guarded by a nil-cache check, or inside the cache's own off-main loader. Such call sites should carry a brief justification comment.

Allowed cases:

- The cache's own background loader (`Task.detached`).
- A background parser that returns a small value and then hops back to `@MainActor` for UI work.
- An explicit cold-cache fallback such as `cache ?? RestorableAgentSessionIndex.load()`.
- Existing call sites the PR does not introduce or worsen.

When reporting, name the heavy loader, the interactive path it now runs on, and the cached/off-main accessor that should replace it.
When reporting, name the heavy loader or large agent file, the interactive path it now runs on, and the cached/off-main accessor or background parser that should replace it.

Background: this rule exists because a synchronous `RestorableAgentSessionIndex.load()` added to the workspace/tab close paths froze the UI 350ms-1.8s on every close (https://github.com/manaflow-ai/cmux/pull/5669).
6 changes: 6 additions & 0 deletions .greptile/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
"scope": ["**/*.swift", "**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mjs", "**/*.cjs", "**/*.sh", "**/*.zsh"],
"severity": "high"
},
{
"id": "cmux-swift-expensive-sync-load",
"rule": "Flag production Swift that reads, decodes, or scans unbounded agent-history data on the main actor or interactive paths: RestorableAgentSessionIndex.load(), agent hook/session stores, agent-turn-diff-baselines.json, transcript files, trajectory files, workstream/event JSONL logs, broad directory scans, per-record syscalls, or large JSON/JSONL parsing. Require SharedLiveAgentIndex.shared, Task.detached, a background actor/repository parser, or another off-main cached path that returns to MainActor only for UI/process launch work. Pass for the cache/background loader itself, explicit nil-cache fallbacks with justification, and existing call sites not worsened.",
"scope": ["**/*.swift", "**/Package.swift"],
"severity": "high"
},
{
"id": "cmux-swiftui-state-layout",
"rule": "Flag SwiftUI changes that can cause stale state, broad invalidation, layout instability, or main-thread churn: new ObservableObject/@Published state where @Observable is correct, GeometryReader measurement that changes layout, lazy/list row subtrees holding store references, or state mutation during body rendering.",
Expand Down
5 changes: 5 additions & 0 deletions .greptile/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"description": "Source-of-truth cmux review rule for scalable collection algorithms and benchmark-backed complexity choices.",
"scope": ["**/*.swift", "**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mjs", "**/*.cjs", "**/*.sh", "**/*.zsh"]
},
{
"path": ".github/review-bot-rules/swift-expensive-sync-load.md",
"description": "Source-of-truth cmux review rule for keeping large agent-history JSON, transcript, trajectory, and syscall loads off MainActor and interactive Swift paths.",
"scope": ["**/*.swift", "**/Package.swift"]
},
{
"path": ".github/review-bot-rules/swift-concurrency-modernization.md",
"description": "Source-of-truth cmux lint rule for Swift concurrency modernization review.",
Expand Down
10 changes: 9 additions & 1 deletion .greptile/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Review production Swift and runtime changes for:
- Architectural fixes that patch symptoms while leaving bad state representable.
- User-facing errors, alerts, command output, API error bodies, and recovery copy that expose implementation details.
- Algorithmic complexity regressions on scalable user-owned collections.
- Expensive synchronous index/disk/syscall loads (such as `RestorableAgentSessionIndex.load()`) on the main actor or interactive paths instead of the off-main cached accessor.
- Expensive synchronous agent-history disk, JSON, transcript, trajectory, JSONL, directory, or syscall loads (such as `RestorableAgentSessionIndex.load()`, hook/session stores, `agent-turn-diff-baselines.json`, transcripts, trajectory files, and workstream/event logs) on the main actor or interactive paths instead of an off-main cached/background accessor.
- Substituting a cached value for a fresh authoritative read in persistence/history/undo paths without handling cold and stale caches.
- Local/generated artifacts, dependency checkouts, caches, logs, screenshots, temp folders, and scratch directories that accidentally enter source control.
- SwiftPM dependency changes that ignore or omit cmux-owned `Package.resolved` lockfiles.
Expand Down Expand Up @@ -54,6 +54,14 @@ For production code over scalable user-owned collections, flag nested full-colle

Pass for tiny fixed-size collections, tests, benchmark harnesses, existing inefficient code not worsened by the PR, and documented bounds backed by measurements.

## Swift Expensive Synchronous Agent Loads

For production Swift, flag any unbounded agent-history read, decode, parse, directory scan, or per-record syscall that can run on MainActor or from user-input paths.

Fail synchronous `Data(contentsOf:)`, `String(contentsOf:)`, `JSONSerialization.jsonObject`, `JSONDecoder.decode`, JSONL line scans, transcript/trajectory parsing, `agent-turn-diff-baselines.json` scans, hook/session-store reads, workstream/event log scans, or per-record `fileExists`/stat/sysctl loops when they run in workspace/panel/tab/window close, SwiftUI body/didSet, menu/command-palette/shortcut evaluation, socket handlers, or any immediate UI interaction. These files can grow with all agent history and have caused UI hangs on real machines.

Require `SharedLiveAgentIndex.shared`, a `Task.detached` parser, a background actor/repository, or another off-main cached path that returns to MainActor only for UI/process launch work. Bound scans by focused workspace/surface/session as early as practical. Pass for the cache/background loader itself, explicit nil-cache fallbacks with a justification, and existing call sites the PR does not worsen.

## Source Control Artifacts

For every changed path, flag local tool output, generated logs, screenshots, recordings, temp folders, dependency checkouts, caches, build output, DerivedData, package-manager downloads, and broad scratch directories that enter source control without a deliberate product, docs, fixture, build, release, or test-system reason.
Expand Down
Loading
Loading