Skip to content

fix(agents): preserve string filter names - #163

Open
floze-the-genius wants to merge 1 commit into
SongshGeoLab:masterfrom
floze-the-genius:fix/152-select-string-filter
Open

floze-the-genius wants to merge 1 commit into
SongshGeoLab:masterfrom
floze-the-genius:fix/152-select-string-filter

Conversation

@floze-the-genius

@floze-the-genius floze-the-genius commented Aug 14, 2026

Copy link
Copy Markdown

Summary

  • preserve string attribute names before ActorsList.select rebinds filter_func to its predicate closure
  • make the public type annotation match the documented string, dictionary, callable, and None filter forms
  • add parameterized coverage for all three filter forms and an end-to-end HumanModule.actors regression test

Root cause

The string branch defined a nested function with the same name as its filter_func argument. Python resolves that closure variable when the predicate runs, after the local name has been rebound to the nested function itself. getattr therefore received a function instead of the original attribute-name string.

Fixes #152.

Testing

Before the fix, the new targeted regression run produced exactly two failures and two passes: the string form and HumanModule.actors raised TypeError, while dictionary and callable filters passed.

After the fix:

  • targeted regression cases: 4 passed
  • tests/api/test_sequence.py and tests/api/test_human.py: 22 passed
  • full pytest suite: 680 passed
  • ruff check abses/: passed
  • mypy abses/: passed for 54 source files; the final widened signature was also checked directly
  • git diff --check: passed

Summary by CodeRabbit

  • New Features

    • Enhanced actor filtering to support attribute names and attribute-value criteria, in addition to custom filter functions.
    • Actor collections now correctly return only actors matching the selected criteria.
  • Bug Fixes

    • Corrected filtering behavior when using attribute-based selection.
    • Ensured module-level actor collections exclude actors created outside the module’s location.
  • Tests

    • Added coverage for string, dictionary, and callable filters, plus module actor membership.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e20f2a9-e6da-470d-8904-2aa48ddc120f

📥 Commits

Reviewing files that changed from the base of the PR and between 8f06d56 and 6542a70.

📒 Files selected for processing (3)
  • abses/agents/sequences.py
  • tests/api/test_human.py
  • tests/api/test_sequence.py

📝 Walkthrough

Walkthrough

ActorsList.select now supports callable, dictionary, and string filters. String filters preserve the requested attribute name. Tests cover all filter forms and human-module actor exposure.

Changes

ActorsList selection

Layer / File(s) Summary
Add string and dictionary filter support
abses/agents/sequences.py
ActorsList.select accepts dictionary and string filters. Dictionary predicates use key_value_pairs. String predicates preserve the attribute name in attr_name.
Validate selection and actor exposure
tests/api/test_sequence.py, tests/api/test_human.py
Parameterized tests cover string, dictionary, and callable filters. Human-module tests verify that actors exposes earth-local agents only.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 6542a

The change preserves supported string, dictionary, callable, and None filter behavior, with regression coverage and all reported checks passing; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary fix: preserving string filter names in agent selection.
Linked Issues check ✅ Passed The implementation fixes string filters, updates the public annotation, and adds the required selection and HumanModule.actors regression tests for issue #152.
Out of Scope Changes check ✅ Passed All code and test changes directly support the string-filter fix and the acceptance criteria in issue #152.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

ActorsList.select("属性名") 必然抛 TypeError(闭包变量重绑定)

1 participant