diff --git a/) {} b/) {} new file mode 100644 index 0000000..2807556 --- /dev/null +++ b/) {} @@ -0,0 +1,47 @@ + +**Test Helper Complexity** +`src/__tests__/helpers/runtime-smoke.ts` creates sophisticated mock environments. The `TestLinearAuth` class extends `LinearAuth` and overrides methods, which creates tight coupling to the implementation. Consider using interface-based mocking or dependency injection instead of class inheritance for tests. + +## Reliability Analysis + +### Strengths + +**Request Policy Resilience** +The `executeWithRequestPolicy` function implements a robust retry mechanism with: +- Exponential backoff calculation (`retryDelayMs * attempt`) +- Attempt context passing for cancellation signals +- Proper cleanup of AbortController listeners +- Last error preservation for final throw + +**GraphQL Error Normalization** +`src/graphql/client.ts` provides sophisticated error handling: +- `normalizeErrors` converts unknown error shapes into structured `GraphQLErrorDetail` objects +- `isRetryable` checks both HTTP status codes and GraphQL error codes +- `createErrorResult` ensures consistent error shapes even for unexpected exceptions + +**Compensation Transactions** +The `createProjectWithIssues` method implements saga pattern compensation: +- If issue creation fails after project creation, it attempts to delete the orphaned project +- Returns detailed failure context including `compensationAttempted` and `compensationSucceeded` flags +- Preserves partial results (`project`, `issues`) for debugging + +**Safe SDK Operations** +The `SAFE_SDK_READ_OPERATIONS` Set in `src/graphql/client.ts` explicitly whitelists operations that can be safely retried, preventing dangerous retries of mutations that may have already partially executed server-side. + +### Areas for Improvement + +**AbortController Listener Cleanup** +In `executeWithTimeout`, the abort listener is added with `{ once: true }`, but if the promise resolves before abort, the listener is removed via `controller.signal.removeEventListener`. However, if `execute` throws synchronously (before the Promise microtask), the `onAbort` listener might not be cleaned up immediately. Consider using `AbortSignal.any` (Node 20+) or ensuring cleanup in a `finally` block. + +**Race Condition in Telemetry** +`RuntimeObservability` maintains counters (`totalRequests`, `successfulRequests`, etc.) as private instance variables. If multiple async operations complete simultaneously, these increments could race. While JavaScript is single-threaded, the async boundary between await points could theoretically allow interleaving. Consider using atomic operations or ensuring these updates happen synchronously. + +**GraphQL Client State Management** +The `LinearGraphQLClient` maintains a reference to `LinearClient` which may hold HTTP connection pools. If `LinearAuth` creates new `LinearClient` instances on token refresh (implied by `createScopedCopy`), old clients might not have their connections cleaned up. Ensure `LinearClient` instances are properly disposed or reused. + +**Test Port Reliability** +`getAvailablePort` in `src/__tests__/helpers/runtime-smoke.ts` binds to port 0 to find an available port, then closes the server. This creates a race condition where another process could bind to that port between `getAvailablePort` returning and the actual test server starting. Consider using port 0 binding directly on the test server with retry logic. + +**Error Message Construction** +The `buildErrorMessage` method in `src/graphql/client.ts` concatenates strings that could potentially be very large (GraphQL error messages). If error messages contain massive query dumps, this could cause memory pressure. Consider truncating error messages: + diff --git a/.claude/commands/opsx/apply.md b/.claude/commands/opsx/apply.md new file mode 100644 index 0000000..bf23721 --- /dev/null +++ b/.claude/commands/opsx/apply.md @@ -0,0 +1,152 @@ +--- +name: "OPSX: Apply" +description: Implement tasks from an OpenSpec change (Experimental) +category: Workflow +tags: [workflow, artifacts, experimental] +--- + +Implement tasks from an OpenSpec change. + +**Input**: Optionally specify a change name (e.g., `/opsx:apply add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes. + +**Steps** + +1. **Select the change** + + If a name is provided, use it. Otherwise: + - Infer from conversation context if the user mentioned a change + - Auto-select if only one active change exists + - If ambiguous, run `openspec list --json` to get available changes and use the **AskUserQuestion tool** to let the user select + + Always announce: "Using change: " and how to override (e.g., `/opsx:apply `). + +2. **Check status to understand the schema** + ```bash + openspec status --change "" --json + ``` + Parse the JSON to understand: + - `schemaName`: The workflow being used (e.g., "spec-driven") + - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others) + +3. **Get apply instructions** + + ```bash + openspec instructions apply --change "" --json + ``` + + This returns: + - Context file paths (varies by schema) + - Progress (total, complete, remaining) + - Task list with status + - Dynamic instruction based on current state + + **Handle states:** + - If `state: "blocked"` (missing artifacts): show message, suggest using `/opsx:continue` + - If `state: "all_done"`: congratulate, suggest archive + - Otherwise: proceed to implementation + +4. **Read context files** + + Read the files listed in `contextFiles` from the apply instructions output. + The files depend on the schema being used: + - **spec-driven**: proposal, specs, design, tasks + - Other schemas: follow the contextFiles from CLI output + +5. **Show current progress** + + Display: + - Schema being used + - Progress: "N/M tasks complete" + - Remaining tasks overview + - Dynamic instruction from CLI + +6. **Implement tasks (loop until done or blocked)** + + For each pending task: + - Show which task is being worked on + - Make the code changes required + - Keep changes minimal and focused + - Mark task complete in the tasks file: `- [ ]` → `- [x]` + - Continue to next task + + **Pause if:** + - Task is unclear → ask for clarification + - Implementation reveals a design issue → suggest updating artifacts + - Error or blocker encountered → report and wait for guidance + - User interrupts + +7. **On completion or pause, show status** + + Display: + - Tasks completed this session + - Overall progress: "N/M tasks complete" + - If all done: suggest archive + - If paused: explain why and wait for guidance + +**Output During Implementation** + +``` +## Implementing: (schema: ) + +Working on task 3/7: +[...implementation happening...] +✓ Task complete + +Working on task 4/7: +[...implementation happening...] +✓ Task complete +``` + +**Output On Completion** + +``` +## Implementation Complete + +**Change:** +**Schema:** +**Progress:** 7/7 tasks complete ✓ + +### Completed This Session +- [x] Task 1 +- [x] Task 2 +... + +All tasks complete! You can archive this change with `/opsx:archive`. +``` + +**Output On Pause (Issue Encountered)** + +``` +## Implementation Paused + +**Change:** +**Schema:** +**Progress:** 4/7 tasks complete + +### Issue Encountered + + +**Options:** +1.