Skip to content

refactor: move runtime metadata into runs service - #497

Merged
delete-cloud merged 1 commit into
mainfrom
runtime-metadata-service
Jun 3, 2026
Merged

delete-cloud merged 1 commit into
mainfrom
runtime-metadata-service

Conversation

@delete-cloud

@delete-cloud delete-cloud commented Jun 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add RuntimeRunMetadataService for runtime run metadata construction and execution placement classification
  • route SessionManager and runtime observation through the shared placement helper
  • document the ADR-0058 completion and add focused metadata service coverage

Tests

  • uv run pytest tests/coding_agent/test_runtime_metadata_service.py tests/coding_agent/test_runtime_observation_service.py tests/coding_agent/test_runtime_run_persistence.py -v
  • uv run pytest tests/ui/test_session_manager_runtime.py -k "run_agent or resume_session or attached_executor" -v
  • uv run pytest tests/ui/test_http_server.py -k "attached_executor or external_executor" -v
  • uv run ruff check src/coding_agent/runs/metadata.py src/coding_agent/runs/observation.py src/coding_agent/runs/lifecycle.py src/coding_agent/runs/init.py src/coding_agent/server/session_manager.py tests/coding_agent/test_runtime_metadata_service.py
  • git diff --check

Review

  • Manual P1/P2 diff review completed locally; no actionable findings.

Summary by CodeRabbit

  • Tests

    • Added comprehensive unit tests for runtime metadata service validating local, cloud, and external worker execution scenarios
  • Refactor

    • Centralized runtime metadata and execution placement calculation into dedicated service for improved code organization
  • Documentation

    • Updated architecture decision record reflecting metadata handling delegation updates

@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extracts runtime metadata construction and execution-placement derivation into a centralized RuntimeRunMetadataService module. It updates RuntimeObservationService and SessionManager to use the new shared service instead of local helpers, adds comprehensive unit tests covering three execution binding types, and marks the architectural work as complete in the ADR.

Changes

Runtime Metadata Service Centralization

Layer / File(s) Summary
Core metadata service and protocol contracts
coding-agent/src/coding_agent/runs/metadata.py, coding-agent/src/coding_agent/runs/lifecycle.py
Define RuntimeMetadataSession protocol, runtime_execution_placement(binding) helper that maps execution binding types to placement strings, and RuntimeRunMetadataService.metadata_for_session() that assembles JSON metadata from session fields, optional resume context, and external-worker executor details. Extend RuntimeRunResumeContext with metadata() method.
Public API re-export
coding-agent/src/coding_agent/runs/__init__.py
Export RuntimeMetadataSession, RuntimeRunMetadataService, and runtime_execution_placement in the package's __all__ list.
Observation service switch to centralized helper
coding-agent/src/coding_agent/runs/observation.py
Update RuntimeObservationService to compute execution_placement via runtime_execution_placement(binding) instead of local _execution_placement() function; remove the local helper.
SessionManager wiring to centralized metadata service
coding-agent/src/coding_agent/server/session_manager.py
Instantiate _runtime_metadata_service in SessionManager.__init__(). Route all runtime metadata generation (attached-executor run creation, root run trace correlation, persistence wiring, wire-event correlation) through self._runtime_metadata_service.metadata_for_session() and runtime_execution_placement(session.execution_binding) instead of local implementations.
Unit tests and ADR documentation
coding-agent/tests/coding_agent/test_runtime_metadata_service.py, coding-agent/docs/adr/0058-local-daemon-control-plane-executor-architecture.md
Add fixtures and tests validating metadata_for_session() output for local, cloud workspace, and external worker execution bindings, verifying metadata field completeness, execution placement consistency, and workspace ref serialization. Mark ADR implementation work as completed.

🎯 3 (Moderate) | ⏱️ ~25 minutes


Possibly Related PRs

  • delete-cloud/Coding-Agent-Loop#380: Both touch SessionManager; #380 moves the implementation while this PR refactors its runtime metadata and execution-placement logic to use a centralized service.
  • delete-cloud/Coding-Agent-Loop#75: This PR builds directly on the execution_binding contract foundation introduced by #75, deriving execution placement from it via the new runtime_execution_placement() helper.

🐰 A metadata service hops in with glee,
Centralizing logic that once ran free.
No more scattered placement, no more duplication,
SessionManager and Observation find their true foundation. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 summarizes the primary change: moving runtime metadata handling into a dedicated runs service, which aligns with the main objective of introducing RuntimeRunMetadataService.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch runtime-metadata-service

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 and usage tips.

@delete-cloud

Copy link
Copy Markdown
Owner Author

Local fallback review note: CodeRabbit is still pending and has not produced actionable review output yet. I performed a manual P1/P2 review of the diff for correctness, data compatibility, scope, and test coverage. No actionable P1/P2 findings found.

Verification already run locally:

  • uv run pytest tests/coding_agent/test_runtime_metadata_service.py tests/coding_agent/test_runtime_observation_service.py tests/coding_agent/test_runtime_run_persistence.py -v
  • uv run pytest tests/ui/test_session_manager_runtime.py -k "run_agent or resume_session or attached_executor" -v
  • uv run pytest tests/ui/test_http_server.py -k "attached_executor or external_executor" -v
  • uv run ruff check src/coding_agent/runs/metadata.py src/coding_agent/runs/observation.py src/coding_agent/runs/lifecycle.py src/coding_agent/runs/init.py src/coding_agent/server/session_manager.py tests/coding_agent/test_runtime_metadata_service.py
  • git diff --check

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
coding-agent/tests/coding_agent/test_runtime_metadata_service.py (1)

77-96: ⚡ Quick win

Consider adding test coverage for external worker with workspace_ref=None.

The implementation correctly handles workspace_ref=None by omitting it from the metadata dict, but there's no test case verifying this behavior. Adding a test would improve coverage.

🧪 Suggested test case
def test_runtime_metadata_service_omits_none_workspace_ref() -> None:
    service = RuntimeRunMetadataService()
    binding = ExternalWorkerBinding(
        executor_kind="local_cli",
        worker_pool="pool-a",
        workspace_ref=None,
    )

    metadata = service.metadata_for_session(FakeSession(execution_binding=binding))

    assert "workspace_ref" not in metadata
    assert metadata["executor_kind"] == "local_cli"
    assert metadata["worker_pool"] == "pool-a"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@coding-agent/tests/coding_agent/test_runtime_metadata_service.py` around
lines 77 - 96, Add a new unit test that verifies
RuntimeRunMetadataService.metadata_for_session omits the workspace_ref key when
an ExternalWorkerBinding is created with workspace_ref=None: instantiate
RuntimeRunMetadataService, create
ExternalWorkerBinding(executor_kind="local_cli", worker_pool="pool-a",
workspace_ref=None), call metadata_for_session with a
FakeSession(execution_binding=binding), then assert "workspace_ref" not in
metadata and that metadata["executor_kind"] == "local_cli" and
metadata["worker_pool"] == "pool-a"; you can mirror the existing
test_runtime_metadata_service_reports_external_worker_metadata structure and
also assert runtime_execution_placement(binding) if desired.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@coding-agent/tests/coding_agent/test_runtime_metadata_service.py`:
- Around line 77-96: Add a new unit test that verifies
RuntimeRunMetadataService.metadata_for_session omits the workspace_ref key when
an ExternalWorkerBinding is created with workspace_ref=None: instantiate
RuntimeRunMetadataService, create
ExternalWorkerBinding(executor_kind="local_cli", worker_pool="pool-a",
workspace_ref=None), call metadata_for_session with a
FakeSession(execution_binding=binding), then assert "workspace_ref" not in
metadata and that metadata["executor_kind"] == "local_cli" and
metadata["worker_pool"] == "pool-a"; you can mirror the existing
test_runtime_metadata_service_reports_external_worker_metadata structure and
also assert runtime_execution_placement(binding) if desired.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d40475d-9d4e-423c-9e6a-a85d9ed09845

📥 Commits

Reviewing files that changed from the base of the PR and between 404ce1a and 1871626.

📒 Files selected for processing (7)
  • coding-agent/docs/adr/0058-local-daemon-control-plane-executor-architecture.md
  • coding-agent/src/coding_agent/runs/__init__.py
  • coding-agent/src/coding_agent/runs/lifecycle.py
  • coding-agent/src/coding_agent/runs/metadata.py
  • coding-agent/src/coding_agent/runs/observation.py
  • coding-agent/src/coding_agent/server/session_manager.py
  • coding-agent/tests/coding_agent/test_runtime_metadata_service.py

@delete-cloud
delete-cloud merged commit 5e0fc46 into main Jun 3, 2026
1 check passed
@delete-cloud
delete-cloud deleted the runtime-metadata-service branch June 3, 2026 05:52
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.

1 participant