Compare commits

..
6 Commits
Author SHA1 Message Date
semantic-release-bot 9d1544d799 chore(release): 1.22.0 [skip ci]
# [1.22.0](https://github.com/asepharyana/zesdex/compare/v1.21.2...v1.22.0) (2026-08-28)

### Features

* **agent:** wire auto-review (review_enabled no-op -> nyata) ([a27e815](https://github.com/asepharyana/zesdex/commit/a27e8151b39da4c8759e8e922ef132212327e413))
2026-08-28 08:31:47 +00:00
asepharyana a27e8151b3 feat(agent): wire auto-review (review_enabled no-op -> nyata)
review_enabled (default TRUE) selama ini no-op: tampil di TUI settings
overlay ("Review: true"), bisa di-toggle via command, TAPI spawn_background_review
tidak pernah dipanggil & Origin::Reviewer tidak pernah dikonstruksi. User
melihat "Review: true" padahal auto-review setelah edit tak pernah jalan.

Sekarang feature yang sudah dibangun penuh (subagent/auto/engine.rs: git diff
-> LLM review -> auto-fix HIGH/MEDIUM) di-wire:
- daemon/handler.rs: trigger setelah run_turn bila review_enabled; capture
  flag+creds SEBELUM api_key/provider_cfg di-move ke LlmClient.
- tui/turn.rs: sama, gated by state.settings.flags.review_enabled.
- ws/lib.rs: channel minimal tanpa settings -> review nyala tiap prompt
  (konsisten dgn default ON).

Aman: review fire-and-forget (tokio::spawn), get_git_diff skip bila no-change,
no-op bila bukan git repo (auto/engine). Creds dipakai = creds ter-resolve yg
sama dgn komposisi turn.

Verifikasi: check/clippy/fmt/test workspace hijau (0 error/warning/fail).
2026-08-28 15:27:33 +07:00
semantic-release-bot 88c2a7d000 chore(release): 1.21.2 [skip ci]
## [1.21.2](https://github.com/asepharyana/zesdex/compare/v1.21.1...v1.21.2) (2026-08-28)

### Performance Improvements

* **agent:** symbol index tak pegang mutex global saat rebuild I/O ([3b25e38](https://github.com/asepharyana/zesdex/commit/3b25e3898f9ba2fc1c58b991ad95a8c0bbe98601))
2026-08-28 07:58:48 +00:00
asepharyana 3b25e3898f perf(agent): symbol index tak pegang mutex global saat rebuild I/O
Sebelumnya SemanticSearch/ListSymbols/RebuildIndex menahan SYMBOL_INDEX
Mutex selama full `rebuild` (walk seluruh workspace, bisa detikan) +
selama search. Di main loop yang menjalankan read-only tools paralel,
semantic_search/list_symbols lain jadi BLOCK selama rebuild.

Refactor:
- Global berubah Mutex<Option<SymbolIndex>> -> OnceLock<Mutex<HashMap<
  workspace, SymbolIndex>>> — index per-workspace, jadi pencarian workspace B
  tidak mungkin bocor simbol stale dari A (workspace-awareness kini struktural,
  bukan hanya via needs_rebuild).
- ensure_symbol_index(workspace, force): rebuild dijalankan DI LUAR lock
  (mutex hanya dicek/insert/lookup singkat), lalu hasilnya di-swap-in di bawah
  short lock. Search/list/rebuild-report tak lagi memblock thread lain selama
  walk I/O. Per-workspace key menghilangkan race lintas-workspace dari skema
  swap tunggal.
- Test +1 (test_ensure_symbol_index_per_workspace_isolation): verifikasi dua
  workspace punya index independen, rebuild A tidak menimpa B.

Verifikasi: check/clippy -D warnings/fmt clean; test infra 64 (0 gagal).
2026-08-28 14:54:54 +07:00
semantic-release-bot d23d3855ec chore(release): 1.21.1 [skip ci]
## [1.21.1](https://github.com/asepharyana/zesdex/compare/v1.21.0...v1.21.1) (2026-08-28)

### Bug Fixes

* **agent:** semantic_search symbol index workspace-aware ([104af3a](https://github.com/asepharyana/zesdex/commit/104af3abb9e626c5d00ea87d523248d606d523ee))
2026-08-28 07:23:23 +00:00
asepharyana 104af3abb9 fix(agent): semantic_search symbol index workspace-aware
SymbolIndex global sudah melacak workspace_path tapi SemanticSearch dan
ListSymbols Cuma rebuild saat index kosong (is_empty). Akibat: setelah
mengindeks workspace A, mencari di workspace B diam-diam mengembalikan
simbol STALE dari A — menyesatkan coding agent (referensikan simbol yang
tidak ada di repo aktif).

Fix:
- Tambah SymbolIndex::needs_rebuild(workspace) — true bila index kosong
  ATAU workspace diminta beda dari yang ter-cache.
- Pakai di 2 call site (SemanticSearch::run, ListSymbols::run) menggantikan
  is_empty(), jadi pindah workspace otomatis trigger rebuild.
- test: +1 (test_needs_rebuild_workspace_aware — verifikasi flip workspace
  memicu rebuild bolak-balik A -> B -> A).

Catatan (bukan bug, dilaporkan): mutex SYMBOL_INDEX masih dipegang selama
full rebuild di run() — bottleneck saat semantic_search dipanggil paralel;
perbaikan butuh restrukturisasi double-checked rebuild, tak diubah di sini.

Verifikasi: check/clippy -D warnings/fmt clean; test infra 63 (0 gagal).
2026-08-28 14:19:22 +07:00
7 changed files with 257 additions and 37 deletions
+21
View File
@@ -1,3 +1,24 @@
# [1.22.0](https://github.com/asepharyana/zesdex/compare/v1.21.2...v1.22.0) (2026-08-28)
### Features
* **agent:** wire auto-review (review_enabled no-op -> nyata) ([a27e815](https://github.com/asepharyana/zesdex/commit/a27e8151b39da4c8759e8e922ef132212327e413))
## [1.21.2](https://github.com/asepharyana/zesdex/compare/v1.21.1...v1.21.2) (2026-08-28)
### Performance Improvements
* **agent:** symbol index tak pegang mutex global saat rebuild I/O ([3b25e38](https://github.com/asepharyana/zesdex/commit/3b25e3898f9ba2fc1c58b991ad95a8c0bbe98601))
## [1.21.1](https://github.com/asepharyana/zesdex/compare/v1.21.0...v1.21.1) (2026-08-28)
### Bug Fixes
* **agent:** semantic_search symbol index workspace-aware ([104af3a](https://github.com/asepharyana/zesdex/commit/104af3abb9e626c5d00ea87d523248d606d523ee))
# [1.21.0](https://github.com/asepharyana/zesdex/compare/v1.20.2...v1.21.0) (2026-08-28) # [1.21.0](https://github.com/asepharyana/zesdex/compare/v1.20.2...v1.21.0) (2026-08-28)
Generated
+11 -11
View File
@@ -4862,7 +4862,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-api" name = "zesdex-api"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argon2", "argon2",
@@ -4885,7 +4885,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-application" name = "zesdex-application"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@@ -4903,7 +4903,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-bootstrap" name = "zesdex-bootstrap"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@@ -4920,7 +4920,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-daemon" name = "zesdex-daemon"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@@ -4944,7 +4944,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-domain" name = "zesdex-domain"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@@ -4960,7 +4960,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-gateway" name = "zesdex-gateway"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
@@ -4987,7 +4987,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-grpc" name = "zesdex-grpc"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
@@ -5004,7 +5004,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-infrastructure" name = "zesdex-infrastructure"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argon2", "argon2",
@@ -5052,7 +5052,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-tui" name = "zesdex-tui"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@@ -5078,7 +5078,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-web" name = "zesdex-web"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
@@ -5098,7 +5098,7 @@ dependencies = [
[[package]] [[package]]
name = "zesdex-ws" name = "zesdex-ws"
version = "1.20.1" version = "1.21.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum", "axum",
+1 -1
View File
@@ -15,7 +15,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "1.21.0" version = "1.22.0"
edition = "2021" edition = "2021"
authors = ["asepharyana <superaseph@gmail.com>"] authors = ["asepharyana <superaseph@gmail.com>"]
+166 -25
View File
@@ -121,7 +121,66 @@ pub struct CodeSymbol {
} }
/// The in-memory symbol index, shared via a global static. /// The in-memory symbol index, shared via a global static.
static SYMBOL_INDEX: Mutex<Option<SymbolIndex>> = Mutex::new(None); ///
/// Keyed by workspace path: each workspace owns its own `SymbolIndex`, so
/// searching one repo never leaks stale symbols from another, and a rebuild
/// triggered for workspace A cannot clobber the index of B. The lock is only
/// ever held briefly (to check/insert/look up) — never across the I/O-heavy
/// walk in `rebuild`, which runs locally and is swapped in under a short lock.
static SYMBOL_INDEX: std::sync::OnceLock<Mutex<HashMap<String, SymbolIndex>>> =
std::sync::OnceLock::new();
/// Access the (lazily initialised) global per-workspace symbol index map.
fn symbol_index_map() -> &'static Mutex<HashMap<String, SymbolIndex>> {
SYMBOL_INDEX.get_or_init(|| Mutex::new(HashMap::new()))
}
/// Ensure the per-workspace symbol index is built, returning the symbol count.
///
/// If `force` is true, or the workspace has no cached (non-empty) index yet,
/// the index is rebuilt. The rebuild itself runs OUTSIDE the global lock
/// (the walk can take seconds on a large repo), then the result is stored
/// under a short lock so concurrent searches never block on the I/O. Returns
/// the number of symbols now cached for the workspace.
fn ensure_symbol_index(workspace: &str, force: bool) -> Result<usize> {
let ready = {
let map = symbol_index_map()
.lock()
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))?;
!force && map.get(workspace).is_some_and(|i| !i.is_empty())
};
if !ready {
// Rebuild locally, off the global lock (I/O heavy).
let mut fresh = SymbolIndex::new();
let count = fresh.rebuild(workspace)?;
// Swap in under a short lock; keep an existing non-empty index if a
// concurrent rebuild already populated this workspace.
let mut map = symbol_index_map()
.lock()
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))?;
if map.get(workspace).is_none_or(|i| i.is_empty()) {
map.insert(workspace.to_string(), fresh);
}
return Ok(count);
}
let map = symbol_index_map()
.lock()
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))?;
Ok(map.get(workspace).map_or(0, |i| i.len()))
}
/// Lock and return a borrow to the global per-workspace symbol index map.
///
/// The caller must have called [`ensure_symbol_index`] first, then looks up
/// its workspace key; the lookup is short and in-memory, so holding the guard
/// for the search is fine.
fn symbol_index() -> Result<std::sync::MutexGuard<'static, HashMap<String, SymbolIndex>>> {
symbol_index_map()
.lock()
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Language-specific regexes (lazily compiled) // Language-specific regexes (lazily compiled)
@@ -270,6 +329,17 @@ impl SymbolIndex {
self.symbols.is_empty() self.symbols.is_empty()
} }
/// Returns true when the cached index must be rebuilt for the given
/// workspace — either because nothing has been indexed yet, or because the
/// requested workspace differs from the one the index was built for.
///
/// Without this, searching a *different* workspace after the first one
/// silently returns stale symbols from the previously indexed repo
/// (a misleading result for a coding agent).
pub fn needs_rebuild(&self, workspace: &str) -> bool {
self.is_empty() || self.workspace_path.as_deref() != Some(workspace)
}
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.symbols.len() self.symbols.len()
} }
@@ -1250,15 +1320,11 @@ impl Tool for SemanticSearch {
"semantic search" "semantic search"
); );
let mut guard = SYMBOL_INDEX // Build (or load) the per-workspace index without holding the global
.lock() // lock across the I/O-heavy walk.
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))?; let _count = ensure_symbol_index(&workspace, rebuild)?;
let index = guard.get_or_insert_with(SymbolIndex::new); let map = symbol_index()?;
let index = map.get(&workspace).expect("index should be ensured");
if rebuild || index.is_empty() {
let count = index.rebuild(&workspace)?;
debug!(symbol_count = count, "symbol index rebuilt");
}
// Map kind filter to enum // Map kind filter to enum
let target_kind = match kind_filter { let target_kind = match kind_filter {
@@ -1398,12 +1464,15 @@ impl Tool for RebuildIndex {
info!("rebuilding multi-language symbol index"); info!("rebuilding multi-language symbol index");
let mut guard = SYMBOL_INDEX // Force a rebuild of this workspace's index. The walk runs off the
.lock() // global lock (via ensure_symbol_index) so it cannot stall concurrent
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))?; // searches.
let index = guard.get_or_insert_with(SymbolIndex::new); let count = ensure_symbol_index(&workspace, true)?;
let count = index.rebuild(&workspace)?; let map = symbol_index()?;
let by_lang = index.count_by_language(); let by_lang = match map.get(&workspace) {
Some(i) => i.count_by_language(),
None => Vec::new(),
};
let mut out = format!( let mut out = format!(
"Symbol index rebuilt successfully. {} symbols indexed.\n\n", "Symbol index rebuilt successfully. {} symbols indexed.\n\n",
@@ -1497,15 +1566,11 @@ impl Tool for ListSymbols {
.map(|p| p.to_string_lossy().to_string()) .map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|| ".".to_string()); .unwrap_or_else(|| ".".to_string());
let mut guard = SYMBOL_INDEX // Build (or load) the per-workspace index without holding the global
.lock() // lock across the I/O-heavy walk.
.map_err(|e| anyhow::anyhow!("index lock failed: {e}"))?; let _count = ensure_symbol_index(&workspace, rebuild)?;
let index = guard.get_or_insert_with(SymbolIndex::new); let map = symbol_index()?;
let index = map.get(&workspace).expect("index should be ensured");
if rebuild || index.is_empty() {
let count = index.rebuild(&workspace)?;
info!(symbol_count = count, "symbol index rebuilt for list");
}
let target_lang = match lang_filter { let target_lang = match lang_filter {
"rust" => Some(Language::Rust), "rust" => Some(Language::Rust),
@@ -1746,4 +1811,80 @@ mod tests {
let index = SymbolIndex::new(); let index = SymbolIndex::new();
assert!(index.search("anything", 10).is_empty()); assert!(index.search("anything", 10).is_empty());
} }
#[test]
fn test_needs_rebuild_workspace_aware() {
let ws_a = std::env::temp_dir().join(format!("ws_a_{}", uuid::Uuid::new_v4()));
let ws_b = std::env::temp_dir().join(format!("ws_b_{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&ws_a).unwrap();
std::fs::create_dir_all(&ws_b).unwrap();
std::fs::write(ws_a.join("a.rs"), "pub fn fn_in_a() {}\n").unwrap();
std::fs::write(ws_b.join("b.rs"), "pub fn fn_in_b() {}\n").unwrap();
let mut index = SymbolIndex::new();
let a = ws_a.to_string_lossy().to_string();
let b = ws_b.to_string_lossy().to_string();
// Fresh index: needs rebuild for any workspace.
assert!(index.needs_rebuild(&a));
// After rebuilding A, searching A needs no rebuild...
index.rebuild(&a).unwrap();
assert!(!index.needs_rebuild(&a));
// ...but searching B DOES (stale index otherwise).
assert!(
index.needs_rebuild(&b),
"workspace switch must trigger rebuild"
);
// Rebuilding B flips the cached workspace.
index.rebuild(&b).unwrap();
assert!(!index.needs_rebuild(&b));
assert!(index.needs_rebuild(&a));
std::fs::remove_dir_all(&ws_a).ok();
std::fs::remove_dir_all(&ws_b).ok();
}
#[test]
fn test_ensure_symbol_index_per_workspace_isolation() {
let ws_a = std::env::temp_dir().join(format!("iso_a_{}", uuid::Uuid::new_v4()));
let ws_b = std::env::temp_dir().join(format!("iso_b_{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&ws_a).unwrap();
std::fs::create_dir_all(&ws_b).unwrap();
std::fs::write(ws_a.join("a.rs"), "pub fn only_in_a() {}\n").unwrap();
std::fs::write(ws_b.join("b.rs"), "pub fn only_in_b() {}\n").unwrap();
let a = ws_a.to_string_lossy().to_string();
let b = ws_b.to_string_lossy().to_string();
// Build A and B independently through the shared global helper.
let count_a = ensure_symbol_index(&a, false).unwrap();
assert!(
count_a >= 1,
"workspace A should index its fn, got {count_a}"
);
let count_b = ensure_symbol_index(&b, false).unwrap();
assert!(
count_b >= 1,
"workspace B should index its fn, got {count_b}"
);
// Rebuilding A must not have clobbered B and vice-versa.
let count_a_again = ensure_symbol_index(&a, true).unwrap();
assert!(count_a_again >= 1);
// Each workspace's cached index is independently correct.
{
let map = symbol_index().unwrap();
let idx_a = map.get(&a).unwrap();
assert!(!idx_a.search("only_in_a", 5).is_empty());
assert!(idx_a.search("only_in_b", 5).is_empty());
let idx_b = map.get(&b).unwrap();
assert!(!idx_b.search("only_in_b", 5).is_empty());
}
std::fs::remove_dir_all(&ws_a).ok();
std::fs::remove_dir_all(&ws_b).ok();
}
} }
+21
View File
@@ -320,6 +320,18 @@ fn handle_submit_input(state: &mut AppStateRest, text: String) {
api_base: provider_cfg.as_ref().map(|cfg| cfg.api_base.clone()), api_base: provider_cfg.as_ref().map(|cfg| cfg.api_base.clone()),
}; };
// Capture state for the optional background auto-review so it can run
// with the same resolved provider. Done here, before `api_key` /
// `provider_cfg` are moved into the client below. The reviewer is
// fire-and-forget and skips itself when the workspace has no diff.
let review_enabled = state.settings.flags.review_enabled;
let review_key = api_key.clone();
let review_model =
zesdex_domain::cms::resolve_effective_model(&state.settings, &state.app_config);
let review_base = provider_cfg.as_ref().map(|c| c.api_base.clone());
let review_ws = params.workspace_roots.clone();
let review_events = params.turn_events.clone();
let client = std::sync::Arc::new(zesdex_infrastructure::llm::provider::LlmClient::new( let client = std::sync::Arc::new(zesdex_infrastructure::llm::provider::LlmClient::new(
api_key, api_key,
zesdex_domain::cms::resolve_effective_model(&state.settings, &state.app_config), zesdex_domain::cms::resolve_effective_model(&state.settings, &state.app_config),
@@ -348,6 +360,15 @@ fn handle_submit_input(state: &mut AppStateRest, text: String) {
use zesdex_application::agent::AgentTurnService; use zesdex_application::agent::AgentTurnService;
tokio::spawn(async move { tokio::spawn(async move {
let _ = turn_service.run_turn(params).await; let _ = turn_service.run_turn(params).await;
if review_enabled {
zesdex_infrastructure::subagent::auto::engine::spawn_background_review(
review_ws,
review_events,
review_key,
review_model,
review_base,
);
}
}); });
} }
+19
View File
@@ -110,6 +110,16 @@ pub fn spawn_agent_turn(state: &mut AppStateRest, text: String) {
api_base: api_base.clone(), api_base: api_base.clone(),
}; };
// Capture for the optional background auto-review before `api_key` /
// `model` / `api_base` move into the client below. The reviewer is
// fire-and-forget and skips itself when the workspace has no diff.
let review_enabled = state.settings.flags.review_enabled;
let review_key = api_key.clone();
let review_model = model.clone();
let review_base = api_base.clone();
let review_ws = workspace_roots.clone();
let review_events = turn_events.clone();
let client = std::sync::Arc::new(LlmClient::new(api_key, model, api_base)); let client = std::sync::Arc::new(LlmClient::new(api_key, model, api_base));
let tool_ctx = ToolCtx::builder() let tool_ctx = ToolCtx::builder()
@@ -127,6 +137,15 @@ pub fn spawn_agent_turn(state: &mut AppStateRest, text: String) {
tokio::spawn(async move { tokio::spawn(async move {
let _ = turn_service.run_turn(params).await; let _ = turn_service.run_turn(params).await;
if review_enabled {
zesdex_infrastructure::subagent::auto::engine::spawn_background_review(
review_ws,
review_events,
review_key,
review_model,
review_base,
);
}
}); });
} }
+18
View File
@@ -130,6 +130,17 @@ async fn handle_socket(mut socket: WebSocket, state: Arc<WsState>) {
api_base: None, api_base: None,
}; };
// Capture for the optional background auto-review
// before `api_key`/`model` move into the client.
// This minimal WS channel has no settings toggle, so
// review fires whenever a prompt runs (consistent
// with the default review_enabled=true).
let review_key = api_key.clone();
let review_model = model.clone();
let review_base = None;
let review_ws = workspace_roots.clone();
let review_events = turn_events.clone();
let client = std::sync::Arc::new( let client = std::sync::Arc::new(
zesdex_infrastructure::llm::provider::LlmClient::new( zesdex_infrastructure::llm::provider::LlmClient::new(
api_key, model, None, api_key, model, None,
@@ -159,6 +170,13 @@ async fn handle_socket(mut socket: WebSocket, state: Arc<WsState>) {
use zesdex_application::agent::AgentTurnService; use zesdex_application::agent::AgentTurnService;
tokio::spawn(async move { tokio::spawn(async move {
let _ = turn_service.run_turn(params).await; let _ = turn_service.run_turn(params).await;
zesdex_infrastructure::subagent::auto::engine::spawn_background_review(
review_ws,
review_events,
review_key,
review_model,
review_base,
);
}); });
let tx_clone = tx.clone(); let tx_clone = tx.clone();