Skip to content

fix(web): backend agent server-mode query routing and API compatibility#202

Closed
madmansn0w wants to merge 2 commits into
abhigyanpatwari:mainfrom
madmansn0w:codex/fix-backend-agent-and-api-url
Closed

fix(web): backend agent server-mode query routing and API compatibility#202
madmansn0w wants to merge 2 commits into
abhigyanpatwari:mainfrom
madmansn0w:codex/fix-backend-agent-and-api-url

Conversation

@madmansn0w

Copy link
Copy Markdown

Summary

Fix backend-mode agent behavior in gitnexus-web when connected to gitnexus serve, including query routing and API compatibility issues that led to false “empty codebase” results.

What this PR fixes

  1. Backend agent initialization in server mode
  • Ensure server-mode sessions initialize the backend-aware agent path (instead of local-only assumptions).
  • Preserve proper repo context during server connection and settings re-init flows.
  1. Server-mode query routing (runBackendQuery)
  • Route Cypher tool queries through backend HTTP when in server mode.
  • Avoid querying local WASM DB paths for server-backed repos.
  1. Backend API URL normalization
  • Fix worker HTTP wrapper so it handles both:
    • http://host:port
    • http://host:port/api
  • Prevent accidental .../api/api/query and .../api/api/search requests.
  1. /api/search response compatibility
  • Support both backend response shapes:
    • grouped (process_symbols, definitions)
    • legacy/flat (results: [...])
  • Prevent valid search responses from being interpreted as empty.

Files changed

  • gitnexus-web/src/App.tsx
  • gitnexus-web/src/hooks/useAppState.tsx
  • gitnexus-web/src/workers/ingestion.worker.ts

User-visible impact

  • Backend-connected chat no longer reports “codebase is empty” when repos are indexed and queryable.
  • Cypher/Search tools work reliably for server-backed repos (crank, crank-control, mentat).
  • Backend mode is resilient across minor backend URL/config differences.

Notes

  • Scope is intentionally limited to backend-mode wiring and HTTP compatibility.
  • No schema/API contract changes required.

@vercel

vercel Bot commented Mar 6, 2026

Copy link
Copy Markdown

@madmansn0w is attempting to deploy a commit to the NexusCore Team on Vercel.

A member of the Team first needs to authorize it.

@reversTeam reversTeam left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good set of changes addressing server-mode query routing. The overall direction is sound. A few observations and questions:

Strengths:

  • buildBackendApiUrl is a solid utility — handles both cases where the user provides a URL ending in /api or just the base URL. This prevents the /api/api/query double-prefix bug.
  • createHttpOptionalExecuteQuery is a nice pattern for non-critical context queries — swallowing 404s for buildCodebaseContext prevents hard failures when the backend lacks the /api/query endpoint.
  • The isServerMode state flag cleanly separates local vs. server workflows, preventing WASM embedding pipelines from running in server mode (which would be pointless).
  • Backward compatibility handling in createHttpHybridSearch for older backends returning flat arrays is a good defensive measure.

Concerns / suggestions:

  1. handleServerConnect signature change — The callback now takes (result, baseUrl) as arguments, but setServerBaseUrl(baseUrl) is also called again in the auto-connect flow after handleServerConnect (line ~203 in App.tsx). This means setServerBaseUrl is called twice during auto-connect. Consider removing the duplicate call.

  2. Indentation inconsistency in initializeBackendAgent — The function body uses 2-space indentation while it's inside a useCallback that starts at a different level. The try/catch/finally blocks appear to be at the wrong indentation level (they're flush with the outer scope rather than indented inside the function body). This won't affect runtime behavior, but it makes the code harder to read.

  3. Indentation issue in switchRepo — Around the initializeBackendAgent call and the setEmbeddingStatus/setEmbeddingProgress lines, the indentation shifts unexpectedly (extra indent). Looks like a formatting artifact.

  4. runBackendQuery in worker — This new method creates a fresh createHttpExecuteQuery closure on every call. If it's called frequently, consider caching the executor per (backendUrl, repo) pair. If it's rarely called, this is fine as-is.

  5. Embedding skip in server modestartEmbeddings now returns early when isServerMode is true, and the server-connect flow sets setEmbeddingStatus('ready') without actually running embeddings. This is correct behavior (server handles embeddings), but the ready status might confuse the UI into showing "embeddings available" when they're actually on the server side. Worth verifying the UI handles this correctly.

Not blocking, but the indentation issues in particular would be nice to clean up before merging.

@madmansn0w

madmansn0w commented Mar 9, 2026

Copy link
Copy Markdown
Author

Implemented the review follow-ups in this PR branch and pushed commit 849a1b4.

What changed:

  • Removed duplicate setServerBaseUrl(baseUrl) in auto-connect flow; handleServerConnect(result, baseUrl) is now the single path setting server URL in App.
  • Updated onboarding server connect callback to normalize serverUrl ?? window.location.origin, pass that same baseUrl into handleServerConnect, and fetch repos from the same URL.
  • Cleaned App effect/callback dependencies accordingly.
  • Fixed indentation/formatting issues in initializeBackendAgent and switchRepo in useAppState.
  • Updated server-mode repo-switch semantics to set embedding status to idle (instead of ready) and clear progress.
  • Added cached HTTP query executors in ingestion.worker.ts keyed by (backendUrl, repo) and switched runBackendQuery to reuse the cached executor (also reused in backend-agent init path).

Validation:

  • npm --prefix gitnexus-web run build passes locally.

@magyargergo

Copy link
Copy Markdown
Collaborator

⚠️ Upcoming Prettier formatting — rebase instructions

PR #563 adds Prettier as the code formatter for the repo. When it merges, the bulk format commit will touch ~350 files (style-only: whitespace, quotes, trailing commas). Your branch will likely conflict.

After #563 merges, rebase your branch:

git fetch origin
git checkout <your-branch>
git rebase origin/main

# Conflicts will be formatting-only — accept your version:
git checkout --theirs .
git add .
git rebase --continue

# Then re-format your branch to match the new style:
npx prettier --write .
git add -A
git commit -m "style: apply prettier formatting"
git push --force-with-lease

New setup step: Run npm install at the repo root (not just in gitnexus/) to get prettier + activate the pre-commit hook. The hook auto-formats staged files on every commit going forward.

@magyargergo

Copy link
Copy Markdown
Collaborator

Please submit a new PR if this is still relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants