Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 17:15 UTC
fix(cli): tolerate post-publish cleanup failures
jkomyno committed
Aug 1, 2026 at 20:10 UTC
5093ca5d6acdd7e65ecd7c241e4d9de16794ccfc
4 files changed
+93
-3
install.sh
+3
-2
@@ -245,7 +245,8 @@ publish_staged_entry() {
245
mv "$publish_target" "$publish_aside" ||
246
error "Failed to move existing install entry aside: $publish_target"
247
if mv "$publish_source" "$publish_target"; then
248
- rm -rf "$publish_aside" || error "Failed to remove old install entry: $publish_aside"
248
+ rm -rf "$publish_aside" ||
249
+ warn "Published install entry; previous contents retained at $publish_aside"
250
return 0
251
fi
252
@@ -297,7 +298,7 @@ install_bundle() {
298
299
publish_staged_entry "$stage/release-tag.txt"
300
publish_staged_entry "$stage/composio"
300
- rmdir "$stage" || error "Failed to remove staging directory: $stage"
301
+ rmdir "$stage" || warn "Published CLI; retained recovery staging directory at $stage"
302
stage=
303
}
304
test/install-sh-atomic-replace.test.sh
+33
@@ -118,6 +118,22 @@ chmod +x "$bundle/composio"
118
EOF
119
chmod +x "$fake_bin/unzip"
120
121
+cat >"$fake_bin/rm" <<'EOF'
122
+#!/usr/bin/env bash
123
+set -euo pipefail
124
+
125
+if [[ ${TEST_FAIL_ASIDE_CLEANUP:-} == 1 ]]; then
126
+ for arg in "$@"; do
127
+ case $arg in
128
+ */.composio-aside.local-tools-binaries) exit 23 ;;
129
+ esac
130
+ done
131
+fi
132
+
133
+exec /bin/rm "$@"
134
+EOF
135
+chmod +x "$fake_bin/rm"
136
+
137
interpreters=("$(command -v sh)")
138
if command -v dash >/dev/null 2>&1 && [[ $(command -v dash) != "${interpreters[0]}" ]]; then
139
interpreters+=("$(command -v dash)")
@@ -133,6 +149,7 @@ for interpreter in "${interpreters[@]}"; do
149
150
run_installer() {
151
local archive_mode=$1
152
+ local fail_aside_cleanup=${2:-0}
153
env \
154
PATH="$fake_bin:$PATH" \
155
HOME="$home" \
@@ -146,6 +163,7 @@ for interpreter in "${interpreters[@]}"; do
163
COMPOSIO_GITHUB_REPO=fake-repo \
164
TEST_TARGET="$target" \
165
TEST_ARCHIVE_MODE="$archive_mode" \
166
+ TEST_FAIL_ASIDE_CLEANUP="$fail_aside_cleanup" \
167
"$interpreter" "$repo_root/install.sh" "$version"
168
}
169
@@ -209,6 +227,21 @@ EOF
227
fail "$interpreter_name missing binary changed metadata"
228
assert_no_residue "$install_dir"
229
230
+ printf '%s\n' old-aside >"$install_dir/local-tools-binaries/recoverable.txt"
231
+ if ! aside_cleanup_output=$(run_installer complete 1 2>&1); then
232
+ fail "$interpreter_name aside cleanup failure aborted published install"
233
+ fi
234
+ grep -Fq 'Published install entry; previous contents retained at' <<<"$aside_cleanup_output" ||
235
+ fail "$interpreter_name aside cleanup warning"
236
+ grep -Fq 'Published CLI; retained recovery staging directory at' <<<"$aside_cleanup_output" ||
237
+ fail "$interpreter_name retained staging warning"
238
+ grep -Fq 'new-binary-marker' "$install_dir/composio" ||
239
+ fail "$interpreter_name aside cleanup did not publish executable"
240
+ retained_stage=$(find "$install_dir" -maxdepth 1 -type d -name '.composio-install.*' -print -quit)
241
+ [[ -n $retained_stage ]] || fail "$interpreter_name missing retained recovery staging directory"
242
+ [[ $(<"$retained_stage/.composio-aside.local-tools-binaries/recoverable.txt") == old-aside ]] ||
243
+ fail "$interpreter_name retained aside is not recoverable"
244
+
245
printf 'install.sh atomic replacement passed under %s\n' "$interpreter_name"
246
done
247
ts/packages/cli/src/utils/atomic-replace.ts
+10
-1
@@ -100,7 +100,16 @@ export const atomicReplaceDirectory = ({
100
);
101
yield* fs.rename(stagedPath, targetPath).pipe(
102
Effect.matchEffect({
103
- onSuccess: () => fs.remove(recoveryDirectory, { recursive: true }),
103
+ onSuccess: () =>
104
+ fs
105
+ .remove(recoveryDirectory, { recursive: true })
106
+ .pipe(
107
+ Effect.catchAll(cause =>
108
+ Effect.logWarning(
109
+ `Published replacement at ${targetPath}; previous contents remain at ${asidePath}: ${String(cause)}`
110
+ )
111
+ )
112
+ ),
113
onFailure: publishCause =>
114
fs.rename(asidePath, targetPath).pipe(
115
Effect.matchEffect({
ts/packages/cli/test/src/utils/atomic-replace.test.ts
+47
@@ -44,6 +44,34 @@ const failDirectoryPublish = (targetPath: string, failRestore = false) =>
44
)
45
).pipe(Layer.provide(BunFileSystem.layer));
46
47
+const failDirectoryCleanup = () =>
48
+ Layer.effect(
49
+ FileSystem.FileSystem,
50
+ Effect.map(
51
+ FileSystem.FileSystem,
52
+ fs =>
53
+ new Proxy(fs, {
54
+ get(target, property, receiver) {
55
+ if (property !== 'remove') {
56
+ return Reflect.get(target, property, receiver);
57
+ }
58
+
59
+ return (path: string, options?: FileSystem.RemoveOptions) =>
60
+ path.includes('.composio-atomic-recovery-')
61
+ ? Effect.fail(
62
+ new PlatformError.SystemError({
63
+ reason: 'Busy',
64
+ module: 'FileSystem',
65
+ method: 'remove',
66
+ pathOrDescriptor: path,
67
+ })
68
+ )
69
+ : target.remove(path, options);
70
+ },
71
+ })
72
+ )
73
+ ).pipe(Layer.provide(BunFileSystem.layer));
74
+
75
const makeDirectoryFixture = (withTarget = true) =>
76
Effect.gen(function* () {
77
const fs = yield* FileSystem.FileSystem;
@@ -173,6 +201,25 @@ describe('atomic replace', () => {
201
})
202
);
203
204
+ it.scoped('keeps the published directory when old-content cleanup fails', () =>
205
+ Effect.gen(function* () {
206
+ const { directory, fs, path, sourcePath, targetPath } = yield* makeDirectoryFixture();
207
+
208
+ yield* Effect.scoped(atomicReplaceDirectory({ sourcePath, targetPath })).pipe(
209
+ Effect.provide(failDirectoryCleanup())
210
+ );
211
+
212
+ const recoveryDirectory = (yield* fs.readDirectory(directory)).find(entry =>
213
+ entry.startsWith('.composio-atomic-recovery-')
214
+ );
215
+ expect(yield* fs.readFileString(path.join(targetPath, 'new.txt'))).toBe('new contents');
216
+ expect(recoveryDirectory).toBeDefined();
217
+ expect(
218
+ yield* fs.readFileString(path.join(directory, recoveryDirectory!, 'target', 'old.txt'))
219
+ ).toBe('old contents');
220
+ })
221
+ );
222
+
223
it.scoped('retains the previous directory when publishing and restoration fail', () =>
224
Effect.gen(function* () {
225
const { directory, fs, path, sourcePath, targetPath } = yield* makeDirectoryFixture();