Skip to content

fix: send rootResourcePath instead of rootDoc_id in compile request#356

Merged
iamhyc merged 2 commits into
overleaf-workshop:masterfrom
riccardogibello:fix/compile-rootresourcepath
Mar 31, 2026
Merged

fix: send rootResourcePath instead of rootDoc_id in compile request#356
iamhyc merged 2 commits into
overleaf-workshop:masterfrom
riccardogibello:fix/compile-rootresourcepath

Conversation

@riccardogibello

Copy link
Copy Markdown
Contributor

Fixes #355

Fix: Compile failure — rootResourcePath is missing in request body

Problem

Every time a save is performed, it triggers a compile request that fails with a 400 error from Overleaf's API:

Compile failure. 400: {"error":"rootResourcePath is missing in request body"}

This causes a permanent red flag in the VS Code status bar and no PDF output in .output, even though the project compiles successfully on overleaf.com directly.

Root Cause

Overleaf's compile API expects a rootResourcePath field containing the file path of the root document (e.g. "main.tex"). However, the extension was sending rootDoc_id — a MongoDB document ID (e.g. "69c4fd3d5256760243b6e292") — which is a completely different field that the API does not accept as a substitute for rootResourcePath.

The bug has two parts:

  1. src/api/base.ts — The compile request body included rootDoc_id but never included rootResourcePath.

  2. src/core/remoteFileSystemProvider.ts — The compile() method passed the raw MongoDB ID directly to the API without resolving it to a file path first.

The ID was available and correct (confirmed via debugging) — it just needed to be resolved to a path using the existing _resolveById() method before being sent.

Fix

src/api/base.ts — Add rootResourcePath to the compile request body (the parameter is renamed accordingly):

async compile(identity, projectId, rootResourcePath, draft = false, stopOnFirstError = false) {
    const body = {
        check: 'silent',
        draft,
        incrementalCompilesEnabled: true,
        rootResourcePath,   // file path e.g. "main.tex"
        stopOnFirstError
    };
    ...
}

src/core/remoteFileSystemProvider.ts — Resolve the MongoDB ID to a file path before calling the API:

// compile project
const resolvedRootDocId = rootDocId ?? this.root?.rootDoc_id ?? null;
const rootResourcePath = resolvedRootDocId
    ? (this._resolveById(resolvedRootDocId)?.path ?? '').replace(/^\//, '')
    : null;
const res = await this.api.compile(identity, this.projectId, rootResourcePath, draft, stopOnFirstError);

The .replace(/^\//, '') strips the leading / from the path returned by _resolveById(), giving a clean relative path like main.tex rather than /main.tex.

Testing

Verified locally on:

  • Overleaf Workshop: 0.15.7
  • VS Code: 1.113.0 (x64, .deb install on Ubuntu Linux)
  • Overleaf: www.overleaf.com (official server)

After the fix, saving a .tex file triggers a successful compile, the PDF appears in .output, and the red flag is gone.

Notes

  • The rootDoc_id field in the request body has been removed since it was never a valid field for Overleaf's compile API — only rootResourcePath is required.
  • This fix does not change any other behaviour; if rootResourcePath resolves to null (no root doc set), the compile request omits it, which matches the previous behaviour.

@NixonZ

NixonZ commented Mar 27, 2026

Copy link
Copy Markdown

This fix is working for me too.

@Zhuhan-J Zhuhan-J mentioned this pull request Mar 27, 2026
@himalalps

Copy link
Copy Markdown

This does work for me.

@rikoras

rikoras commented Mar 28, 2026

Copy link
Copy Markdown

works for me. tks!

@MaxCrisafulli

Copy link
Copy Markdown

This worked, thank you!

For anyone on MacOS, the relevant files were in:
~/.vscode/extensions/.vscode/extensions/iamhyc.overleaf-workshop-0.15.7/out/api/base.js
and
~/.vscode/extensions/iamhyc.overleaf-workshop-0.15.7/out/core/remoteFileSystemProvider.js

@salehisaeed

Copy link
Copy Markdown

Thanks! Worked for me as well.

@mashdtu

mashdtu commented Mar 28, 2026

Copy link
Copy Markdown

i love you

@iamhyc iamhyc requested review from QianrenLi, iamhyc and zeyugao and removed request for QianrenLi March 29, 2026 03:48
@iamhyc

iamhyc commented Mar 29, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! I wonder if it works for the older version, will do a quick check.

Updated: Intuitively, you can pass both rootDoc_id and rootResourcePath in the request body.

Copilot AI 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.

Pull request overview

Fixes Overleaf compile requests by sending the root document path (rootResourcePath) instead of the root document Mongo ID (rootDoc_id), resolving the 400 error on save-triggered compiles.

Changes:

  • Update BaseAPI.compile() to accept and send rootResourcePath in the compile request body.
  • Resolve the configured root document ID to a workspace path before calling the compile API.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/core/remoteFileSystemProvider.ts Resolves rootDoc_id to a relative rootResourcePath before compiling.
src/api/base.ts Renames compile parameter and sends rootResourcePath in the POST body.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/api/base.ts
Comment thread src/core/remoteFileSystemProvider.ts Outdated
If _resolveById fails to resolve the root document ID to a path,
fall back to null instead of sending an empty string as
rootResourcePath, which would cause a harder-to-diagnose 400 error.
Add a console.warn to make the failure visible in logs.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@edkontar edkontar 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.

Tried the fix, but I have the remote file system read error:

[Window] Failed to resolve files at location: overleaf-workshop://www.overleaf.com/ProjectName

@weiyz23

weiyz23 commented Mar 30, 2026

Copy link
Copy Markdown

This PR is fully functional and resolves my problems : )

@weiyz23

weiyz23 commented Mar 30, 2026

Copy link
Copy Markdown

Tried the fix, but I have the remote file system read error:

[Window] Failed to resolve files at location: overleaf-workshop://www.overleaf.com/ProjectName

Maybe you didn't apply all the two commits?

@CwbyWifsy

Copy link
Copy Markdown

it works

@edkontar

Copy link
Copy Markdown

Tried the fix, but I have the remote file system read error:
[Window] Failed to resolve files at location: overleaf-workshop://www.overleaf.com/ProjectName

Maybe you didn't apply all the two commits?

yes, it works

@zhz-0

zhz-0 commented Mar 30, 2026

Copy link
Copy Markdown

thx,what should this be like for Windows version?

@CwbyWifsy

Copy link
Copy Markdown

thx,what should this be like for Windows version?

C:\Users.vscode\extensions\iamhyc.overleaf-workshop-0.15.7\out,you can see
api\base.js and core\remoteFileSystemProvider.js

@zhz-0

zhz-0 commented Mar 30, 2026

Copy link
Copy Markdown

thx,what should this be like for Windows version?

Resolved,for windows users the files are located at:

base.js
~\ .vscode\extensions\iamhyc.overleaf-workshop-0.15.7\out\api
remoteFileSystemProvider.js
~\ .vscode\extensions\iamhyc.overleaf-workshop-0.15.7\out\core

@zhz-0

zhz-0 commented Mar 30, 2026

Copy link
Copy Markdown

thx,what should this be like for Windows version?

C:\Users.vscode\extensions\iamhyc.overleaf-workshop-0.15.7\out,you can see api\base.js and core\remoteFileSystemProvider.js

thx

@iamhyc

iamhyc commented Mar 31, 2026

Copy link
Copy Markdown
Member

Sorry for the late, really busy on the works. I have tested the function both working on community & offical server. Just need one more approval to move it forward.

@iamhyc iamhyc merged commit 8521263 into overleaf-workshop:master Mar 31, 2026
1 check passed
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile failure 400: rootResourcePath missing in request body on every save