Skip to content

Add pre-suite persona cleanup fixture#788

Open
mendral-app[bot] wants to merge 3 commits into
mainfrom
mendral/add-persona-cleanup-fixture
Open

Add pre-suite persona cleanup fixture#788
mendral-app[bot] wants to merge 3 commits into
mainfrom
mendral/add-persona-cleanup-fixture

Conversation

@mendral-app
Copy link
Copy Markdown

@mendral-app mendral-app Bot commented Apr 24, 2026

Summary

  • Add a session-scoped autouse pytest fixture that deletes all non-important active personas before the test session starts, preventing accumulated leaked personas from previous (possibly crashed) CI runs from exhausting the staging account's 10-persona limit (HTTP 429)
  • Remove the redundant test_does_nothing_expect_cleanup_personas test since the fixture now handles cleanup automatically before any tests run

Details

Problem: All 9 tests in tests/integration/sdk/test_personas.py were failing with HTTP 429 (Max active personas limit exceeded) because prior CI runs left personas open without cleaning them up, eventually hitting the 10-persona cap.

Fix: A new tests/integration/sdk/conftest.py with a cleanup_all_personas session-scoped autouse fixture that:

  1. Lists all active personas on the staging account
  2. Deletes any that aren't in the protected "important personas" set (used by frontend tests and other suites)
  3. Runs before any test in the session, ensuring a clean slate
  4. Uses best-effort error handling so cleanup failures don't block the test suite

Related insight: https://app.mendral.com/insights/01KQ0X2XXZ0CFVGJMBDPTHMN7B


Note

Created by Mendral. Tag @mendral-app with feedback or questions.

mendral-app Bot added 2 commits April 24, 2026 16:29
Add a session-scoped autouse pytest fixture in tests/integration/sdk/conftest.py
that deletes all non-important active personas before the test session starts.
This prevents accumulated leaked personas from previous CI runs from exhausting
the staging account's 10-persona limit (HTTP 429).

- Create conftest.py with cleanup_all_personas fixture
- Preserve important persona IDs used by frontend and other test suites
- Remove redundant test_does_nothing_expect_cleanup_personas test
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR replaces the ad-hoc test_does_nothing_expect_cleanup_personas function with a proper session-scoped autouse pytest fixture in a new conftest.py. The fixture runs _delete_non_important_personas both before and after the session, with error logging, addressing the HTTP 429 failures caused by leaked personas from prior CI runs. Previous review findings (silent error suppression, missing teardown) have been resolved in this iteration.

Confidence Score: 5/5

Safe to merge — changes are well-structured test infrastructure with no production code impact.

Only P2 findings; the fixture implementation is correct, previous review issues are addressed, and the removal of the pseudo-test is appropriate.

No files require special attention.

Important Files Changed

Filename Overview
tests/integration/sdk/conftest.py New session-scoped autouse fixture that deletes non-important personas before and after the test session, with proper error logging and symmetric teardown — previous review issues (silent suppression, missing teardown) are addressed.
tests/integration/sdk/test_personas.py Removes the ad-hoc cleanup pseudo-test test_does_nothing_expect_cleanup_personas; its responsibility is now correctly handled by the conftest fixture.

Fix All in Claude Code

Prompt To Fix All With AI
This is a comment left during a code review.
Path: tests/integration/sdk/conftest.py
Line: 24-56

Comment:
**No new integration tests added**

This PR is a bug fix (HTTP 429 from leaked personas) but removes a test without adding a replacement. The fixture itself is infrastructure — it doesn't assert any new behavior. Per the team's guideline, bug-fix PRs should include at least one new integration test (e.g., a test that verifies the fixture's cleanup logic actually removes a persona it shouldn't keep).

**Context Used:** # Test guidelines
- Add a comment if the PR does n... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "fix: add error logging and post-session ..." | Re-trigger Greptile

Comment thread tests/integration/sdk/conftest.py Outdated
Comment on lines +42 to +47
if persona.persona_id not in IMPORTANT_PERSONAS:
try:
client.personas.delete(persona.persona_id)
except Exception:
pass # best-effort cleanup
except Exception:
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 Silent error suppression hides cleanup failures

Both except Exception: pass blocks silently discard all errors, making it impossible to distinguish between "cleanup succeeded" and "cleanup silently failed" in CI logs. A warnings.warn or print on the outer block would at least surface API connectivity issues without blocking the suite.

Suggested change
if persona.persona_id not in IMPORTANT_PERSONAS:
try:
client.personas.delete(persona.persona_id)
except Exception:
pass # best-effort cleanup
except Exception:
except Exception as e:
print(f"[cleanup_all_personas] persona listing failed, skipping cleanup: {e}") # best-effort
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/integration/sdk/conftest.py
Line: 42-47

Comment:
**Silent error suppression hides cleanup failures**

Both `except Exception: pass` blocks silently discard all errors, making it impossible to distinguish between "cleanup succeeded" and "cleanup silently failed" in CI logs. A `warnings.warn` or `print` on the outer block would at least surface API connectivity issues without blocking the suite.

```suggestion
    except Exception as e:
        print(f"[cleanup_all_personas] persona listing failed, skipping cleanup: {e}")  # best-effort
```

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed — both except blocks now log the error with a [cleanup_all_personas] prefix and the phase (setup/teardown), so failures are visible in CI logs without blocking the suite. Also extracted the cleanup logic into a _delete_non_important_personas helper to keep it DRY with the new teardown pass.

Comment thread tests/integration/sdk/conftest.py Outdated
Comment on lines +41 to +49
for persona in client.personas.list(page_size=100):
if persona.persona_id not in IMPORTANT_PERSONAS:
try:
client.personas.delete(persona.persona_id)
except Exception:
pass # best-effort cleanup
except Exception:
pass # don't block the test suite if cleanup itself fails

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 No post-session cleanup

The fixture only runs cleanup before the suite (pre-yield) and does nothing after. Personas leaked by a crash in the current run won't be cleaned up until the next CI run, which may still hit the 10-persona cap if several runs overlap. Adding a symmetric teardown pass after yield would keep the account clean regardless of which run crashed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/integration/sdk/conftest.py
Line: 41-49

Comment:
**No post-session cleanup**

The fixture only runs cleanup *before* the suite (pre-`yield`) and does nothing after. Personas leaked by a crash in the *current* run won't be cleaned up until the next CI run, which may still hit the 10-persona cap if several runs overlap. Adding a symmetric teardown pass after `yield` would keep the account clean regardless of which run crashed.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed — the fixture now runs a symmetric teardown pass after yield, so personas created during the current run are cleaned up even if individual test teardowns fail. Extracted the cleanup into a _delete_non_important_personas(phase) helper that runs in both setup and teardown phases.

Address review feedback:
- Log errors instead of silently suppressing them in except blocks
- Add symmetric teardown pass after yield to clean up personas leaked
  by the current run
- Extract cleanup logic into helper to avoid duplication
@mendral-app mendral-app Bot marked this pull request as ready for review April 24, 2026 23:54
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.

0 participants