Skip to content

fix: use correct bearer token for lazy-load video fetch#5030

Merged
siddseethepalli merged 1 commit into
mainfrom
do/fix-lazy-load-auth
Feb 19, 2026
Merged

fix: use correct bearer token for lazy-load video fetch#5030
siddseethepalli merged 1 commit into
mainfrom
do/fix-lazy-load-auth

Conversation

@siddseethepalli
Copy link
Copy Markdown
Contributor

@siddseethepalli siddseethepalli commented Feb 19, 2026

Summary

  • Video lazy-load was using the Keychain auth token (SessionTokenManager) instead of the daemon HTTP bearer token (~/.vellum/http-token), causing 401 errors when fetching attachment data
  • Added readHttpToken() helper to read the correct bearer token from disk
  • Updated InlineVideoAttachmentView to use readHttpToken() for HTTP API auth

🤖 Generated with Claude Code


Open with Devin

Co-Authored-By: Claude <noreply@anthropic.com>
@siddseethepalli siddseethepalli merged commit 6342136 into main Feb 19, 2026
@siddseethepalli siddseethepalli deleted the do/fix-lazy-load-auth branch February 19, 2026 07:37
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +56 to +65
func readHttpToken() -> String? {
let tokenPath = NSHomeDirectory() + "/.vellum/http-token"
guard let data = try? Data(contentsOf: URL(fileURLWithPath: tokenPath)),
let token = String(data: data, encoding: .utf8)?
.trimmingCharacters(in: .whitespacesAndNewlines),
!token.isEmpty else {
return nil
}
return token
}
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.

🟡 readHttpToken() ignores BASE_DATA_DIR, unlike readSessionToken() and other path resolvers

The new readHttpToken() hardcodes the path as NSHomeDirectory() + "/.vellum/http-token", but does not respect the BASE_DATA_DIR environment variable. This is inconsistent with the existing readSessionToken() function at clients/shared/IPC/DaemonClient.swift:35-41 which explicitly checks BASE_DATA_DIR and the daemon-side getHttpTokenPath() at assistant/src/util/platform.ts:146-148 which uses getRootDir() (also BASE_DATA_DIR-aware).

Root Cause and Impact

On the daemon side, getHttpTokenPath() returns join(getRootDir(), 'http-token') where getRootDir() resolves to join(process.env.BASE_DATA_DIR || homedir(), '.vellum'). When BASE_DATA_DIR is set (e.g. in Docker via ENV BASE_DATA_DIR=/data, or in development), the daemon writes the http-token to $BASE_DATA_DIR/.vellum/http-token.

The Swift readHttpToken() always reads from ~/.vellum/http-token, so when BASE_DATA_DIR is set to a non-home directory, the token file won't be found and the function returns nil, causing fetchAttachmentData() to throw URLError(.userAuthenticationRequired) — the same class of auth failure this PR was meant to fix.

The existing readSessionToken() in the same file correctly handles this:

func resolveSessionTokenPath(environment: [String: String]? = nil) -> String {
    let env = environment ?? ProcessInfo.processInfo.environment
    if let baseDir = env["BASE_DATA_DIR"]?..., !baseDir.isEmpty {
        return expandHomePath(baseDir) + "/.vellum/session-token"
    }
    return NSHomeDirectory() + "/.vellum/session-token"
}

Impact: Video lazy-load will fail with 401 when BASE_DATA_DIR is set to a non-default path.

Suggested change
func readHttpToken() -> String? {
let tokenPath = NSHomeDirectory() + "/.vellum/http-token"
guard let data = try? Data(contentsOf: URL(fileURLWithPath: tokenPath)),
let token = String(data: data, encoding: .utf8)?
.trimmingCharacters(in: .whitespacesAndNewlines),
!token.isEmpty else {
return nil
}
return token
}
/// Resolve the daemon HTTP token path.
/// Uses BASE_DATA_DIR when set to match daemon root resolution.
func resolveHttpTokenPath(environment: [String: String]? = nil) -> String {
let env = environment ?? ProcessInfo.processInfo.environment
if let baseDir = env["BASE_DATA_DIR"]?.trimmingCharacters(in: .whitespacesAndNewlines), !baseDir.isEmpty {
return expandHomePath(baseDir) + "/.vellum/http-token"
}
return NSHomeDirectory() + "/.vellum/http-token"
}
/// Read the daemon HTTP bearer token from disk (~/.vellum/http-token).
func readHttpToken(environment: [String: String]? = nil) -> String? {
let tokenPath = resolveHttpTokenPath(environment: environment)
guard let data = try? Data(contentsOf: URL(fileURLWithPath: tokenPath)),
let token = String(data: data, encoding: .utf8)?
.trimmingCharacters(in: .whitespacesAndNewlines),
!token.isEmpty else {
return nil
}
return token
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7523217c77

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


/// Read the daemon HTTP bearer token from disk (~/.vellum/http-token).
func readHttpToken() -> String? {
let tokenPath = NSHomeDirectory() + "/.vellum/http-token"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve HTTP token path via BASE_DATA_DIR

Use the same root-dir resolution as the daemon when reading http-token; this helper currently hardcodes ~/.vellum/http-token, but the daemon writes the bearer token under (BASE_DATA_DIR || $HOME)/.vellum/http-token (assistant/src/util/platform.ts + assistant/src/daemon/lifecycle.ts). In environments that set BASE_DATA_DIR (custom data roots, containerized/dev setups), readHttpToken() returns nil, so lazy-loaded video requests are sent without a valid token and fail with 401.

Useful? React with 👍 / 👎.

@siddseethepalli
Copy link
Copy Markdown
Contributor Author

Addressed in #5055

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.

1 participant