Skip to content

feat(workers): use types for worker messages#1767

Merged
paul-nechifor merged 2 commits intodevfrom
paul/fix/type-worker-requests
Apr 9, 2026
Merged

feat(workers): use types for worker messages#1767
paul-nechifor merged 2 commits intodevfrom
paul/fix/type-worker-requests

Conversation

@paul-nechifor
Copy link
Copy Markdown
Contributor

Problem

Closes DIM-XXX

Solution

Breaking Changes

How to Test

Contributor License Agreement

  • I have read and approved the CLA.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 9, 2026

Greptile Summary

This PR refactors worker inter-process communication to use typed frozen dataclasses (DeployModuleRequest, CallMethodRequest, etc.) instead of presumably untyped structures, and introduces a WorkerResponse type for replies. The structural pattern matching in _worker_loop is updated to destructure the new typed messages, and python_worker.py gains strong type annotations throughout.

Confidence Score: 5/5

Safe to merge — the refactor is a clean drop-in of typed frozen dataclasses with no logic changes.

All findings are P2 style suggestions. The typed message classes are well-structured, pickling is correct, structural pattern matching aligns with the new types, and the shutdown/locking flow is unchanged and correct.

No files require special attention.

Vulnerabilities

No security concerns identified. Messages are exchanged only over a local multiprocessing.connection.Connection (pipe), not a network socket. No secrets are exposed, and input validation is handled by Python's structural pattern matching with typed dataclasses.

Important Files Changed

Filename Overview
dimos/core/coordination/worker_messages.py New module defining typed frozen dataclasses for worker messages; frozen=True on DeployModuleRequest and CallMethodRequest does not prevent in-place mutation of their dict fields.
dimos/core/coordination/python_worker.py Updated to import and use typed message dataclasses; structural pattern matching, locking, and shutdown flow all look correct.

Sequence Diagram

sequenceDiagram
    participant P as PythonWorker (parent)
    participant C as Connection (pipe)
    participant W as _worker_loop (child)

    P->>C: DeployModuleRequest(module_id, module_class, kwargs)
    C->>W: recv()
    W-->>C: WorkerResponse(result=module_id)
    C-->>P: recv()

    P->>C: SetRefRequest(module_id, ref=actor)
    C->>W: recv()
    W-->>C: WorkerResponse(result=worker_id)
    C-->>P: recv()

    P->>C: CallMethodRequest(module_id, name, args, kwargs)
    C->>W: recv()
    W-->>C: WorkerResponse(result=return_value)
    C-->>P: recv()

    P->>C: GetAttrRequest(module_id, name)
    C->>W: recv()
    W-->>C: WorkerResponse(result=attr_value)
    C-->>P: recv()

    P->>C: UndeployModuleRequest(module_id)
    C->>W: recv()
    W-->>C: WorkerResponse(result=True)
    C-->>P: recv()

    P->>C: ShutdownRequest()
    C->>W: recv()
    W-->>C: WorkerResponse(result=True)
    C-->>P: poll + recv()
Loading

Reviews (1): Last reviewed commit: "feat(workers): use types for worker mess..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@leshy leshy left a comment

Choose a reason for hiding this comment

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

great, this stuff is cool for logging also, as you can write str on these etc

@paul-nechifor paul-nechifor enabled auto-merge (squash) April 9, 2026 06:29
@paul-nechifor paul-nechifor merged commit eb04e60 into dev Apr 9, 2026
3 of 4 checks passed
@paul-nechifor paul-nechifor deleted the paul/fix/type-worker-requests branch April 9, 2026 06:29
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.

2 participants