Skip to content

Conversation

@enyst
Copy link
Collaborator

@enyst enyst commented Nov 6, 2025

Summary
Enable Ruff rules that catch mutable default pitfalls:

  • B006 (mutable-argument-default)
  • B008 (function-call-in-default-argument)
  • B039 (mutable-contextvar-default)
  • RUF012 (mutable-class-default)

Changes

  • pyproject.toml: add extend-select = ["B006", "B008", "B039", "RUF012"] under [tool.ruff.lint]

Context
Motivated by a review thread on the visualization API discussing mutable defaults. On main, our Ruff config selected only E, F, I, UP, ARG. Pre-commit and CI therefore did not flag these cases.

Impact
A local run surfaced:

  • 20× B008
  • 8× RUF012
  • 2× B006
  • 0× B039

Follow-ups

  • Address reported violations in subsequent PR(s), or allowlist intentional patterns using flake8-bugbear options where appropriate.

Closes: #1054

Co-authored-by: openhands [email protected]

@enyst can click here to continue refining the PR


Agent Server images for this PR

GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.12-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:6ef3209-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-6ef3209-python \
  ghcr.io/openhands/agent-server:6ef3209-python

All tags pushed for this build

ghcr.io/openhands/agent-server:6ef3209-golang-amd64
ghcr.io/openhands/agent-server:6ef3209-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:6ef3209-golang-arm64
ghcr.io/openhands/agent-server:6ef3209-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:6ef3209-java-amd64
ghcr.io/openhands/agent-server:6ef3209-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:6ef3209-java-arm64
ghcr.io/openhands/agent-server:6ef3209-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:6ef3209-python-amd64
ghcr.io/openhands/agent-server:6ef3209-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-amd64
ghcr.io/openhands/agent-server:6ef3209-python-arm64
ghcr.io/openhands/agent-server:6ef3209-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-arm64
ghcr.io/openhands/agent-server:6ef3209-golang
ghcr.io/openhands/agent-server:6ef3209-java
ghcr.io/openhands/agent-server:6ef3209-python

About Multi-Architecture Support

  • Each variant tag (e.g., 6ef3209-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 6ef3209-python-amd64) are also available if needed

- Add extend-select to enable flake8-bugbear rules B006, B008, B039 and Ruff RUF012
- These catch mutable defaults in function args, default-call patterns, ContextVar defaults, and mutable class attributes

Co-authored-by: openhands <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   file_router.py572556%40, 56–58, 69–73, 78–79, 83–84, 88, 94–98, 109–112, 115–116
openhands-sdk/openhands/sdk/agent
   agent.py1515464%136, 140–141, 148–149, 151–153, 155–157, 173, 188–190, 197–199, 201, 205, 208–209, 211, 218, 244, 249, 280, 284, 289, 300, 303, 325–327, 329, 341–342, 347–348, 363–366, 375–376, 381, 393–394, 399–400, 432, 439–440, 459
TOTAL11916553253% 

enyst and others added 5 commits November 7, 2025 21:13
- Add fastapi.Depends and fastapi.params.Depends to flake8-bugbear extend-immutable-calls
- This keeps B008 enabled while ignoring the idiomatic FastAPI pattern

Co-authored-by: openhands <[email protected]>
- Change file: UploadFile = File(...) -> file: Annotated[UploadFile, File(...)]
- Removes the last non-Depends B008 while preserving FastAPI semantics

Co-authored-by: openhands <[email protected]>
- Change default list params to Optional and coalesce to [] inside
- Ensures no shared mutable defaults, keeps behavior identical for callers

Co-authored-by: openhands <[email protected]>
…needed

- Use Field(default_factory=...) for lists/dicts in tests
- Switch VisualizerCustomAction.task_list to default_factory
- Add pydantic.Field imports in affected tests

Co-authored-by: openhands <[email protected]>
@OpenHands OpenHands deleted a comment from openhands-ai bot Nov 8, 2025
@enyst enyst marked this pull request as ready for review November 8, 2025 19:42
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.

Ruff config missing mutable-default checks (B006, B008, B039, RUF012)

2 participants