Skip to content
Closed
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions .github/workflows/patched-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Builds this branch (an upstream release tag plus a few local patches) with upstream's own
# Linux CLI build workflow, so the result differs from the upstream release only by the patches,
# and publishes the gnu tarballs as a release of this fork.
#
# Run: push a tag named patched-<upstream version>.<n>, e.g. patched-1.54.0.1, on the patched branch.
# The name must not start with "v": upstream's release.yml and publish-docker.yml fire on v* tags.
on:
push:
tags:
- "patched-*"

name: "Patched release"

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/build-cli-linux.yml
permissions:
contents: read
with:
ref: ${{ github.sha }}

# Unit tests for the patched code paths (including the vendored acp-http crate), on the same toolchain.
test-patches:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev libdbus-1-dev libxcb1-dev protobuf-compiler cmake clang libclang-dev
- name: Vendored acp-http is the one in the build graph
# An unused [patch] is only a cargo warning; fail loudly instead. --locked also
# fails if Cargo.lock is stale (build-cli-linux.yml does not pass --locked).
run: |
cargo tree --locked -p goose-cli --features acp-http -i agent-client-protocol-http --depth 0 \
| tee /dev/stderr | grep -F 'vendor/agent-client-protocol-http'
- name: Test patched modules
run: |
F=code-mode,tree-sitter,aws-providers,telemetry,otel,rustls-tls,live-voice,system-keyring,platform-apps,chat-recall,scheduler,acp-http,online-model-meta
cargo test --release -p goose --features "$F" --lib -- gcpvertexai gcpauth process_group
cargo test --release -p goose-cli --lib -- cache_ttl
cargo test --release -p agent-client-protocol-http --features server --lib

release:
needs: [build, test-patches]
if: ${{ !cancelled() && needs.test-patches.result == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: goose-*-unknown-linux-gnu
merge-multiple: true
path: dist
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
ls -la dist
test -f dist/goose-aarch64-unknown-linux-gnu.tar.gz
(cd dist && sha256sum * > SHA256SUMS)
gh release create "$TAG" dist/* --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" \
--title "$TAG" --notes "Upstream goose v$(echo "$TAG" | sed -E 's/^patched-([0-9]+[.][0-9]+[.][0-9]+).*/\1/') plus the local patches committed after that tag at $GITHUB_SHA."
49 changes: 48 additions & 1 deletion crates/goose-cli/src/session/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ fn validate_provider_override_context(
Ok(())
}

/// `GOOSE_HEADLESS_CACHE_TTL` ("5m" or "1h"): the prompt-cache TTL a non-interactive run uses
/// instead of the default clamp to 5m. Read from the environment only, so it is a deliberate
/// per-invocation choice and never inherited from a user's interactive config.
fn headless_cache_ttl_opt_in() -> Option<String> {
let ttl = std::env::var("GOOSE_HEADLESS_CACHE_TTL").ok()?;
match ttl.trim().to_lowercase().as_str() {
v @ ("5m" | "1h") => Some(v.to_string()),
other => {
tracing::warn!("ignoring GOOSE_HEADLESS_CACHE_TTL={other:?}: expected '5m' or '1h'");
None
}
}
}

async fn resolve_provider_and_model(
session_config: &SessionBuilderConfig,
config: &Config,
Expand Down Expand Up @@ -436,7 +450,13 @@ async fn resolve_provider_and_model(
};

if !session_config.interactive {
model_config = model_config.with_cache_ttl_clamped();
model_config = match headless_cache_ttl_opt_in() {
// An explicit opt-in for headless runs that are resumed at intervals (e.g. a standing
// session woken by a timer): those idle between runs, which is exactly when a 1h TTL
// pays for its 2x write. Without the opt-in, burst-only headless runs keep the clamp.
Some(ttl) => model_config.with_cache_ttl(&ttl),
None => model_config.with_cache_ttl_clamped(),
};
}

ResolvedProviderConfig {
Expand Down Expand Up @@ -1546,6 +1566,33 @@ mod tests {
assert_eq!(resolved.model_config.cache_ttl().as_deref(), Some("5m"));
}

#[tokio::test]
async fn headless_cache_ttl_opt_in_overrides_clamp() {
let _guard = env_lock::lock_env([
("GOOSE_PROVIDER", None::<&str>),
("GOOSE_MODEL", None::<&str>),
("GOOSE_CACHE_TTL", None::<&str>),
("GOOSE_HEADLESS_CACHE_TTL", Some("1h")),
]);
let temp_dir = TempDir::new().unwrap();
let config = test_config(&temp_dir);
let saved = goose_providers::model::ModelConfig::new("claude-sonnet-4-6");

let resolved = resolve_provider_and_model(
&SessionBuilderConfig {
resume: true,
interactive: false,
..SessionBuilderConfig::default()
},
&config,
Some("anthropic".to_string()),
Some(saved),
)
.await;

assert_eq!(resolved.model_config.cache_ttl().as_deref(), Some("1h"));
}

#[test]
fn resumed_provider_override_rejects_context_owning_provider() {
let error = validate_provider_override_context(
Expand Down
35 changes: 34 additions & 1 deletion crates/goose/src/providers/gcpauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@ struct TokenResponse {
token_type: String,
}

const DEFAULT_SCOPE: &str = "https://www.googleapis.com/auth/cloud-platform";

/// Scopes requested when refreshing authorized-user (gcloud ADC) credentials.
/// `GCP_AUTH_SCOPES` (space-separated; env or config.yaml) replaces the default cloud-platform scope.
/// A gateway in front of Vertex that attributes requests by identity needs
/// `https://www.googleapis.com/auth/userinfo.email` as well; Vertex itself does
/// not. The scopes must be a subset of what the refresh token was granted.
fn authorized_user_scope() -> String {
crate::config::Config::global()
.get_param::<String>("GCP_AUTH_SCOPES")
.ok()
.map(|s| s.split_whitespace().collect::<Vec<_>>().join(" "))
.filter(|s| !s.is_empty())
.unwrap_or_else(|| DEFAULT_SCOPE.to_string())
}

/// Handles authentication with Google Cloud Platform services.
///
/// This struct manages the complete authentication lifecycle including:
Expand Down Expand Up @@ -562,12 +578,13 @@ impl GcpAuth {
&self,
creds: &AuthorizedUserCredentials,
) -> Result<TokenResponse, AuthError> {
let scope = authorized_user_scope();
let params = [
("client_id", creds.client_id.as_str()),
("client_secret", creds.client_secret.as_str()),
("refresh_token", creds.refresh_token.as_str()),
("grant_type", "refresh_token"),
("scope", "https://www.googleapis.com/auth/cloud-platform"),
("scope", &scope),
];

self.exchange_token(&creds.token_uri, &params).await
Expand Down Expand Up @@ -619,6 +636,22 @@ mod tests {
// Only import what we need
use wiremock::{Mock, MockServer, ResponseTemplate};

#[test]
fn authorized_user_scope_defaults_and_overrides() {
{
let _guard = env_lock::lock_env([("GCP_AUTH_SCOPES", None::<&str>)]);
assert_eq!(authorized_user_scope(), DEFAULT_SCOPE);
}
let _guard = env_lock::lock_env([(
"GCP_AUTH_SCOPES",
Some(" https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.email "),
)]);
assert_eq!(
authorized_user_scope(),
"https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.email"
);
}

mockall::mock! {
#[derive(Debug)]
FilesystemOpsMock {}
Expand Down
55 changes: 52 additions & 3 deletions crates/goose/src/providers/gcpvertexai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pub struct GcpVertexAIProvider {
name: String,
#[serde(skip)]
request_builder: RequestBuilderDecorator,
/// True when GCP_VERTEX_HOST is set: every location then goes to that host.
#[serde(skip)]
host_overridden: bool,
}

impl GcpVertexAIProvider {
Expand All @@ -197,7 +200,25 @@ impl GcpVertexAIProvider {
let config = crate::config::Config::global();
let project_id = config.get_param("GCP_PROJECT_ID")?;
let location = Self::determine_location(config)?;
let host = Self::build_host_url(&location);
// GCP_VERTEX_HOST points every request at a proxy that speaks the Vertex paths (for
// example a local failover proxy) instead of Google's regional hosts.
let host_override: Option<String> = config
.get_param("GCP_VERTEX_HOST")
.ok()
.map(|h: String| h.trim().trim_end_matches('/').to_string())
.filter(|h| !h.is_empty());
let host_overridden = host_override.is_some();
let host = host_override.unwrap_or_else(|| Self::build_host_url(&location));
// GCP_VERTEX_SESSION_HEADER renames the session-id header, so a proxy that keys session
// stickiness on its own header name (e.g. x-opencode-session) can see goose sessions.
let session_header: Option<String> = config
.get_param("GCP_VERTEX_SESSION_HEADER")
.ok()
.filter(|h: &String| !h.trim().is_empty());
let request_builder = crate::session_context::session_id_request_builder_with_header_override(
session_header.as_deref().map(str::trim),
)
.map_err(|e| anyhow::anyhow!("invalid GCP_VERTEX_SESSION_HEADER: {e}"))?;

let client = Client::builder()
.connect_timeout(Duration::from_secs(DEFAULT_CONNECT_TIMEOUT_SECS))
Expand All @@ -217,7 +238,8 @@ impl GcpVertexAIProvider {
location,
retry_config,
name: GCP_VERTEX_AI_PROVIDER_NAME.to_string(),
request_builder: crate::session_context::session_id_request_builder(),
request_builder,
host_overridden,
})
}

Expand Down Expand Up @@ -293,9 +315,16 @@ impl GcpVertexAIProvider {
location: &str,
streaming: bool,
) -> Result<Url, GcpVertexAIError> {
// With a host override, never switch to a Google regional host for another location; the
// location stays in the path and the proxy forwards it.
let configured_location = if self.host_overridden {
location
} else {
self.location.as_str()
};
build_vertex_url(
&self.host,
&self.location,
configured_location,
&self.project_id,
&model.model_name,
provider,
Expand Down Expand Up @@ -801,6 +830,26 @@ mod tests {
);
}

#[test]
fn test_build_vertex_url_proxy_host_keeps_target_location_in_path() {
// With GCP_VERTEX_HOST set, build_request_url passes the target location as the
// configured one, so the proxy host is kept and the location only appears in the path.
let url = build_vertex_url(
"http://127.0.0.1:8789",
"us-east5",
"test-project",
"claude-opus-5-5",
ModelProvider::Anthropic,
"us-east5",
true,
)
.unwrap();
assert_eq!(
url.as_str(),
"http://127.0.0.1:8789/v1/projects/test-project/locations/us-east5/publishers/anthropic/models/claude-opus-5-5:streamRawPredict"
);
}

#[test]
fn test_build_vertex_url_endpoints() {
let anthropic_url = build_vertex_url(
Expand Down
Loading