terraphim / terraphim/terraphim-ai

Implement JSONL RPC envelope for agent-orchestrator communication

Open
#688 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
62
Forks
5
Avg merge
2h 27m
Merged PRs (30d)
1

Description

Context

ADF currently communicates with agents via unstructured stdout/stderr pipes. This causes:

  • SIGPIPE kills when stderr pipe is dropped
  • Fragile text parsing for cost/session/status extraction
  • No message framing, idempotency, or error typing

Proposal

Implement a JSONL envelope protocol inspired by Piwork's taskd RPC spec (docs/runtime-taskd-rpc-spec.md).

Envelope Format

Agent -> Orchestrator (event):

{"type": "event", "event": "cost_update", "agent": "security-sentinel", "ts": "...", "payload": {...}}

Orchestrator -> Agent (command, future):

{"id": "req_01", "type": "pause", "payload": {"reason": "budget_exceeded"}}
Key Properties
  • Strict envelope: {type, event/id, payload} (payload required even if empty)
  • Idempotency: duplicate request IDs with same payload produce no duplicate effects
  • Typed error codes with retryable flag
  • State recovery: runtime_get_state equivalent after reconnect
Integration
  • For Claude agents: wrap --output-format stream-json events in ADF envelope
  • For Codex agents: gracefully degrade to unstructured mode
  • New agents: require envelope support as spawn prerequisite
Benefits
  • Foundation for cost tracking (#638), session persistence (#639), activity log (#641)
  • Eliminates SIGPIPE bug (structured framing detects incomplete messages)
  • Enables future Agent SDK migration

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading docs/runtime-taskd-rpc-spec.md and item 1.3 in cto-executive-system/plans/adf-architecture-improvements.md, then inspect the Claude stream-json and Codex agent communication paths. Done means the proposed envelope, idempotency, typed errors, state recovery, and graceful Codex fallback are implemented across the listed integrations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend-api-design, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.