Skip to content

chore: fix replay when self host#1102

Merged
Wendong-Fan merged 5 commits into
mainfrom
fix-replay-in-self-host
Feb 1, 2026
Merged

chore: fix replay when self host#1102
Wendong-Fan merged 5 commits into
mainfrom
fix-replay-in-self-host

Conversation

@fengju0213

Copy link
Copy Markdown
Collaborator

🐞 Root Cause

The local Electron app always overwrote SERVER_URL when spawning the backend,
forcing it to: https://dev.eigent.ai/api

As a result:

  • Step events were synced to the cloud instead of the local server
  • The local server had no step data
  • Local replay got stuck with no steps to replay

✅ Fix

Updated the Electron backend launcher to:

  • Read SERVER_URL from ~/.eigent/.env or existing environment variables
  • Only fall back to the cloud URL if SERVER_URL is not provided

After restarting the app and running a new task:

  • Step events are stored locally
  • Local replay works as expected

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@fengju0213 fengju0213 linked an issue Jan 28, 2026 that may be closed by this pull request

@Wendong-Fan Wendong-Fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice fix! The root cause analysis is solid and the multi-source resolution approach makes sense. Left a few inline comments on edge cases that could bite us in production.

Comment thread electron/main/init.ts Outdated
if (!fs.existsSync(filePath)) return undefined;
const content = fs.readFileSync(filePath, 'utf-8');
const lines = content.split(/\r?\n/);
const line = lines.find((l) => l.trim() && !l.trim().startsWith('#') && l.startsWith(`${key}=`));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small inconsistency here: l.trim() is used for the empty/comment checks, but l.startsWith(...) runs on the raw (untrimmed) line. So if someone has a leading space like SERVER_URL=xxx in their .env, the trim checks pass but the key match fails silently.

Suggestion: store l.trim() in a variable and use it for all checks:

const line = lines.find((l) => {
    const trimmed = l.trim();
    return trimmed && !trimmed.startsWith('#') && trimmed.startsWith(`${key}=`);
});

Comment thread electron/main/init.ts Outdated
const lines = content.split(/\r?\n/);
const line = lines.find((l) => l.trim() && !l.trim().startsWith('#') && l.startsWith(`${key}=`));
if (!line) return undefined;
return line.slice(key.length + 1).trim();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will break if the .env value is quoted, e.g. SERVER_URL="https://my-server.com/api". The returned value would include the surrounding quotes, making the URL invalid.

Worth adding a strip for single/double quotes after the trim:

let value = line.trim().slice(key.length + 1).trim();
if ((value.startsWith('"') && value.endsWith('"')) ||
    (value.startsWith("'") && value.endsWith("'"))) {
    value = value.slice(1, -1);
}
return value;

(Also note: since we changed to matching on trimmed, need line.trim().slice(...) here too.)

Comment thread electron/main/init.ts Outdated
if (!proxyUrl) return undefined;
const trimmed = proxyUrl.trim().replace(/\/+$/, '');
if (!trimmed) return undefined;
return `${trimmed}/api`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If someone already has /api in their proxy URL (e.g. VITE_PROXY_URL=http://localhost:8000/api), this would produce http://localhost:8000/api/api.

Quick guard before appending:

if (trimmed.endsWith('/api')) return trimmed;
return `${trimmed}/api`;

Comment thread electron/main/init.ts Outdated

const devServerUrl = process.env.VITE_DEV_SERVER_URL;
if (!resolvedServerUrl && devServerUrl) {
const devEnvPath = path.join(process.cwd(), '.env.development');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

process.cwd() is unreliable in packaged Electron apps. It varies depending on how the user launched the app (Finder, terminal, Spotlight, etc.). Since this block only runs when VITE_DEV_SERVER_URL is set (i.e. during dev), app.getAppPath() would be a safer choice here and still point to the project root.

@Wendong-Fan Wendong-Fan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

added commit 67e42f5

@Wendong-Fan Wendong-Fan added this to the Sprint 12 milestone Feb 1, 2026
@Wendong-Fan Wendong-Fan merged commit 6dc6db7 into main Feb 1, 2026
6 checks passed
@fengju0213

Copy link
Copy Markdown
Collaborator Author

thanks! @Wendong-Fan

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.

[BUG] Failed to load previous project

2 participants