Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ function startHttpTokenWatcher(cfg: GatewayConfig): FSWatcher | null {
?? join(process.env.BASE_DATA_DIR?.trim() || homedir(), ".vellum", "http-token");

const dir = dirname(tokenPath);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
try {
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
} catch (err) {
log.warn({ err, path: dir }, "Cannot create token directory, skipping http-token watcher");
return null;
}

let debounceTimer: ReturnType<typeof setTimeout> | null = null;

function refresh(): void {
// Skip file-based refresh when env vars explicitly pin the tokens β€”
// respect the same precedence as loadConfig().
if (process.env.RUNTIME_BEARER_TOKEN) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep refreshing proxy token when bearer token is env-pinned

Returning immediately when RUNTIME_BEARER_TOKEN is set stops all file-driven refreshes, including cfg.runtimeProxyBearerToken. That regresses the startup-order case this watcher is meant to handle: if the gateway starts before the daemon and only RUNTIME_BEARER_TOKEN is env-set, the daemon later writes http-token but runtimeProxyBearerToken is never updated, so /deliver/* auth checks (e.g., createTelegramDeliverHandler) keep using an undefined/stale token and can fail with 503/401 indefinitely.

Useful? React with πŸ‘Β / πŸ‘Ž.


try {
const token = readFileSync(tokenPath, "utf-8").trim() || undefined;
if (token && token !== cfg.runtimeBearerToken) {
Expand Down
Loading