The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(onepassword): a failed batch read no longer outlasts the 45-second bound (#35937)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 14, 2026 at 20:52 UTC
3cd8b0537101d2d2bfe23f378b73984a816a9b5f
2 files changed
+54
-19
packages/secret-provider-onepassword/src/server/driver.test.ts
+28
-1
@@ -2,9 +2,12 @@
2
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
4
import { assert, describe, it } from "@effect/vitest";
5
+import * as Clock from "effect/Clock";
6
import * as Deferred from "effect/Deferred";
7
+import type * as Duration from "effect/Duration";
8
import * as Effect from "effect/Effect";
9
import * as Fiber from "effect/Fiber";
10
+import * as FileSystem from "effect/FileSystem";
11
import * as Layer from "effect/Layer";
12
import * as Sink from "effect/Sink";
13
import * as Stream from "effect/Stream";
@@ -23,6 +26,7 @@ type OpResult = {
26
readonly stderr?: string;
27
readonly code?: number;
28
readonly hang?: boolean;
29
+ readonly delay?: Duration.Input;
30
};
31
32
function fakeOp(answer: (args: ReadonlyArray<string>) => OpResult) {
@@ -41,7 +45,9 @@ function fakeOp(answer: (args: ReadonlyArray<string>) => OpResult) {
45
pid: ChildProcessSpawner.ProcessId(1),
46
exitCode: result.hang
47
? Effect.never
44
- : Effect.succeed(ChildProcessSpawner.ExitCode(result.code ?? 0)),
48
+ : Effect.sleep(result.delay ?? 0).pipe(
49
+ Effect.as(ChildProcessSpawner.ExitCode(result.code ?? 0)),
50
+ ),
51
isRunning: Effect.succeed(false),
52
kill: () => Effect.void,
53
unref: Effect.succeed(Effect.void),
@@ -152,4 +158,25 @@ describe("1Password driver", () => {
158
assert.strictEqual(op.invocations.length, 1);
159
}).pipe(Effect.provide(op.layer));
160
});
161
+
162
+ it.effect("gives up within the read timeout when a slow batch fails", () => {
163
+ const op = fakeOp((args) =>
164
+ args.includes("inject")
165
+ ? { code: 1, delay: "40 seconds" }
166
+ : { stdout: "sk-a", delay: "40 seconds" },
167
+ );
168
+ // Keeps the temp template off real disk I/O so the virtual clock alone drives the read.
169
+ const templateFile = FileSystem.layerNoop({
170
+ makeTempFileScoped: () => Effect.succeed("/template"),
171
+ writeFileString: () => Effect.void,
172
+ });
173
+ return Effect.gen(function* () {
174
+ const reading = yield* driver
175
+ .read({ account }, ["op://Private/OpenAI/credential", "op://Private/Anthropic/key"])
176
+ .pipe(Effect.andThen(Clock.currentTimeMillis), Effect.forkChild);
177
+ yield* TestClock.adjust("5 minutes");
178
+
179
+ assert.isAtMost(yield* Fiber.join(reading), 45_000);
180
+ }).pipe(Effect.provide(Layer.merge(op.layer, templateFile)));
181
+ });
182
});
packages/secret-provider-onepassword/src/server/driver.ts
+26
-18
@@ -76,21 +76,14 @@ const readTogether = Effect.fn("OnePasswordDriver.readTogether")(function* (
76
return values.map(nonEmpty);
77
}, Effect.scoped);
78
79
-/** `None` when 1Password did not answer in time; a failed run reads as `Some(undefined)`. */
80
-const bounded = <A, E extends { readonly _tag: string }, R>(
79
+const recover = <A, E extends { readonly _tag: string }, R>(
80
stage: "read" | "inject",
81
effect: Effect.Effect<A | undefined, E, R>,
82
) =>
83
effect.pipe(
85
- Effect.timeoutOption(READ_TIMEOUT),
86
- Effect.tap((outcome) =>
87
- Option.isNone(outcome)
88
- ? Effect.logWarning("1Password did not answer in time", { stage })
89
- : Effect.void,
90
- ),
84
Effect.catch((error) =>
85
Effect.logWarning("Could not run 1Password", { stage, error: error._tag }).pipe(
93
- Effect.as(Option.some(undefined)),
86
+ Effect.as(undefined),
87
),
88
),
89
);
@@ -99,14 +92,29 @@ export const driver = defineSecretProviderDriver({
92
kind: definition.kind,
93
definition,
94
read: Effect.fn("OnePasswordDriver.read")(function* ({ account }, references) {
102
- if (references.length > 1) {
103
- const together = yield* bounded("inject", readTogether(account, references));
104
- // Reading one by one after a timeout would only wait that long again for each reference.
105
- if (Option.isNone(together)) return references.map(() => undefined);
106
- if (together.value !== undefined) return together.value;
107
- }
108
- return yield* Effect.forEach(references, (reference) =>
109
- bounded("read", readOne(account, reference)).pipe(Effect.map(Option.getOrUndefined)),
110
- );
95
+ // One deadline covers the batch and the fallback; a reference not read by then is unreadable.
96
+ const values: Array<string | undefined> = references.map(() => undefined);
97
+ const outcome = yield* Effect.gen(function* () {
98
+ if (references.length > 1) {
99
+ const together = yield* recover("inject", readTogether(account, references));
100
+ if (together !== undefined) return together;
101
+ }
102
+ yield* Effect.forEach(
103
+ references,
104
+ (reference, index) =>
105
+ recover("read", readOne(account, reference)).pipe(
106
+ Effect.map((value) => {
107
+ values[index] = value;
108
+ }),
109
+ ),
110
+ { discard: true },
111
+ );
112
+ return values;
113
+ }).pipe(Effect.timeoutOption(READ_TIMEOUT));
114
+ if (Option.isSome(outcome)) return outcome.value;
115
+ yield* Effect.logWarning("1Password did not answer in time", {
116
+ references: references.length,
117
+ });
118
+ return values;
119
}),
120
});