Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix C051

Julius Marmingeb4c74723d1a3
diff --git a/.plans/16c-pr89-remediation-checklist.md b/.plans/16c-pr89-remediation-checklist.md
index 70203677e..c77b59dda 100644
--- a/.plans/16c-pr89-remediation-checklist.md
+++ b/.plans/16c-pr89-remediation-checklist.md
@@ -378,8 +378,8 @@ Counts: active `51` (`valid=33`, `partially-valid=18`), closed-invalid `6`
- Threads: PRRT_kwDORLtfbc5wiLhY
- Audit note: ProviderSessionDirectory upsert remains read-merge-write without concurrency control.
-- [ ] `C051` Using `??` for `providerThreadId` and `adapterKey` makes it impossible to clear these fields by passing `null`, since `null ?? existing` evaluates to `existing`. Consider using explicit `undefined` checks (like `resumeCursor` does) if clearing should be supported. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
- - Status: `TODO`
+- [x] `C051` Using `??` for `providerThreadId` and `adapterKey` makes it impossible to clear these fields by passing `null`, since `null ?? existing` evaluates to `existing`. Consider using explicit `undefined` checks (like `resumeCursor` does) if clearing should be supported. <details> <summary>🚀 Reply "<strong>fix it for me</strong>" or copy this <strong>AI Prompt</strong> for your agent:</summary>
+ - Status: `DONE`
- Verdict: `partially-valid`
- Severity: `Low`
- Area: `Other`
diff --git a/apps/server/src/provider/Layers/ProviderSessionDirectory.test.ts b/apps/server/src/provider/Layers/ProviderSessionDirectory.test.ts
index 90fa94032..a892c6f0f 100644
--- a/apps/server/src/provider/Layers/ProviderSessionDirectory.test.ts
+++ b/apps/server/src/provider/Layers/ProviderSessionDirectory.test.ts
@@ -154,6 +154,39 @@ it.layer(makeDirectoryLayer(SqlitePersistenceMemory))("ProviderSessionDirectoryL
}
}));
+ it("clears providerThreadId when explicitly set to null", () =>
+ Effect.gen(function* () {
+ const directory = yield* ProviderSessionDirectory;
+ const runtimeRepository = yield* ProviderSessionRuntimeRepository;
+
+ const sessionId = ProviderSessionId.makeUnsafe("sess-clear-provider-thread-id");
+ const threadId = ThreadId.makeUnsafe("thread-clear-provider-thread-id");
+ const providerThreadId = ProviderThreadId.makeUnsafe("provider-thread-to-clear");
+
+ yield* directory.upsert({
+ sessionId,
+ provider: "codex",
+ threadId,
+ adapterKey: "custom-adapter",
+ providerThreadId,
+ });
+
+ yield* directory.upsert({
+ sessionId,
+ provider: "codex",
+ providerThreadId: null,
+ });
+
+ const runtime = yield* runtimeRepository.getBySessionId({
+ providerSessionId: sessionId,
+ });
+ assert.equal(Option.isSome(runtime), true);
+ if (Option.isSome(runtime)) {
+ assert.equal(runtime.value.providerThreadId, null);
+ assert.equal(runtime.value.adapterKey, "custom-adapter");
+ }
+ }));
+
it("rehydrates persisted mappings across layer restart", () =>
Effect.gen(function* () {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-provider-directory-"));
diff --git a/apps/server/src/provider/Layers/ProviderSessionDirectory.ts b/apps/server/src/provider/Layers/ProviderSessionDirectory.ts
index 700f8b509..1b096e91e 100644
--- a/apps/server/src/provider/Layers/ProviderSessionDirectory.ts
+++ b/apps/server/src/provider/Layers/ProviderSessionDirectory.ts
@@ -108,7 +108,10 @@ const makeProviderSessionDirectory = Effect.gen(function* () {
threadId: resolvedThreadId,
providerName: binding.provider,
adapterKey: binding.adapterKey ?? existingRuntime?.adapterKey ?? binding.provider,
- providerThreadId: binding.providerThreadId ?? existingRuntime?.providerThreadId ?? null,
+ providerThreadId:
+ binding.providerThreadId !== undefined
+ ? binding.providerThreadId
+ : (existingRuntime?.providerThreadId ?? null),
status: binding.status ?? existingRuntime?.status ?? "running",
lastSeenAt: now,
resumeCursor: