agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

Extract shared isProcessRunning + normalizePermissionMode into @composio/ao-core

Open OrcInc opened this issue 8 months ago • 2 comments

Problem

All 4 agent plugins (agent-codex, agent-claude-code, agent-opencode, agent-aider) independently implement nearly identical tmux pane TTY lookup + ps parsing + PID signal-check logic (~150 LOC each, ~600 total wasted lines). The only difference is the process name regex.

Performance bug: agent-claude-code has ps output caching but the other 3 do not, meaning they spawn N ps processes when checking N concurrent sessions.

Additionally, normalizePermissionMode() is copy-pasted identically in 3 of the 4 plugins.

Proposed Solution

1. Shared isAgentProcessRunning in @composio/ao-core

// @composio/ao-core/src/process-detection.ts
export async function isAgentProcessRunning(
  handle: RuntimeHandle,
  processName: string,
  options?: { psCacheTtlMs?: number }
): Promise<boolean>

Each agent plugin reduces to:

async isProcessRunning(handle: RuntimeHandle): Promise<boolean> {
  return isAgentProcessRunning(handle, "codex");
}

Move the ps cache from agent-claude-code into the shared implementation so all agents benefit.

2. Shared normalizePermissionMode in @composio/ao-core

export function normalizePermissionMode(mode: string | undefined): PermissionMode | undefined;

Files to modify

  • New: packages/core/src/process-detection.ts
  • Update: packages/core/src/index.ts (re-export)
  • Simplify: packages/plugins/agent-codex/src/index.ts
  • Simplify: packages/plugins/agent-claude-code/src/index.ts
  • Simplify: packages/plugins/agent-opencode/src/index.ts
  • Simplify: packages/plugins/agent-aider/src/index.ts

Impact

  • ~600 lines of duplication removed
  • Performance improvement: all agents get ps caching (currently only claude-code has it)
  • Every future agent plugin gets process detection for free
  • Single source of truth for permission mode normalization

Source: code quality audit (Split 4 — Agent & Runtime Plugins)

OrcInc avatar Mar 29 '26 06:03 OrcInc

While you're consolidating normalizePermissionMode into @composio/ao-core, worth thinking about whether the fallback resolution path gets unified at the same time. There's a related bug where, when agentConfig.permissions is missing entirely from a project's config, the spawn-time default produces inconsistent results across workers spawned by identical ao spawn invocations (we hit this — see the spawn-side variant I just commented on #1475).

The triplicated normalizePermissionMode is fine in isolation; the more interesting consolidation would be a single resolvePermissionMode(projectConfig, sessionOverride) helper that handles the entire resolution chain (override → project → plugin default → safe fallback) in one place, with deterministic behavior when any layer is missing. That would close both the dedup gap and the inheritance bug simultaneously.

Just a flag for the design, not a blocker for the existing scope.

Tonedeath avatar Apr 29 '26 10:04 Tonedeath

Closing this as part of the migration cleanup for the ground-up rewrite of Agent Orchestrator.

This item was opened more than a month before the migration batch and the codebase has been replaced, so this thread no longer maps cleanly onto the current source tree.

If something here still needs tracking, please reopen this item or open a fresh one against the new tree. Thank you for contributing.

harshitsinghbhandari avatar Jun 24 '26 14:06 harshitsinghbhandari