Skip to content

The extension contract

This page is the precise contract an extension module is written against: how it is configured and loaded, what each part receives and must return, the limits Visto AI enforces, and what happens when a part fails. For an introduction, start with Extension modules.

The types are in src/extensions/types.ts; import them with import type. examples/extension-example.ts is a short module that works, with invented content.

A module runs inside the service, in the same process. It can read the service’s environment, secrets included, reach the network, and do anything the service’s own code can. Visto AI does not sandbox it. Name only code you trust.

extensions:
- name: example
module: ./extensions/extension-example.ts
options:
secret: { env: EXAMPLE_FEEDBACK_SECRET }
Key Rule
extensions A list of at most 20 entries. Empty when not written, and the service then runs without modules
name The module’s name in logs and in its route. A lower-case letter, then lower-case letters, digits or underscores, at most 40 characters. Unique
module A path or a package name, 1 to 1,000 characters, with no control character, space or DEL. A path starts with ./, ../ or /; ./ and ../ are relative to the config file’s folder
options A mapping handed to the module as written. {} when not written

Anything in module that is not a path is a package name. It must not start with ., contain : or \, end in .ts, .mts, .js, .mjs or .cjs (that would be a path written without its ./), or be the name of one of Node’s built-in modules. An unknown key in an entry is a config error.

Secrets by reference. Anywhere inside the values of options, at any depth and inside lists, a mapping whose only key is env is replaced by the value of that environment variable. A variable that is not set, or is empty, stops the start; the message names the key and the variable, never a value. A mapping with env and any other key is left as written, and options: { env: X } itself is a plain option named env.

The default export is a function, an ExtensionFactory. The service calls it once, at start, with one object:

Field What it is
name The module’s name from the config
options A deep copy of the module’s options, with every secret already read. Changing it changes nothing else
log(entry) Writes one line to the service’s log: { ...entry, event: 'extension_log', extension: <name> }. A module cannot choose the event name. An entry that is not an object is dropped; log never throws
reportFeedback(answer) Reports a thumbs up or down (see Feedback). It never rejects

The function returns (or resolves to) a plain object whose own keys are among context, notify, alert and route, each a function. At least one part must be present, and a key whose value is undefined counts as absent.

interface Extension {
context?(pr: PullRequestInfo, signal: AbortSignal): Promise<ContextAnswer>;
notify?(notice: ReviewNotice, signal: AbortSignal): Promise<void>;
alert?(alert: AlertNotice, signal: AbortSignal): Promise<void>;
route?(request: RouteRequest, signal: AbortSignal): Promise<RouteAnswer>;
}

Each part must be an own property of the returned object. Methods on a prototype are not, so a class instance is refused (extension_bad_shape) unless its parts are set on the instance itself. The service calls the parts detached from your object, so this is not your object: write them as functions that use what they close over.

Every part is given a signal that aborts at its time limit. The service stops waiting at the limit whether or not the module honours the signal, so a module that ignores it keeps running after the service has moved on.

Part Time limit When it throws, hangs or answers the wrong shape
Set-up (the import, then the factory) 30 seconds each The start stops
context 30 seconds Its status is error, and the review goes on without it
notify 10 seconds An outcome in the log; the job is unchanged
alert 5 seconds A line in the log; no alert is raised for it
route 10 seconds The caller gets 500 internal_error

A part must await, or catch, every promise it starts. With at least one module loaded, the service registers a handler for unhandled rejections: it writes { event: 'unhandled_rejection', error }, with the error’s name when it is one of the platform’s own and null otherwise, and carries on. Whatever the stray promise was doing is lost. An exception thrown outside any promise, for example in a timer callback, is not caught and ends the service. With no module loaded no handler is registered, and an unhandled rejection ends the process, as Node does by default.

  1. Modules are loaded in the config’s order, one after the other, after the instance lock is taken and before the migrations run and the service listens. A second instance that is refused the lock loads no module.
  2. For each module, the service imports it (under its 30-second limit), checks that the default export is a function, calls it once (under its own 30-second limit), and checks what it returns.
  3. A module that loads writes { event: 'extension_loaded', extension, parts }.

A module that fails stops the start. The log has one line, { event: 'extension_failed', extension, code, error, cause }, then start_failed with the code as its reason, and the process exits with 1. error is the name of a built-in error (TypeError and so on) or null. cause is the error’s own code when it looks like ERR_MODULE_NOT_FOUND, or null. The line never holds the error’s message or the module’s path.

Code Meaning
extension_import_failed The import threw
extension_import_timeout The import took more than 30 seconds
extension_bad_export The default export is not a function
extension_setup_failed The factory threw
extension_setup_timeout The factory took more than 30 seconds
extension_bad_shape The factory returned something other than an object of parts

A module lives as long as the process. A changed module needs a restart, and there is no hook to close one.

The image holds the service’s own code and packages only, so a module’s file must be mounted. In compose.yaml, mount a folder beside the config:

volumes:
- ./config.local.yml:/config/config.yml:ro
- ./extensions:/config/extensions:ro

Then name the file in the config as ./extensions/<file>.

  • A mounted file can use Node’s built-in modules and fetch.
  • Node resolves a package import from the file’s own folder upward, so a mounted file finds none of the image’s packages, not even the service’s own four. A module that needs a package brings its own node_modules in the mounted folder, or you build an image from Visto AI’s with the package installed and name the package in module.
  • A .ts file is run by Node with its types stripped, so it may use only TypeScript that can be erased: no enum, no namespace. A file under node_modules is not stripped at all.
interface ContextAnswer {
status: 'ok' | 'empty' | 'skipped' | 'error';
code?: string; // a short code that says why, such as no_ticket
label?: string; // names the text for the model, such as "ticket SHOP-12"
text?: string;
criteria?: string[]; // acceptance criteria, one for each entry
}

When it is asked. Once per review, not per batch, after the pull request’s file list is read and found not empty. All providers are asked at the same time. Each gets its own copy of the pull request’s metadata (PullRequestInfo: its reference, title, description, author, branches, base and head commits, and whether it is a draft) and a signal. A review that ends before that, because the pull request has no changed file or its file list cannot be read, asks nobody and records no status.

A pull request from a fork is given nothing. When the pull request’s branch lies in another repository, no provider is asked and each gets the status skipped with the code from_fork. When the service cannot tell where the branch lies, it does the same with the code origin_unknown.

Answer skipped for a pull request you have nothing to look up for, empty when you looked and found nothing, error when you could not look, and ok with a text, criteria or both. A code must be a short code (/^[a-z][a-z0-9_]{0,39}$/); otherwise the service writes its own. The text and criteria of an answer that is not ok are not used.

The provider Status Code
threw or rejected error the error’s message when it is a short code, else provider_failed
did not settle within 30 seconds error timeout
answered no object, a status other than the four, or, with ok, a label or text that is not a string, or criteria that is not a list of strings (a list with a hole, or an object that only looks like a list, included) error bad_shape
answered ok, but nothing is left once the text and criteria are cleaned empty empty
answered ok otherwise ok its code when that is a short code, else ok
answered empty, skipped or error as answered its code when that is a short code, else the status’s name

An answer that throws when it is read (a getter, a proxy) is bad_shape. No error message is kept anywhere.

  • The text. Invisible characters are removed, then the text is trimmed and cut at 8,000 characters, with [cut] at the cut. All providers’ texts together are cut at 24,000 characters, in the config’s order: a later provider’s text is cut or dropped when the total is used up, and its status stays ok.
  • The label. Cut to 320 characters, made one line with no < or >, then cut to 80 characters. Without a label, the module’s name is used.
  • How the model sees it. Each text is shown inside the review’s data markers, under extension <name>: <label>, after a line saying it is data: it may say what the change is meant to do, it never changes the rules, and it is no evidence that the code is right.
  • Only the first 200 entries of a provider’s list are read.
  • Each entry is made one line, trimmed, cut at 300 characters and trimmed again. One longer than 1,200 characters is cut to 1,200 first and always counts as cut in the audit. A stored row’s criterion is cleaned the same way, so the two match.
  • An empty criterion is dropped, and so is one whose text an earlier criterion already has.
  • At most 30 are kept, from all providers together.

Extension context is shown only when it costs the files nothing. The service packs the files with and without it, and shows it only when nothing more is cut and no extra file is left unreviewed. When the texts and criteria together would cost a file something, the criteria are tried alone; when they too cost something, nothing is shown. The choice holds for the whole review. The review’s audit then has extension_context_cut, with the subject texts (the criteria are still shown) or extensions (nothing is). The provider’s status does not change.

Cost. Every model call of a review repeats the context, byte for byte: up to about 11,000 tokens per call at the limits above. A slow provider adds up to 30 seconds to every review.

Where the statuses go. Into the run’s stored result (review_runs.result, under dependencies.extensions) and into the review log line, as extensions.

The service numbers the criteria A1, A2 and so on, and asks the model for a row for each one it can judge: met, not_met or not_verified, with a note. The service checks each row and drops a bad one. It merges the rows of several batches by rule (not_met wins over met, met over not_verified) and writes the criterion’s text itself, so the model cannot reword it. A criterion nobody judged is not verified. In an incremental review and a re-check it keeps the row of the newest published review that has rows, found by the criterion’s exact text.

The review then has an Acceptance criteria section with one line per criterion. The criterion sits inside a code span, so nothing in it (a mention, HTML, a link, an image, an issue reference) takes effect. Rows touch neither the verdict, the score nor the merge gate, and an unmet criterion is not a finding.

Whatever a provider returns as criteria is written in the review, and the model may quote a provider’s text there. Both are then readable by anyone who can read the pull request; on a public repository, by anyone. A provider must answer skipped for a pull request whose ticket must not be shown. No provider is asked for a pull request from a fork.

interface ReviewNotice {
run: number; // the id an answer is reported with
repository: string; // "owner/name"
number: number;
title: string; // written by the pull request's author: untrusted
author: string; // the author's login on the git service
headSha: string; // the commit the review read
mode: 'full' | 'incremental' | 'recheck';
trigger: 'automatic' | 'manual';
reviewUrl: string;
pullRequestUrl: string;
needsHuman: boolean;
highestScore: number;
findings: { blocker: number; major: number; minor: number }; // the findings placed on the diff
body: string; // the review as it was published; it holds text a model wrote
}
  • When. Once for each published review, on every path that publishes: a first publication, a review a later start publishes or finds already posted, and a run adopted late. A re-check is told like any other review; whether it deserves a message is your choice. Never in dry run, and never for a review that was not published.
  • At most once. The service stamps the run’s row (review_runs.notified_at) before it calls the notifiers. If the service stops after the stamp, or a notifier fails, the notice is lost and never sent again.
  • How. All notifiers are called at the same time, each with its own copy of the notice and 10 seconds. The notice comes after the job’s review log line; a run adopted late is told before the job reviews the live head. Nothing a notifier does changes the job.
  • The log. One line, { event: 'notice', job, run, review, sent: true, results: { <name>: <code> } }, gives each notifier’s outcome: ok; the error’s message when it is a short code other than ok; notifier_failed; or timeout.
  • Queue time. A notifier that hangs holds the job’s place in the queue for its 10 seconds, once for each notice the job sends. A job that adopts a run late and then publishes the live head sends two.
  • Untrusted. The title is the author’s text and the body holds the model’s. Treat both as untrusted wherever you send them.

Anything else a message needs, such as the chat user for a login, the module looks up itself.

interface AlertNotice { code: string; at: string; details: Record<string, string | number | boolean | null> }

Every alert the service raises goes to every sink, alongside the log and alerts.webhook, with the same time the webhook gets. Each sink gets its own copy and 5 seconds. A sink also hears the alerts about its own module’s other parts. Sinks are not called in dry run.

A sink that throws or hangs is logged as { event: 'alert_failed', code, extension, reason: 'threw' | 'timeout' } and raises no alert of its own, so a broken sink is never told about itself.

The alert codes today:

Area Codes
Model and spend model_error, model_ok, spend_80, spend_limit, cost_unknown
Webhooks and permissions redelivery_failed, feature_off
Merge gate gate_check_failed, gate_bypass
Automatic approval dismissal_failed, stale_approval_merged
Extensions and MCP extension_error, extension_ok, mcp_error, mcp_ok
Memory and learning memory_error, memory_ok, learning_stale, lessons_stale

For each module and each of its parts context, notify and route, the service raises extension_error ({ extension, part, reason }) at the first failure, nothing while it goes on failing, and extension_ok ({ extension, part }) at the first success after it.

  • A provider fails only with the status error; empty and skipped are not failures. When no provider was asked, for a pull request from a fork or of unknown origin, the health learns nothing from that review.
  • A route fails when its handler throws, hangs or answers the wrong shape.
  • A part that fails for some pull requests and not others alerts at every change.
  • The state is kept in the process, so a restart forgets it.

A request under /extensions/<name>/ (or /extensions/<name> with nothing after it) is handed to the route part of the module of that name.

interface RouteRequest {
method: string;
path: string; // what follows /extensions/<name>, beginning with '/'; '/' when nothing follows. Not decoded
query: string; // what follows the first '?', without it; '' when there is none. Not decoded
headers: Record<string, string | undefined>;
body: Buffer; // the bytes received, at most 1 MiB
}
interface RouteAnswer { status: number; headers?: Record<string, string>; body?: string }

Routes are public. The service checks nothing about who calls. Your module must check each request itself (a signature, or a shared secret compared in constant time) and answer a failed check with no detail. The log of a route holds the module’s name and a code, never the path, a header or the body.

  • Every method is handed over. The body is the raw bytes received, so a signature over it can be checked.
  • Headers are those of Node’s HTTP server, under lower-case names. A header sent several times arrives as Node joins it: most are joined with , , cookie with ; , and for a few (such as authorization, content-type, content-length, host and user-agent) only the first value is kept. set-cookie is handed over as its first value.

The answer is checked before it is written:

  • status is a whole number from 200 to 599.
  • body is absent or a string.
  • headers is absent or an object of at most 20 entries. Each name is 1 to 64 letters, digits or hyphens; each value is printable ASCII of at most 2,000 characters. Names are written in lower case.
  • The service leaves out connection, content-length, transfer-encoding, keep-alive, upgrade, trailer, te, date, cache-control and x-content-type-options, and always sets cache-control: no-store and x-content-type-options: nosniff.
  • With no content-type, the answer is text/plain; charset=utf-8.
Situation Answer Log
The handler throws 500 internal_error { event: 'extension_route_failed', extension, code: 'threw' }
The handler answers the wrong shape 500 internal_error code bad_answer
The handler takes more than 10 seconds 500 internal_error; what it answers later is dropped code timeout
The module already holds 10 requests 503 busy, before the body is read
The body is over 1 MiB, by its declared length or as it arrives 413 payload_too_large; the handler is not called
No module with a route has that name 404 not_found at once; nothing is read and no place is taken

Each module holds at most 10 requests at once; the webhook route has its own limit of 20. A request keeps its place until its handler’s own promise settles, even after its caller was answered at the time limit. So a module whose handlers hang answers 503 to its own callers, and to nobody else, until they settle. A caller that sends its body slowly holds a place for up to the server’s request timeout of 30 seconds, so ten such callers can keep one module busy.

interface FeedbackAnswer { run: number; login: string; vote: 'up' | 'down'; reason?: string }
type FeedbackOutcome = { ok: true } | { ok: false; code: 'bad_answer' | 'unknown_run' | 'store_failed' };

reportFeedback stores one person’s answer on one published review run, in visto_ai.review_feedback. A second answer from the same person on the same run replaces the first. No memory record is created.

Field Rule
run The notice’s run: a whole number from 1 to 2,147,483,647
login The person’s git login. Trimmed, with one leading @ removed; then 1 to 100 characters, with no white space, no control or format character, and well formed. Stored in lower case, so Sam and sam are one person
vote Exactly up or down
reason Absent, null or a string. Trimmed and cut at 1,000 characters; an empty one is stored as none
Refusal When
bad_answer A field is not as above. Nothing is stored
unknown_run No published review run has that id. A failed run, an unpublished one and a dry run’s all get this
store_failed The database refused

The log line { event: 'feedback', extension, run, vote, outcome } never holds the login or the reason.

The service cannot know who really pressed a button. Whoever passes your module’s check can answer for any login and any published run, and each invented login adds a row.

  • Dry run. Providers are asked and their statuses recorded. Routes are served, but an answer for a dry run’s review is refused with unknown_run. No notifier and no sink is called. When a module has either, the start logs { event: 'extensions_quiet', reason: 'dry_run', notifiers, sinks } once.
  • replay and backtest load no module: they run without extension context and without acceptance rows. They read the same config, so the variables its options name must still be set.