Skip to content

fix: various bugs#165

Open
Cedric / ViaDézo1er (viadezo1er) wants to merge 5 commits intomainfrom
cedric/various-bug-fix
Open

fix: various bugs#165
Cedric / ViaDézo1er (viadezo1er) wants to merge 5 commits intomainfrom
cedric/various-bug-fix

Conversation

@viadezo1er
Copy link
Copy Markdown
Contributor

@viadezo1er Cedric / ViaDézo1er (viadezo1er) commented Apr 30, 2026

Concurrency issue with multiple bt switch (although it seems unlikely it would have ever triggered)
Unicode issues causing thread panic (try bt sync pull --window 1é on the main branch)
bt functions pull could ask for rows with invalid project id
bt view logs/trace next page hint lacked the --limit argument
Replace manual .tmp file write with tempfile::NamedTempFile
Deduplicate parse_duration_to_seconds

unicode issues (try bt sync pull --window 1é)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

Latest downloadable build artifacts for this PR commit 3dab7fc192bd:

Available artifact names
  • ``artifacts-build-global
  • ``artifacts-build-local-x86_64-apple-darwin
  • ``artifacts-build-local-x86_64-pc-windows-msvc
  • ``artifacts-build-local-aarch64-pc-windows-msvc
  • ``artifacts-build-local-x86_64-unknown-linux-musl
  • ``artifacts-build-local-x86_64-unknown-linux-gnu
  • ``artifacts-build-local-aarch64-unknown-linux-gnu
  • ``artifacts-build-local-aarch64-apple-darwin
  • ``artifacts-plan-dist-manifest
  • ``cargo-dist-cache

@viadezo1er Cedric / ViaDézo1er (viadezo1er) changed the title fix: concurrency issue with multiple bt switch fix: various bugs May 1, 2026
@viadezo1er
Copy link
Copy Markdown
Contributor Author

Cedric / ViaDézo1er (viadezo1er) commented May 1, 2026

Normal call, 1 slug is requested 1 function is seen:

bt functions pull demo-prompt-3 --json
{"status":"partial","projects_total":1,"files_written":0,"files_skipped":1,"files_failed":0,"functions_seen":1,"functions_materialized":0,"malformed_records_skipped":0,"unsupported_records_skipped":0,"files":[{"output_file":"/workspace/bt-various-bug-fix/demo/braintrust/aaa.ts","status":"skipped","skipped_reason":"dirty_target"}],"warnings":[],"errors":[]}

Buggy call, 2 slugs requested 3 functions seen:

bt functions pull demo-prompt-3 demo-prompt-2 --json
{"status":"partial","projects_total":1,"files_written":0,"files_skipped":1,"files_failed":0,"functions_seen":3,"functions_materialized":0,"malformed_records_skipped":0,"unsupported_records_skipped":0,"files":[{"output_file":"/workspace/bt-various-bug-fix/demo/braintrust/aaa.ts","status":"skipped","skipped_reason":"dirty_target"}],"warnings":[],"errors":[]}

The API endpoint used to get functions only accepts 1 slug id.
Therefore to get multiple slugs, either you make 1 requests fetching all slugs, or you make multiple requests. I'm not sure which one is better, currently 1 request is made, not changing this behavior.

This code could be used if multiple requests are deemed better.

diff --git a/src/functions/pull.rs b/src/functions/pull.rs
index 8f2e6de..4fa9ffa 100644
--- a/src/functions/pull.rs
+++ b/src/functions/pull.rs
@@ -185,16 +185,44 @@ pub async fn run(base: BaseArgs, args: PullArgs) -> Result<()> {
         ProgressBar::hidden()
     };
 
-    let fetched = match fetch_all_function_rows(&auth_ctx.client, &query).await {
-        Ok(fetched) => fetched,
-        Err(err) => {
-            spinner.finish_and_clear();
-            return fail_pull(
-                &base,
-                &mut summary,
-                HardFailureReason::PaginationUnsupported,
-                err.to_string(),
-            );
+    let fetched = if resolved_slugs.len() > 1 {
+        // Issue one request per slug so the server filters server-side.
+        let mut merged = FetchRowsResult {
+            rows: Vec::new(),
+            warnings: Vec::new(),
+        };
+        for slug in &resolved_slugs {
+            let mut slug_query = query.clone();
+            slug_query.slug = Some(slug.clone());
+            match fetch_all_function_rows(&auth_ctx.client, &slug_query).await {
+                Ok(result) => {
+                    merged.rows.extend(result.rows);
+                    merged.warnings.extend(result.warnings);
+                }
+                Err(err) => {
+                    spinner.finish_and_clear();
+                    return fail_pull(
+                        &base,
+                        &mut summary,
+                        HardFailureReason::PaginationUnsupported,
+                        err.to_string(),
+                    );
+                }
+            }
+        }
+        merged
+    } else {
+        match fetch_all_function_rows(&auth_ctx.client, &query).await {
+            Ok(fetched) => fetched,
+            Err(err) => {
+                spinner.finish_and_clear();
+                return fail_pull(
+                    &base,
+                    &mut summary,
+                    HardFailureReason::PaginationUnsupported,
+                    err.to_string(),
+                );
+            }
         }
     };
     summary.functions_seen = fetched.rows.len();

@viadezo1er
Copy link
Copy Markdown
Contributor Author

Cedric / ViaDézo1er (viadezo1er) commented May 1, 2026

The server validates all the rows anyway but it's better to choose only the rows bt functions pull.
winners are the selected rows, but materializable is the subset that can be chosen.

So not a bug per se but could have become one.

@viadezo1er
Copy link
Copy Markdown
Contributor Author

Cedric / ViaDézo1er (viadezo1er) commented May 1, 2026

These projects are from a personal org, you have to select different project ids if you want to test it yourself.

bt view logs --non-interactive --limit 1 --since 2026-05-01T00:00:00Z --object-ref project_logs:b667bd4c-7e55-49e0-a370-f6526e6bbccd
bt view logs [summary]: returned 1 row(s) (object_ref=project_logs:b667bd4c-7e55-49e0-a370-f6526e6bbccd, limit=1, preview_length=125)
  1. created=2026-05-01T20:48:39.870Z root_span_id=6304a076-193f-4bce-9eb9-b37ecf46c2e2 id=6d0e6f48-82f3-44a8-ade1-ec47a4c5b5d9 span_id=6304a076-193f-4bce-9eb9-b37ecf46c2e2 input={"q":"query 59"}

Truncated fields use preview_length=125.
next_cursor: afURqKAzADs
next: bt view logs --object-ref project_logs:b667bd4c-7e55-49e0-a370-f6526e6bbccd --cursor afURqKAzADs --non-interactive

The command to show the next page drops the --limit argument, showing 50 rows (the default).

Now does not drop the argument:

bt view logs --non-interactive --limit 1 --since 2026-05-01T00:00:00Z --object-ref project_logs:b667bd4c-7e55-49e0-a370-f6526e6bbccd
bt view logs [summary]: returned 1 row(s) (object_ref=project_logs:b667bd4c-7e55-49e0-a370-f6526e6bbccd, limit=1, preview_length=125)
  1. created=2026-05-01T20:48:39.870Z root_span_id=6304a076-193f-4bce-9eb9-b37ecf46c2e2 id=6d0e6f48-82f3-44a8-ade1-ec47a4c5b5d9 span_id=6304a076-193f-4bce-9eb9-b37ecf46c2e2 input={"q":"query 59"}

Truncated fields use preview_length=125.
next_cursor: afURqKAzADs
next: bt view logs --object-ref project_logs:b667bd4c-7e55-49e0-a370-f6526e6bbccd --cursor afURqKAzADs --non-interactive --limit 1

bt view trace has the same issue.

@viadezo1er Cedric / ViaDézo1er (viadezo1er) marked this pull request as ready for review May 1, 2026 23:05
@AbhiPrasad
Copy link
Copy Markdown
Member

let's just make these all individual prs. easier to revert that way.

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.

2 participants