@devries-cameron20 / composio-1 / commits / c18a6f4a4
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(cli): retry busy Windows executable renames during upgrade (#5434)

This PR: - retries a busy Windows executable rename up to 10 times at 200 ms intervals during self-upgrade - keeps permission failures immediate and preserves the existing replacement rollback - tests temporary locks, retry exhaustion, and non-retryable failures, including exact attempt timestamps through the final retry at two seconds - records the change in the CLI changelog ## Context The second self-upgrade in the Windows smoke test failed with `EBUSY` while moving `composio.exe` to `composio.exe.old`: https://github.com/ComposioHQ/composio/actions/runs/43943628392/job/133568262696?pr=5417. The updater already retries removing a locked backup; the executable rename had no retry. This applies the same two-second retry budget specifically to `Busy` rename failures. It mitigates locks that clear within that window; the original lock holder and duration remain unknown. Validation on `0ba5498c19823d33b06951f9e484c37b06a5d419`: - `pnpm --filter @composio/cli exec vitest run test/src/utils/atomic-replace.test.ts test/src/services/upgrade-binary.test.ts`: 31 passed - `pnpm typecheck`: 14/14 tasks passed - `pnpm --filter @composio/cli run lint:effect`: 0 errors, warnings, or messages - Oxlint and Prettier checks on the changed files passed - Sensitivity checks: temporarily changing the retry interval to zero or 30 seconds makes the updated timing test fail; the production interval was restored before committing - Native Windows installation and runtime passed: https://github.com/ComposioHQ/composio/actions/runs/44061974883/job/133966653794 The native smoke test covers installation, repeated self-upgrades, locked-backup preservation, companion repair, agent setup, and credential storage. A passing run does not establish that it encountered and recovered from the original intermittent rename lock.

Alberto Schiabel committed Nov 18, 2026 at 20:53 UTC c18a6f4a46645f31948e1e2f51795d4eb372be03
3 files changed +105 -13
ts/packages/cli/CHANGELOG.md
+2
@@ -4,6 +4,8 @@
4
5 ### Patch Changes
6
7 +- `composio upgrade` on Windows now retries a busy executable rename for up to two seconds, allowing a brief file lock after a previous upgrade to clear before replacing the binary.
8 +
9 - Update @composio/client to 2.1.33 to include the latest API changes.
10
11 - A failed request that is safe to send again now exits 75 (`EX_TEMPFAIL`) instead of 1 and says so on stderr: one the API refused with a 429, or a read that timed out, lost its connection, or got a 408 or 5xx. Scripts and agents can retry on 75 without guessing. A failed `composio execute` adds `"retry": "safe"`, or `"retry": "check-first"` when the tool may have run before the request failed, to its `{ "successful": false }` result, and the `composio-cli` skill tells agents what both mean. Every other failed request still exits 1.
ts/packages/cli/src/utils/atomic-replace.ts
+16 -12
@@ -1,4 +1,4 @@
1 -import { Data, Effect, FileSystem, Path, Scope } from 'effect';
1 +import { Data, Effect, FileSystem, Path, Predicate, Schedule, Scope } from 'effect';
2
3 export class AtomicReplaceError extends Data.TaggedError('utils/AtomicReplaceError')<{
4 readonly targetPath: string;
@@ -46,19 +46,23 @@ export const atomicReplaceFile = ({
46 // until the next upgrade, when the process using it has exited.
47 yield* fs.remove(backupPath, { force: true });
48 yield* Effect.uninterruptible(
49 - fs
50 - .rename(targetPath, backupPath)
51 - .pipe(
52 - Effect.andThen(
53 - fs
54 - .rename(stagedPath, targetPath)
55 - .pipe(
56 - Effect.catch(cause =>
57 - fs.rename(backupPath, targetPath).pipe(Effect.andThen(Effect.fail(cause)))
58 - )
49 + fs.rename(targetPath, backupPath).pipe(
50 + // Windows can briefly lock the new executable after a preceding upgrade.
51 + Effect.retry({
52 + times: 10,
53 + schedule: Schedule.spaced('200 millis'),
54 + while: error => Predicate.isTagged(error.reason, 'Busy'),
55 + }),
56 + Effect.andThen(
57 + fs
58 + .rename(stagedPath, targetPath)
59 + .pipe(
60 + Effect.catch(cause =>
61 + fs.rename(backupPath, targetPath).pipe(Effect.andThen(Effect.fail(cause)))
62 )
60 - )
63 + )
64 )
65 + )
66 );
67 }).pipe(
68 Effect.mapError(
ts/packages/cli/test/src/utils/atomic-replace.test.ts
+87 -1
@@ -1,7 +1,8 @@
1 import * as BunFileSystem from '@effect/platform-bun/BunFileSystem';
2 import * as BunPath from '@effect/platform-bun/BunPath';
3 import { describe, expect, layer } from '@effect/vitest';
4 -import { Effect, FileSystem, Layer, Option, Path } from 'effect';
4 +import { Clock, Effect, Fiber, FileSystem, Layer, Option, Path, PlatformError } from 'effect';
5 +import { TestClock } from 'effect/testing';
6 import { AtomicReplaceError, atomicReplaceFile } from 'src/utils/atomic-replace';
7
8 const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer);
@@ -73,6 +74,91 @@ describe('atomic replace', () => {
74 })
75 );
76
77 + it.effect.each([
78 + {
79 + name: 'waits for a briefly busy executable before replacing it',
80 + reason: 'Busy',
81 + failures: 2,
82 + attempts: 3,
83 + },
84 + {
85 + name: 'fails after bounded retries when an executable stays busy',
86 + reason: 'Busy',
87 + failures: Infinity,
88 + attempts: 11,
89 + },
90 + {
91 + name: 'does not retry a permission failure when moving an executable',
92 + reason: 'PermissionDenied',
93 + failures: Infinity,
94 + attempts: 1,
95 + },
96 + ] as const)('$name', scenario =>
97 + Effect.gen(function* () {
98 + const fs = yield* FileSystem.FileSystem;
99 + const path = yield* Path.Path;
100 + const directory = yield* fs.makeTempDirectoryScoped();
101 + const sourcePath = path.join(directory, 'source');
102 + const targetPath = path.join(directory, 'composio.exe');
103 + const backupPath = `${targetPath}.old`;
104 + yield* fs.writeFileString(sourcePath, 'new binary');
105 + yield* fs.writeFileString(targetPath, 'old binary');
106 + const lockedError = PlatformError.systemError({
107 + _tag: scenario.reason,
108 + module: 'FileSystem',
109 + method: 'rename',
110 + pathOrDescriptor: targetPath,
111 + });
112 + const attemptTimes: number[] = [];
113 + const lockedFs = FileSystem.make({
114 + ...fs,
115 + rename: (from, to) =>
116 + Effect.gen(function* () {
117 + if (from === targetPath && to === backupPath) {
118 + attemptTimes.push(yield* Clock.currentTimeMillis);
119 + if (attemptTimes.length <= scenario.failures) {
120 + return yield* Effect.fail(lockedError);
121 + }
122 + }
123 + return yield* fs.rename(from, to);
124 + }),
125 + });
126 + const fiber = yield* Effect.scoped(
127 + atomicReplaceFile({ sourcePath, targetPath, backupPath })
128 + ).pipe(
129 + Effect.provideService(FileSystem.FileSystem, lockedFs),
130 + Effect.result,
131 + Effect.forkChild
132 + );
133 + yield* Effect.yieldNow.pipe(
134 + Effect.andThen(TestClock.adjust('3 seconds')),
135 + Effect.repeat({ times: 100, while: () => fiber.pollUnsafe() === undefined })
136 + );
137 + const result = yield* Fiber.join(fiber);
138 +
139 + expect(attemptTimes).toHaveLength(scenario.attempts);
140 + const firstAttempt = attemptTimes[0];
141 + expect(attemptTimes.map(time => time - firstAttempt)).toEqual(
142 + Array.from({ length: scenario.attempts }, (_, index) => index * 200)
143 + );
144 + if (scenario.failures === 2) {
145 + expect(yield* fs.readFileString(targetPath)).toBe('new binary');
146 + expect(yield* fs.readFileString(backupPath)).toBe('old binary');
147 + } else {
148 + const error = yield* Effect.flip(Effect.fromResult(result));
149 + expect(error).toBeInstanceOf(AtomicReplaceError);
150 + expect(error.cause).toBe(lockedError);
151 + expect(yield* fs.readFileString(targetPath)).toBe('old binary');
152 + expect(yield* fs.exists(backupPath)).toBe(false);
153 + }
154 + expect((yield* fs.readDirectory(directory)).sort()).toEqual(
155 + scenario.failures === 2
156 + ? ['composio.exe', 'composio.exe.old', 'source']
157 + : ['composio.exe', 'source']
158 + );
159 + })
160 + );
161 +
162 it.effect('restores the old executable when placing its staged replacement fails', () =>
163 Effect.gen(function* () {
164 const fs = yield* FileSystem.FileSystem;