Skip to content

Web research and sign-in ​

The web node of the answer graph searches the web, reads the best pages and turns them into evidence. This page explains the provider chain, page reading, ranking, and the sign-in flow for gated sources. The code is in app/web/.

The provider chain ​

WebSearch (app/web/search.py) runs, per query:

  1. Tavily, when there is a key and credits left this month. Credits are counted per month in the usage table.
  2. SearXNG, when Tavily fails or runs out. Once switched, the run stays on SearXNG, and a web.provider_switched event says so. Without a Tavily key, SearXNG is the only provider.
  3. OpenAlex and arXiv, alongside, for papers. They are free and need no key.

Results are cached in web_cache for WEB_CACHE_HOURS (24) and deduplicated by canonical address and DOI, so one paper found by Tavily and by OpenAlex is one source.

Reading pages ​

A search snippet is a sentence or two; the answer needs the page. PageFetcher (app/web/pages.py) reads the top results:

  • Every fetch, and every redirect, passes the same SSRF guard as imports: public addresses only.
  • robots.txt is respected. Pages are capped in size.
  • HTML is reduced to its article text with trafilatura. PDFs are read with PyMuPDF.
  • A page that yields nothing readable, typical of pages built by JavaScript, is opened in a real browser: a Playwright MCP server (app/web/mcp_browser.py). The node calls browser_navigate, then browser_snapshot, and flattens the accessibility tree to text. The browser runs headless, isolated per session, on loopback.
  • Pages are cached in web_pages for a week, including failures such as a 403, so a dead page is not fetched again in every run.
  • A page's date comes from its own metadata (the last update), or else from the provider.

Each page is split into passages. The reranker scores them against the question on the same 0 to 1 scale as course passages, so web and course passages compete for the evidence on equal terms.

Signals and freshness ​

credibility() attaches signals to a web source, shown as badges: Official site, university, known publisher, and others. No signal makes a page evidence by itself; the reranker decides that.

For a question about the current state of something ("latest", "current", "newest version"), freshness() adjusts scores:

PageAdjustment
On the site of the thing the question names (for example opencv.org for "OpenCV")+0.15
Dated within the last year+0.05
Older than two years−0.1

The draft then gets a note: prefer the newest official source, say which source is older, and give an "as of" date. Web source labels in the evidence say "dated YYYY-MM-DD".

Research mode ​

Research reads more pages and searches the web and scholarly sources before the course passages are weighed. It is also the only mode that can pause for a gated source.

Gated sources ​

A page that answers 401, 402, 403, 407 or 451, or shows a login wall, is gated. In Research mode, when a top source is gated and nobody asked about it yet in this run, the web node pauses the run with an interrupt. The card offers sign-in (when the sign-in browser is set up), upload or skip.

The sign-in browser ​

sequenceDiagram
  participant S as Student's browser
  participant A as API
  participant C as Sign-in Chromium
  S->>A: Sign in via secure browser
  A->>C: new private context, open the gated page (DevTools)
  S->>A: VNC over WebSocket
  A->>C: VNC bridge
  Note over S,C: The student signs in with their own account
  S->>A: I've signed in
  A->>C: read that site's cookies
  A->>A: seal the cookies, store per student and Space
  A->>C: close the context
  A->>A: resume the run

Figure 1. Signing in to a gated source.

  • The signin service is Chromium on a virtual screen, in its own container: non-root, no capabilities, read-only root, profile on tmpfs. Its DevTools and VNC ports are on loopback only.
  • The API drives it over the DevTools protocol and bridges its screen to the student over VNC (/api/sign-in/<id>/screen).
  • Each sign-in gets a fresh private browser context, thrown away afterwards. A window closes after SIGNIN_SESSION_MINUTES (15).
  • Only the gated site's cookies are kept, sealed with a server key (ACCESS_GRANT_KEY, or derived from JWT_SECRET), in access_grants, per student and Space, for ACCESS_GRANT_DAYS (14).
  • Later page fetches for that site, in that student's runs in that Space, send those cookies.

Cookies never reach the model, the prompts, the events or the logs. Only the site name and counts are reported. Scholar Lens never gets around a login: the student signs in with an account they already have.

Upload instead ​

The student can upload the paper instead. The file is indexed for the chat (a session file) and searched like a course source when the run resumes.

Saving to the Library ​

Save to library on a web source imports the page as a Library item, through the normal import job.