Repository navigation
fix(harness): reuse one upstream connection in the image gate, keep Content-Encoding #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
79decba
2748ec9
568be8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,137 @@ | ||||||||||||||||||||||||||||||||||||
| // The link-line filter `build.rs` applies to the kit's CMake `commandFragments`. | ||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||
| // A separate file with no dependencies, so `build.rs` and | ||||||||||||||||||||||||||||||||||||
| // `tests/test_wally_build_link_args.rs` can both compile it: a build script's own | ||||||||||||||||||||||||||||||||||||
| // `#[cfg(test)]` module is never run by `cargo test`. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// Drop the arguments a compiler driver needs and a linker does not, keeping | ||||||||||||||||||||||||||||||||||||
| /// the ones whose value is a separate argument out of the same list. | ||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||
| /// `split_fragment` gives "-isystem /dir" back as two entries, and a bare | ||||||||||||||||||||||||||||||||||||
| /// directory is a link input: dropping the flag and keeping the path is what | ||||||||||||||||||||||||||||||||||||
| /// turned a `CXXFLAGS` of `-nostdinc++ -isystem ${SDKROOT}/usr/include/c++/v1 | ||||||||||||||||||||||||||||||||||||
| /// --sysroot=${SDKROOT}` into `ld: file cannot be mmap()ed ... usr/include/c++/v1`. | ||||||||||||||||||||||||||||||||||||
| /// The same shape hides `-I`, `-F`, `-L`'s compile-only siblings and the | ||||||||||||||||||||||||||||||||||||
| /// `--sysroot=<dir>` spelling, which takes its value inside the argument and | ||||||||||||||||||||||||||||||||||||
| /// so leaked on its own. | ||||||||||||||||||||||||||||||||||||
| pub fn link_args_from(chunk: Vec<String>) -> Vec<String> { | ||||||||||||||||||||||||||||||||||||
| let mut kept = Vec::with_capacity(chunk.len()); | ||||||||||||||||||||||||||||||||||||
| let mut rest = chunk.into_iter(); | ||||||||||||||||||||||||||||||||||||
| while let Some(arg) = rest.next() { | ||||||||||||||||||||||||||||||||||||
| if TAKES_SEPARATE_OPERAND.contains(&arg.as_str()) { | ||||||||||||||||||||||||||||||||||||
| // Drop the flag and the argument it eats, whatever it looks like. | ||||||||||||||||||||||||||||||||||||
| rest.next(); | ||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if is_compile_only(&arg) { | ||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| kept.push(arg); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| kept | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// Compiler flags whose value arrives as the next argument. A pathlib entry | ||||||||||||||||||||||||||||||||||||
| /// here never reaches the linker, and neither does its operand. | ||||||||||||||||||||||||||||||||||||
| const TAKES_SEPARATE_OPERAND: [&str; 6] = [ | ||||||||||||||||||||||||||||||||||||
| "-isystem", | ||||||||||||||||||||||||||||||||||||
| "-I", | ||||||||||||||||||||||||||||||||||||
| "-F", | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||||||||||||||||||||||||||||||||||||
| "-iframework", | ||||||||||||||||||||||||||||||||||||
| "-iquote", | ||||||||||||||||||||||||||||||||||||
| "-idirafter", | ||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Add Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// GCC-style drivers get CMAKE_CXX_FLAGS on the link line too ("-O3 -DNDEBUG"); | ||||||||||||||||||||||||||||||||||||
| /// harmless to a driver, fatal once passed straight to ld (the Swift host's | ||||||||||||||||||||||||||||||||||||
| /// -Xlinker path). Keep only what linking needs. | ||||||||||||||||||||||||||||||||||||
| pub fn is_compile_only(arg: &str) -> bool { | ||||||||||||||||||||||||||||||||||||
| if arg.starts_with("-Wl,") { | ||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if let Some(msvc) = arg.strip_prefix('/') { | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Unix absolute paths that start with an uppercase Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||
| return is_msvc_compile_only(msvc); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if matches!(arg, "-MD" | "-MDd" | "-MT" | "-MTd") { | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||
| "-D", | ||||||||||||||||||||||||||||||||||||
| "-U", | ||||||||||||||||||||||||||||||||||||
| "-I", | ||||||||||||||||||||||||||||||||||||
| "-O", | ||||||||||||||||||||||||||||||||||||
| "-g", | ||||||||||||||||||||||||||||||||||||
| "-W", | ||||||||||||||||||||||||||||||||||||
| "-std=", | ||||||||||||||||||||||||||||||||||||
| "-isystem", | ||||||||||||||||||||||||||||||||||||
| "-pedantic", | ||||||||||||||||||||||||||||||||||||
| // A compile-only sysroot is spelled with the value inside the | ||||||||||||||||||||||||||||||||||||
| // argument, so it has no separate operand to drop with it. | ||||||||||||||||||||||||||||||||||||
| "--sysroot", | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consume the operand of a separate
GCC accepts Handle the separate form the same way as the joined form. The existing test requires the joined form to be omitted, so the separate form should also be omitted with its operand. Add Consume the operand of a separate --sysroot
Dropping
|
||||||||||||||||||||||||||||||||||||
| "-nostdinc", | ||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||
| .any(|p| arg.starts_with(p)) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// MSVC spells CMAKE_CXX_FLAGS with `/` (`/DWIN32 /EHsc /O2 /Ob2 /DNDEBUG`), and | ||||||||||||||||||||||||||||||||||||
| /// `link.exe` warns LNK4044 on each one it is handed. `/D` is a define unless it | ||||||||||||||||||||||||||||||||||||
| /// is one of the linker's own `/D…` options. | ||||||||||||||||||||||||||||||||||||
| pub fn is_msvc_compile_only(opt: &str) -> bool { | ||||||||||||||||||||||||||||||||||||
| const LINKER_D: [&str; 11] = [ | ||||||||||||||||||||||||||||||||||||
| "DEBUG", | ||||||||||||||||||||||||||||||||||||
| "DEBUGTYPE", | ||||||||||||||||||||||||||||||||||||
| "DEF", | ||||||||||||||||||||||||||||||||||||
| "DEFAULTLIB", | ||||||||||||||||||||||||||||||||||||
| "DELAY", | ||||||||||||||||||||||||||||||||||||
| "DELAYLOAD", | ||||||||||||||||||||||||||||||||||||
| "DELAYSIGN", | ||||||||||||||||||||||||||||||||||||
| "DEPENDENTLOADFLAG", | ||||||||||||||||||||||||||||||||||||
| "DLL", | ||||||||||||||||||||||||||||||||||||
| "DRIVER", | ||||||||||||||||||||||||||||||||||||
| "DYNAMICBASE", | ||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||
| if let Some(define) = opt.strip_prefix('D') { | ||||||||||||||||||||||||||||||||||||
| let name = define.split([':', '=']).next().unwrap_or(define); | ||||||||||||||||||||||||||||||||||||
| let head = format!("D{name}").to_ascii_uppercase(); | ||||||||||||||||||||||||||||||||||||
| return !LINKER_D.iter().any(|l| head == *l); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| matches!( | ||||||||||||||||||||||||||||||||||||
| opt, | ||||||||||||||||||||||||||||||||||||
| "GR" | "GR-" | "MD" | "MDd" | "MT" | "MTd" | "Zi" | "Z7" | "utf-8" | "bigobj" | "MP" | ||||||||||||||||||||||||||||||||||||
| ) || opt.starts_with("EH") | ||||||||||||||||||||||||||||||||||||
| || opt.starts_with("std:") | ||||||||||||||||||||||||||||||||||||
| || (opt.starts_with('O') && opt.len() <= 3 && !opt.contains(':')) | ||||||||||||||||||||||||||||||||||||
| || (opt.len() == 2 && opt.starts_with('W') && opt.as_bytes()[1].is_ascii_digit()) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// A file API fragment can hold several arguments ("-framework IOKit", | ||||||||||||||||||||||||||||||||||||
| /// "kernel32.lib user32.lib"); CMake double-quotes an argument with spaces. | ||||||||||||||||||||||||||||||||||||
| pub fn split_fragment(text: &str) -> Vec<String> { | ||||||||||||||||||||||||||||||||||||
| let mut out = Vec::new(); | ||||||||||||||||||||||||||||||||||||
| let mut current = String::new(); | ||||||||||||||||||||||||||||||||||||
| let mut quoted = false; | ||||||||||||||||||||||||||||||||||||
| let mut any = false; | ||||||||||||||||||||||||||||||||||||
| for c in text.chars() { | ||||||||||||||||||||||||||||||||||||
| match c { | ||||||||||||||||||||||||||||||||||||
| '"' => { | ||||||||||||||||||||||||||||||||||||
| quoted = !quoted; | ||||||||||||||||||||||||||||||||||||
| any = true; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| c if c.is_whitespace() && !quoted => { | ||||||||||||||||||||||||||||||||||||
| if any { | ||||||||||||||||||||||||||||||||||||
| out.push(std::mem::take(&mut current)); | ||||||||||||||||||||||||||||||||||||
| any = false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| c => { | ||||||||||||||||||||||||||||||||||||
| current.push(c); | ||||||||||||||||||||||||||||||||||||
| any = true; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if any { | ||||||||||||||||||||||||||||||||||||
| out.push(current); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| out | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,10 @@ use crate::anthropic::translate::{ | |||||||||||||||
| UpstreamFailureBody, MAX_IMAGES_PER_REQUEST, | ||||||||||||||||
| }; | ||||||||||||||||
| use crate::codex::translate::{self, error_body, failure_code, StreamState}; | ||||||||||||||||
| use crate::harness::{fit_reasoning_effort, text_only_ids, CatalogModel, Endpoint}; | ||||||||||||||||
| use crate::harness::{ | ||||||||||||||||
| fit_reasoning_effort, harness_header_value, text_only_ids, CatalogModel, DeclaredHarness, | ||||||||||||||||
| Endpoint, HARNESS_HEADER, | ||||||||||||||||
| }; | ||||||||||||||||
| use crate::io::output::{error_line, status_line}; | ||||||||||||||||
| use crate::net::decompress::Decoder; | ||||||||||||||||
| use crate::net::http1::{ResponseWriter, Server, ServerHandle, ServerRequest}; | ||||||||||||||||
|
|
@@ -362,9 +365,10 @@ fn stop_running_instance() { | |||||||||||||||
| runtime.upstream.drain_cancels(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// The `User-Agent` sent upstream. The contract's `Harness` enum has no Codex | ||||||||||||||||
| /// member, so there is no `X-RA-Harness` to declare; the agent string names it | ||||||||||||||||
| /// the way `upstream_user_agent` names the others. | ||||||||||||||||
| /// The `User-Agent` sent upstream. It names the harness the way | ||||||||||||||||
| /// `upstream_user_agent` names the others; the `X-RA-Harness` header comes from | ||||||||||||||||
| /// that same function, because the contract does carry `codex` | ||||||||||||||||
| /// (`Harness::KCodex`, added with release 2's contract family). | ||||||||||||||||
| pub fn upstream_user_agent() -> String { | ||||||||||||||||
|
Comment on lines
+369
to
372
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This doc says Prompt for AI agents
Suggested change
|
||||||||||||||||
| format!("wally/{} (codex)", crate::WALLY_VERSION) | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -405,7 +409,13 @@ pub fn start( | |||||||||||||||
| log_tag: "codex", | ||||||||||||||||
| stopping: AtomicBool::new(false), | ||||||||||||||||
| cancels: relay::cancel_worker(&upstream.console_url, &upstream.api_key), | ||||||||||||||||
| headers: vec![("User-Agent".to_string(), upstream_user_agent())], | ||||||||||||||||
| headers: vec![ | ||||||||||||||||
| ( | ||||||||||||||||
| HARNESS_HEADER.to_string(), | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This adds Prompt for AI agents |
||||||||||||||||
| harness_header_value(DeclaredHarness::KCodex).to_string(), | ||||||||||||||||
| ), | ||||||||||||||||
| ("User-Agent".to_string(), upstream_user_agent()), | ||||||||||||||||
| ], | ||||||||||||||||
| }, | ||||||||||||||||
| model: model.to_string(), | ||||||||||||||||
| catalog: cached_model_ids(), | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep
-Fand its directory on the link line.TAKES_SEPARATE_OPERANDlists-F.link_args_fromtherefore drops-Fand the directory after it. The merge-base filter kept both arguments. The filtered arguments reach Cargo throughcargo:rustc-link-arg, so the linker loses the framework search directory.With
CXXFLAGS="-F /opt/vendor/Frameworks"and-framework Vendor, the link fails whenVendor.frameworkexists only in that directory. The-Foption is a linker search option, so the pair must stay on the link line.Remove
-Ffrom the list. Update the array length to match. Update the include-flag test, and add a test that keeps the-Fpair.Filter list fix (
build_link_args.rs)Test expectations (
tests/test_wally_build_link_args.rs)for flag in [ "-isystem", "-I", - "-F", "-iframework", "-iquote", "-idirafter", ] { @@ +/// `-F` names a framework search directory, so its operand stays on the link line. +#[test] +fn framework_search_path_survives() { + assert_eq!( + kept("-F /opt/vendor/Frameworks -framework Vendor"), + vec![ + "-F".to_string(), + "/opt/vendor/Frameworks".to_string(), + "-framework".to_string(), + "Vendor".to_string(), + ] + ); +}