Skip to content

Memory update from review of PR #16#18

Open
arcanist[bot] wants to merge 2 commits into
mainfrom
memory/update-from-pr-16
Open

Memory update from review of PR #16#18
arcanist[bot] wants to merge 2 commits into
mainfrom
memory/update-from-pr-16

Conversation

@arcanist
Copy link
Copy Markdown

@arcanist arcanist Bot commented Apr 19, 2026

Memory updates from PR #16

Add: Checking Optional fields on Pydantic models using hasattr

Type: gotcha

Memory:

When checking if a Pydantic BaseModel field is set/truthy, never use hasattr() — all declared fields always have the attribute. Use an explicit is not None check (or is not None + not-empty) instead. E.g., decision.params if decision.params is not None else {}.

Rationale:

The agent had hasattr(decision, 'params') which is always True for Pydantic models, silently passing None to tools. This is a non-obvious footgun that a competent engineer could easily repeat. The fix is a clear, actionable pattern: never use hasattr for Pydantic field presence checks.

Why this is a memory (not a convention update): This is a situational pattern that helps the agent in specific contexts, not a permanent rule for all future code.

Referenced files: nons/core/agents/agent.py


Add: Operators or transforms that cache results and process dataclass objects

Type: gotcha

Memory:

When modifying dataclass objects inside operator transform() methods (or any caching pipeline), never mutate fields in-place — use dataclasses.replace() to create a new instance. In-place mutation changes the object's hash, corrupting cache keys and causing unbounded cache growth.

Rationale:

ExtractWinners was mutating Candidate.score in-place, breaking cache key stability. The fix (dataclasses.replace) is non-obvious since Python dataclasses are mutable by default and the silent cache corruption would only appear under load. This pattern applies anywhere the codebase uses cached operators over dataclass inputs.

Why this is a memory (not a convention update): This is a situational pattern that helps the agent in specific contexts, not a permanent rule for all future code.

Referenced files: nons/operators/deterministic.py


Sessions: 9db00177-844e-4c98-8cbd-e0c7354f9f04

Merge to apply. Close to discard.

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