Fix Agent Issue Creation - Adapter Failure (Issue #4)#190
Open
om952 wants to merge 7 commits into
Open
Conversation
- Added section 9: Error Handling Standards - Rules: try/catch wrapper, logError call, exact error response shape, HTTP status codes (500/400/404), logError location - Renumbered subsequent sections (10-13)
## Problem Agent creation fails with adapter errors when agents try to create issues. CTO agent specifically gets: adapter_failed, tool_call_id errors, max iterations reached. ## Root Causes 1. Missing Permissions - Only CEO had canCreateAgents permission 2. Process Adapter Missing JWT - No supportsLocalAgentJwt flag 3. Missing API Keys - Agents created without API keys 4. Missing tool_call_id - ACPX adapter events lacked toolCallId ## Fixes - Extended defaultPermissionsForRole() to include leadership roles (CEO, CTO, CFO, COO, VP, Director) - Added applyDefaultAgentCreateGrant() to auto-grant agents:create permission in DB - Added auto-generation of API keys on agent creation - Added supportsLocalAgentJwt: true to process adapter with PAPERCLIP_API_KEY injection - Added toolCallId validation and fallback ID generation in ACPX adapter ## Tests - 75 tests passing across modified areas - New e2e tests: agent-issue-creation-e2e.test.ts (4 tests) - New full e2e tests: agent-issue-creation-full-e2e.test.ts (4 tests with real DB) Closes OpenScanAI#4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Agent creation fails with adapter errors when agents try to create issues. The CTO agent specifically gets:
adapter_failederrorstool_call_id is not founderrorsRoot Causes Identified
Missing Permissions: Only CEO had
canCreateAgentspermission. CTO and other leadership roles couldn't create agents.Process Adapter Missing JWT Support: The
processadapter lackedsupportsLocalAgentJwtflag, so agents using it couldn't authenticate.Missing API Keys: Agents were created without API keys in
agent_api_keystable, causing auth failures.Missing tool_call_id: ACPX adapter events sometimes lacked
toolCallId, causing API errors.Fixes Implemented
1. Extended Permissions (
server/src/services/agent-permissions.ts)2. Auto-Grant DB Permissions (
server/src/routes/agents.ts)Added
applyDefaultAgentCreateGrant()that callsaccess.setPrincipalPermission(companyId, "agent", agentId, "agents:create", true, ...)on creation.3. Auto-Generate API Keys (
server/src/routes/agents.ts)Added
svc.createApiKey(agent.id, "auto-generated")in both creation paths.4. Process Adapter JWT (
server/src/adapters/process/)index.ts: AddedsupportsLocalAgentJwt: trueexecute.ts: ExtractsauthTokenfrom context, injectsPAPERCLIP_API_KEYinto env5. tool_call_id Fallback (
packages/adapters/acpx-local/)execute.ts: ValidatestoolCallId, generates fallback if missingparse-stdout.ts: Robust fallback ID generationformat-event.ts: Same fallback logicTest Coverage
Unit + Integration Tests (71 tests)
server/src/__tests__/agent-issue-creation-e2e.test.ts(4 tests)canCreateAgentspermission for leadership rolessupportsLocalAgentJwtenabledFull E2E Tests with Real DB (4 tests)
server/src/__tests__/agent-issue-creation-full-e2e.test.ts(4 tests)Test Results
75 tests passing across all modified areas. No regressions.
Files Changed
server/src/services/agent-permissions.tsserver/src/routes/agents.tsserver/src/adapters/process/index.tsserver/src/adapters/process/execute.tspackages/adapters/acpx-local/src/server/execute.tspackages/adapters/acpx-local/src/ui/parse-stdout.tspackages/adapters/acpx-local/src/cli/format-event.tsserver/src/__tests__/agent-permissions-routes.test.tsserver/src/__tests__/agent-adapter-validation-routes.test.tsserver/src/__tests__/agent-issue-creation-e2e.test.ts(new)server/src/__tests__/agent-issue-creation-full-e2e.test.ts(new)Status: ✅ COMPLETE
All 5 phases implemented and verified with 75 passing tests.
Fixes #4