Skip to content

Commit 9650937

Browse files
laststylebender14tusharmathautofix-ci[bot]
authored
fix(sync): use env-based batch size for consistent file-read concurrency (#2613)
Co-authored-by: Tushar Mathur <tusharmath@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 5e784a1 commit 9650937

14 files changed

Lines changed: 422 additions & 327 deletions

File tree

‎crates/forge_api/src/api.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ pub trait API: Sync + Send {
207207
async fn sync_workspace(
208208
&self,
209209
path: PathBuf,
210-
batch_size: usize,
211210
) -> Result<MpscStream<Result<forge_domain::SyncProgress>>>;
212211

213212
/// Query the indexed workspace

‎crates/forge_api/src/forge_api.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,8 @@ impl<
360360
async fn sync_workspace(
361361
&self,
362362
path: PathBuf,
363-
batch_size: usize,
364363
) -> Result<MpscStream<Result<forge_domain::SyncProgress>>> {
365-
self.services.sync_workspace(path, batch_size).await
364+
self.services.sync_workspace(path).await
366365
}
367366

368367
async fn query_workspace(

‎crates/forge_app/src/services.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ pub trait WorkspaceService: Send + Sync {
305305
async fn sync_workspace(
306306
&self,
307307
path: PathBuf,
308-
batch_size: usize,
309308
) -> anyhow::Result<forge_stream::MpscStream<anyhow::Result<SyncProgress>>>;
310309

311310
/// Query the indexed workspace with semantic search
@@ -1110,11 +1109,8 @@ impl<I: Services> WorkspaceService for I {
11101109
async fn sync_workspace(
11111110
&self,
11121111
path: PathBuf,
1113-
batch_size: usize,
11141112
) -> anyhow::Result<forge_stream::MpscStream<anyhow::Result<SyncProgress>>> {
1115-
self.workspace_service()
1116-
.sync_workspace(path, batch_size)
1117-
.await
1113+
self.workspace_service().sync_workspace(path).await
11181114
}
11191115

11201116
async fn query_workspace(

‎crates/forge_main/src/built_in_commands.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
"command": "sync-info",
104104
"description": "Show workspace information with sync details"
105105
},
106+
{
107+
"command": "sync-init",
108+
"description": "Initialize a new workspace without syncing files"
109+
},
106110
{
107111
"command": "clone",
108112
"description": "Clone and manage conversation context"

‎crates/forge_main/src/cli.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,10 @@ pub enum WorkspaceCommand {
242242
#[arg(default_value = ".")]
243243
path: PathBuf,
244244

245-
/// Number of files to process concurrently
246-
#[arg(long, default_value = "100")]
247-
batch_size: usize,
245+
/// Automatically initialize the workspace before syncing if it has not
246+
/// been initialized yet.
247+
#[arg(long)]
248+
init: bool,
248249
},
249250
/// List all workspaces.
250251
List {

‎crates/forge_main/src/ui.rs‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
600600
}
601601
TopLevelCommand::Workspace(index_group) => {
602602
match index_group.command {
603-
crate::cli::WorkspaceCommand::Sync { path, batch_size } => {
604-
self.on_index(path, batch_size).await?;
603+
crate::cli::WorkspaceCommand::Sync { path, init } => {
604+
self.on_index(path, init).await?;
605605
}
606606
crate::cli::WorkspaceCommand::List { porcelain } => {
607607
self.on_list_workspaces(porcelain).await?;
@@ -1980,8 +1980,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
19801980
}
19811981
SlashCommand::Index => {
19821982
let working_dir = self.state.cwd.clone();
1983-
// Use default batch size of 100 for slash command
1984-
self.on_index(working_dir, 100).await?;
1983+
self.on_index(working_dir, false).await?;
19851984
}
19861985
SlashCommand::AgentSwitch(agent_id) => {
19871986
// Validate that the agent exists by checking against loaded agents
@@ -3634,11 +3633,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
36343633
Ok(())
36353634
}
36363635

3637-
async fn on_index(
3638-
&mut self,
3639-
path: std::path::PathBuf,
3640-
batch_size: usize,
3641-
) -> anyhow::Result<()> {
3636+
async fn on_index(&mut self, path: std::path::PathBuf, init: bool) -> anyhow::Result<()> {
36423637
use forge_domain::SyncProgress;
36433638
use forge_spinner::ProgressBarManager;
36443639

@@ -3647,7 +3642,17 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
36473642
self.init_forge_services().await?;
36483643
}
36493644

3650-
let mut stream = self.api.sync_workspace(path.clone(), batch_size).await?;
3645+
// When init is set, check if the workspace is already initialized
3646+
// via get_workspace_info before calling init, so we only initialize
3647+
// when a workspace does not yet exist for the given path.
3648+
if init {
3649+
let workspace_info = self.api.get_workspace_info(path.clone()).await?;
3650+
if workspace_info.is_none() {
3651+
self.on_workspace_init(path.clone()).await?;
3652+
}
3653+
}
3654+
3655+
let mut stream = self.api.sync_workspace(path.clone()).await?;
36513656
let mut progress_bar = ProgressBarManager::default();
36523657

36533658
while let Some(event) = stream.next().await {
@@ -3998,19 +4003,20 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
39984003

39994004
/// Initialize workspace for a directory without syncing files
40004005
async fn on_workspace_init(&mut self, path: std::path::PathBuf) -> anyhow::Result<()> {
4006+
// Check if auth already exists and create if needed
4007+
if !self.api.is_authenticated().await? {
4008+
self.init_forge_services().await?;
4009+
}
4010+
40014011
self.spinner.start(Some("Initializing workspace"))?;
40024012

40034013
let workspace_id = self.api.init_workspace(path.clone()).await?;
40044014

40054015
self.spinner.stop(None)?;
40064016

4007-
// Resolve and display the path
4008-
let canonical_path = path.canonicalize().unwrap_or_else(|_| path.clone());
4009-
40104017
self.writeln_title(
40114018
TitleFormat::info("Workspace initialized successfully")
4012-
.sub_title(format!("Path: {}", canonical_path.display()))
4013-
.sub_title(format!("Workspace ID: {}", workspace_id)),
4019+
.sub_title(format!("{}", workspace_id)),
40144020
)?;
40154021

40164022
Ok(())

0 commit comments

Comments
 (0)