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 22, 10:45 UTC
fix(server): recover PR cache from corrupt scope revisions (#26873)
Markus committed
Oct 30, 2026 at 14:22 UTC
c61a51d6989ac15298f7b9f1a2b3fb0fc81635dc
2 files changed
+32
-3
apps/server/src/pullRequest/PullRequestReadCache.test.ts
+21
@@ -123,6 +123,27 @@ it.layer(NodeServices.layer)("PR filesystem cache", (it) => {
123
}),
124
);
125
126
+ it.effect.each(["", "{", '{"pr":{"revision":42}}'])(
127
+ "recovers from malformed scope revisions without reusing stale entries: %j",
128
+ (corrupt) =>
129
+ Effect.gen(function* () {
130
+ const fs = yield* FileSystem.FileSystem;
131
+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pr-cache-" });
132
+ const original = yield* cacheLayer(directory);
133
+ yield* original.get("summary", Effect.succeed("stale"), ["pr"]);
134
+ yield* fs.writeFileString(directory + "/revisions", corrupt);
135
+ const recovered = yield* cacheLayer(directory);
136
+ let reads = 0;
137
+ const lookup = Effect.sync(() => String(++reads));
138
+ assert.strictEqual(yield* recovered.get("summary", lookup, ["pr"]), "1");
139
+ assert.strictEqual(yield* recovered.get("summary", lookup, ["pr"]), "1");
140
+ yield* recovered.invalidate("pr");
141
+ assert.strictEqual(yield* recovered.get("summary", lookup, ["pr"]), "2");
142
+ const restarted = yield* cacheLayer(directory);
143
+ assert.strictEqual(yield* restarted.get("summary", lookup, ["pr"]), "2");
144
+ assert.strictEqual(reads, 2);
145
+ }),
146
+ );
147
it.effect("resumes caching after a failed scope read", () =>
148
Effect.gen(function* () {
149
const backing = yield* KeyValueStore.KeyValueStore;
apps/server/src/pullRequest/PullRequestReadCache.ts
+11
-3
@@ -88,9 +88,17 @@ export const make = Effect.gen(function* () {
88
crypto.digest("SHA-256", new TextEncoder().encode(key)).pipe(Effect.map(Hex.encode));
89
const revisions = yield* Cache.makeWith(
90
() =>
91
- backing
92
- .get("revisions")
93
- .pipe(Effect.flatMap((raw) => Schema.decodeEffect(revisionCodec)(raw ?? "{}"))),
91
+ backing.get("revisions").pipe(
92
+ Effect.flatMap((raw) => Schema.decodeEffect(revisionCodec)(raw ?? "{}")),
93
+ Effect.catchTags({
94
+ SchemaError: Effect.fn("PullRequestReadCache.recoverRevisions")(function* () {
95
+ // Without scope revisions, persisted PR entries cannot be trusted.
96
+ yield* backing.clear;
97
+ yield* Effect.logWarning("PR cache reset after invalid scope revisions");
98
+ return yield* Schema.decodeEffect(revisionCodec)("{}");
99
+ }),
100
+ }),
101
+ ),
102
{
103
capacity: 1,
104
timeToLive: (exit) => (Exit.isSuccess(exit) ? Duration.infinity : Duration.zero),