Skip to content

Give the file bridge and container registry the request's Unit of Work, and the sweepers a worker one #1478

Description

@peteski22

Problem

The backend standards (.github/skills/backend-standards/SKILL.md, "Who commits") give each request one Unit of Work, from get_unit_of_work, and each worker job one, from create_unit_of_work(). Four places build their own instead.

Over the request's session, both in api/deps.py:

  • build_sandbox_file_bridge: UnitOfWork(db). Recording the files a provider's code produced now runs here too, through SandboxFileBridge.copy_provider_files, so it shares this Unit of Work.
  • build_sandbox_container_registry: UnitOfWork(db).

Over a worker session, each opening create_session() and then building a UnitOfWork by hand:

  • run_file_sweeper in services/files/file_sweeper.py;
  • run_sandbox_container_sweeper in services/code_execution/container_sweeper.py.

A UnitOfWork counts its open blocks on the object itself. So a second one over the same session does not see a block the first has open, and the rule that an inner block joins the outer one no longer holds between them. RequestContext has no Unit of Work to hand on today: it carries the session as db.

Proposal

Put the request's Unit of Work on RequestContext, and pass it to the file bridge and to the sandbox container registry. Have both sweepers use create_unit_of_work(). That also removes the need to trace whether a block is open when this code runs.

Acceptance

  • In src/gateway/, outside core/unit_of_work.py, only get_unit_of_work constructs a UnitOfWork.
  • The file bridge, container registry and both sweeper tests pass.

Part of #1470.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/backendBackend service implementationtype/tech-debtMaintenance and cleanup

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions