Repository navigation
Add ImportService gRPC: proto definition, nodespaced handler, and Tauri proxy (closes #1136) - #1154
Conversation
malibio
left a comment
There was a problem hiding this comment.
Code Review Summary
This PR successfully migrates bulk markdown import from the Tauri process into nodespaced over gRPC, which is the correct architectural move under ADR-031. The proto definition is well-structured, the two-phase pipeline is correctly preserved, and the Tauri proxy is properly thinned out. The change is a definitive net improvement to the codebase.
All acceptance criteria are met except for one — there are no new tests for ImportService itself (the integration test suite covers NodeService round-trips but has no import-specific test). This is the primary concern to address before merge.
Findings
Critical Issues
None.
Suggested Improvements
[Improvement] packages/daemon/src/services/import_service.rs — No integration test for ImportService
The issue requires "bun run test:all passes" but there is no new test exercising the import gRPC path. grpc_round_trip.rs only covers NodeService. The import handler touches non-trivial logic: the two-phase pipeline, collection routing, the CHANNEL_BUFFER=64 back-pressure, and the final-event-carries-results contract. A minimal test (spin up in-process server, call ImportMarkdown with a temp .md file, drain the stream, assert step==9 and success==true) would close the gap between the existing coverage and what this PR adds.
[Improvement] packages/daemon/src/services/import_service.rs lines 1070–1228 — Silent bulk-create failure in Phase 2 background task does not surface to the caller
match node_service_clone
.bulk_create_hierarchy_trusted(all_nodes)
.await
{
Ok(ids) => tracing::info!("Bulk created {} nodes", ids.len()),
Err(e) => tracing::error!("Failed to bulk create nodes: {:?}", e),
}If bulk_create_hierarchy_trusted fails, the error is logged but the stream still sends a step=9 / complete event with success=true for all prepared files. The client (CLI or Tauri) therefore receives a successful result for files that were never written to the database. The Phase 2 task should either mark results as failed and send those in the final event, or send an error-typed event. At minimum, the final summary count should reflect actual DB outcomes, not Phase 1 parse outcomes.
[Improvement] packages/cli/src/commands/import.rs lines 162–163 — Magic constant 9 for final step
if event.step == 9 {This appears in four places across the CLI and Tauri proxy. The proto comment documents 9 = complete but there is no shared constant or enum. A const STEP_COMPLETE: u32 = 9; in the daemon crate (or a proto enum) would make intent explicit and eliminate the risk of one site being updated while others are not.
[Improvement] packages/daemon/src/services/import_service.rs lines 830–851 — base_dir fallback uses first file's parent, not the common ancestor
let base_dir = if !opts.base_directory.is_empty() {
PathBuf::from(&opts.base_directory)
} else {
file_paths
.first()
.map(|p| {
PathBuf::from(p)
.parent()
...
})
...
};When base_directory is empty and files come from multiple directories, the routing falls back to the first file's parent. This can produce inconsistent collection assignments depending on file ordering. This is a pre-existing behavior inherited from the original commands/import.rs, but now that the daemon owns this logic, documenting the known limitation (or asserting that base_directory must be set for multi-directory batches) would prevent silent mis-routing.
[Improvement] packages/desktop-app/src-tauri/src/commands/import.rs line 2284 — import_markdown_file returns an error if the stream closes without a result event
last_result.ok_or_else(|| "Import stream ended without a result".to_string())This is the right approach, but the error string surfaced to the Tauri frontend is opaque. If the daemon crashes mid-import the user sees "Import stream ended without a result" with no context. Adding the file path to the message (format!("Import stream ended without a result for {}", file_path)) makes the frontend error actionable.
[Improvement] packages/daemon/src/services/import_service.rs — import_markdown_content (run_single_file_import path) duplicates node creation logic from the batch path
The single-file path calls create_node_with_parent + bulk_create_hierarchy_root_notify, while the batch path calls bulk_create_hierarchy_trusted. This means single-file imports trigger per-node notification events while batch imports do not, which is an intentional difference inherited from the original code — but the divergence now lives inside the daemon where it is less visible. A comment at the top of import_markdown_content explaining why it uses root_notify vs trusted would prevent accidental unification that breaks notification semantics.
Nitpicks
-
Nit:
packages/daemon/proto/import_service.protoline 433 — the comment"file_result populated for single-file RPC"onImportProgressEvent.resultsis slightly misleading; both RPCs populate results on step 9. Worth updating to"Populated on the final event (step=9) with per-file import results for both RPCs". -
Nit:
packages/cli/src/commands/import.rslines 148–149 —exclude_patterns: vec![]andbase_directory: String::new()are set unconditionally for the single-file path even thoughImportFileArgshas noexclude_patternsfield. These are proto defaults and are harmless, but shadowing them explicitly whileImportFileArgshas no corresponding fields adds slight confusion. A comment noting these are unused for single-file RPCs would help. -
Nit:
packages/daemon/src/services/import_service.rs—FileReadResult.relative_pathis constructed but only used for display infilenamefallback. The field could be removed in favour of computing the display name inline at the single call site, reducing the struct footprint. -
Nit:
packages/daemon/src/services/import_service.rslines 1094–1101 — the large anonymous tuple typeVec<(String, String, String, Option<String>, f64, serde_json::Value)>appears twice (single-file path and batch path). Extracting this as a type aliastype BulkNodeTuple = (String, String, String, Option<String>, f64, serde_json::Value)would reduce noise.
Acceptance Criteria Status
| Criterion | Status |
|---|---|
ImportService proto defined and compiled via tonic-build |
Done |
| nodespaced handler implements two-phase import with smart collection routing | Done |
| Progress streamed back via gRPC server-streaming RPC | Done |
commands/import.rs proxies via gRPC; no direct packages/core imports remain |
Done |
| Import completes if Tauri window is closed mid-import | Done (daemon-side background task) |
nodespace import <file> CLI subcommand works |
Done |
cargo build succeeds |
Cannot verify in review — author must confirm |
bun run test:all passes |
No new import-specific tests added (see Improvement above) |
bun run quality:fix passes |
Cannot verify in review — author must confirm |
The silent-failure-on-bulk-create-error issue and the missing integration test are the two items most worth addressing before merge. Everything else is polish.
|
Addressed the two review findings from the initial review: 1. Silent bulk-insert failure (🔴 Critical) — fixed Added a 2. No integration test (🟡 Important) — added New
All 1182 Rust tests pass; |
…ri proxy (closes #1136) - `packages/daemon/proto/import_service.proto`: ImportService with ImportMarkdown and ImportMarkdownFiles server-streaming RPCs - `packages/daemon/src/services/import_service.rs`: handler preserving two-phase pipeline (parse → background DB write) and smart collection routing from commands/import.rs - `packages/daemon/src/main.rs`: registers ImportServiceServer alongside NodeServiceServer in both headless and tray server loops - `packages/desktop-app/src-tauri/src/commands/import.rs`: replaced direct nodespace-core calls with thin gRPC proxy; imports now survive Tauri window close - `packages/desktop-app/src-tauri/src/services/grpc_client.rs`: added ImportServiceClient to the in-process server; exposes import_client() - `packages/cli/src/commands/import.rs`: `nodespace import file` and `nodespace import dir` subcommands via ImportServiceClient - Fixed pre-existing CreateNodeRequest struct literal errors in grpc_round_trip.rs, cli/commands/node.rs, and cli_integration.rs (id and insert_after_node_id fields added in #1147 but not propagated) Co-Authored-By: Claude <[email protected]>
- Surface bulk DB write failures to gRPC callers (bulk_insert_failed flag marks all phase1 results as failed rather than silently reporting success) - Add import_round_trip.rs: 3 in-process gRPC tests covering single-file import, batch import, and missing-file error surfacing Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
ca62981 to
32a9944
Compare
…ri proxy (closes #1136) (#1154) * Add ImportService gRPC: proto definition, nodespaced handler, and Tauri proxy (closes #1136) - `packages/daemon/proto/import_service.proto`: ImportService with ImportMarkdown and ImportMarkdownFiles server-streaming RPCs - `packages/daemon/src/services/import_service.rs`: handler preserving two-phase pipeline (parse → background DB write) and smart collection routing from commands/import.rs - `packages/daemon/src/main.rs`: registers ImportServiceServer alongside NodeServiceServer in both headless and tray server loops - `packages/desktop-app/src-tauri/src/commands/import.rs`: replaced direct nodespace-core calls with thin gRPC proxy; imports now survive Tauri window close - `packages/desktop-app/src-tauri/src/services/grpc_client.rs`: added ImportServiceClient to the in-process server; exposes import_client() - `packages/cli/src/commands/import.rs`: `nodespace import file` and `nodespace import dir` subcommands via ImportServiceClient - Fixed pre-existing CreateNodeRequest struct literal errors in grpc_round_trip.rs, cli/commands/node.rs, and cli_integration.rs (id and insert_after_node_id fields added in #1147 but not propagated) Co-Authored-By: Claude <[email protected]> * Fix silent bulk-insert failure and add ImportService integration tests - Surface bulk DB write failures to gRPC callers (bulk_insert_failed flag marks all phase1 results as failed rather than silently reporting success) - Add import_round_trip.rs: 3 in-process gRPC tests covering single-file import, batch import, and missing-file error surfacing Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude <[email protected]>
Summary
ImportServicein a newimport_service.protowith server-streamingImportMarkdownandImportMarkdownFilesRPCsImportServiceImplinnodespaced, preserving the two-phase pipeline (parse → background DB write) and smart collection routing from the original Tauri commandscommands/import.rsin the Tauri app to a thin gRPC proxy; all import logic now runs in the daemon (survives window close)nodespace import fileandnodespace import dirCLI subcommandsCreateNodeRequeststruct literal errors in three test/integration filesTest plan
cargo buildsucceeds with no errorsbun run test:allpasses with no new failuresbun run quality:fixpasses cleannodespace import file <path>streams progress and reports successnodespace import dir <path>imports all .md files recursivelyimport_markdown_fileandimport_markdown_filescommands work via gRPC proxy🤖 Generated with Claude Code