Skip to content

fix: key project id cache by full project identity - #1188

Open
Chen Yufeiyang (feiiiiii5) wants to merge 2 commits into
braintrustdata:mainfrom
feiiiiii5:feiiiiii5/1126-D303
Open

Chen Yufeiyang (feiiiiii5) wants to merge 2 commits into
braintrustdata:mainfrom
feiiiiii5:feiiiiii5/1126-D303

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Summary

ProjectIdCache.get_by_name() posted the project's org, name, and group to the API, but cached the resulting ID under project_name alone. A second lookup with the same name in a different project group returned the first group's ID without any API call. Since Project.publish() and CLI push use this cache, two projects sharing a name across groups could have their prompts and parameters published to the wrong project.

Fix

Key _name_cache by the full identity (org_name, project_name, project_group_name). The ungrouped (None) case stays distinct from a named group. Public API and single-group behavior are unchanged.

Verification

  • Three new focused regression tests: base-red 2 failed / 1 passed (cross-group collision and ungrouped-vs-grouped reuse both returned the wrong cached ID); with fix 3/3 passed.
  • Related suites: test_framework2.py + new module 25 passed; CLI push modules (test_push_evaluator.py, test_push.py) 15 passed.
  • ruff check and ruff format --check clean.

Mocks only — no live API, network, or credentials. Full repo suite / nox matrix and Python 3.14 not run (verified on available 3.11 with plugin autoload disabled).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T08:14:49.081136Z e053207 New commits
ℹ️ About Codex in GitHub

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

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 462b77e0e7

ℹ️ 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 (@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 (@codex) address that feedback".

return mock_state


def test_get_by_name_does_not_collide_across_project_groups():

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 Move the cache regression tests into the collected core suite

The nox job in .github/workflows/checks.yaml reaches _run_core_tests() in py/noxfile.py, which passes only src/braintrust as pytest's collection target (pytest --help: [file_or_dir] [file_or_dir] [...]). The other nox sessions targeting tests/ collect only tests/api_codegen or tests/wheel, so none of these three new regression tests runs in the configured CI suite. This leaves the cross-group cache collision without CI regression coverage. Move these tests into the existing py/src/braintrust/test_framework2.py or another collected core module, consistent with AGENTS.md's instruction to “Keep tests close to the code they cover.”

AGENTS.md reference: AGENTS.md:L333-L333

Useful? React with 👍 / 👎.

@feiiiiii5

Copy link
Copy Markdown
Contributor Author

Addressed the Codex finding about test collection. The three ProjectIdCache regression tests were in py/tests/ and would not be collected by nox -s test_core (_run_core_tests passes only src/braintrust to pytest). They are now appended to src/braintrust/test_framework2.py, which CI does collect. Branch head updated to e053207; the full module passes (25 tests) and ruff check / ruff format --check are clean. The fix in framework2.py is unchanged.

This branch has not been deployed

No deployments
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