effect icon indicating copy to clipboard operation
effect copied to clipboard

Bug: Unused bindings and leftover manual `_tag` handling in `effect/ai`, `ai-anthropic`, `effect/http`, and `effect/eventlog`

Open devin-ai-integration[bot] opened this issue 1 month ago • 1 comments

Summary

None of these are runtime bugs; they are small code-quality issues. A strict lint pass (Oxlint with eslint/no-unused-vars and the anti-slop ruleset) flagged them, and I checked each one by hand on main @ 95a3ab78e924c3270d7b4e2e0b144e3341fa7029. I grouped them into one issue so they don't each need their own.

Reproduction

  1. Check out main at 95a3ab78e924c3270d7b4e2e0b144e3341fa7029 and run pnpm install.
  2. Run Oxlint with eslint/no-unused-vars set to error on the files below, e.g. pnpm exec oxlint -A all -D eslint/no-unused-vars -f unix packages/ai/anthropic/src/AnthropicLanguageModel.ts packages/effect/src/ai/AnthropicStructuredOutput.ts.
  3. Items 3–4 come from reading the code; they aren't lint errors under the repo's current config.

Actual behavior

  1. Unused destructured binding: packages/ai/anthropic/src/AnthropicLanguageModel.ts:1163
    const { type, ...params } = part.params
    
    type is declared but never read. The destructuring is there to strip type from params before they become the server_tool_use input, so the behavior is fine, but the unused binding is reported.
  2. Imports used only in JSDoc: packages/effect/src/ai/AnthropicStructuredOutput.ts:17-18
    import * as LanguageModel from "./LanguageModel.ts"
    import * as OpenAiStructuredOutput from "./OpenAiStructuredOutput.ts"
    
    The only references are in {@link ...} tags on lines 49–50. Because these are value imports, they become real module dependencies of AnthropicStructuredOutput and are reported as unused.
  3. Broad catchIf that checks _tag by hand: packages/effect/src/http/HttpStaticServer.ts:425
    (error): error is PlatformError => error.reason._tag === "NotFound",
    
    and packages/effect/src/eventlog/SqlEventJournal.ts:246
    (e) => e._tag !== "EventJournalError",
    
  4. Hidden type mismatch behind a double cast: packages/effect/src/ai/internal/mcpRuntime.ts:467
    !((admission.protocol as unknown as McpProtocol.ProtocolAdapter).handlerRpcs?.requests.has(
    

Expected behavior

  1. Drop the binding without changing behavior, e.g. const { type: _type, ...params } = part.params (if _-prefixed names are allowed) or another omit helper.
  2. Either use import type (if the docs tooling resolves {@link} through type-only imports) or link by module path, so the runtime module graph has no unused value imports.
  3. Possible cleanup: use the tagged-error combinators (Effect.catchTag/catchTags, or catchReason for PlatformError reasons) instead of comparing _tag strings, provided behavior stays the same. In particular, NotFound → route-not-found and everything else → internal server error.
  4. Possible cleanup: type admission.protocol as (or narrow it to) ProtocolAdapter so the as unknown as cast is no longer needed.

Environment

  • Version/commit: effect 4.0.3 / @effect/ai-anthropic 4.0.3, main @ 95a3ab78e924c3270d7b4e2e0b144e3341fa7029
  • OS: Ubuntu 22.04.5 LTS, Node v24.21.0
  • Relevant configuration: Oxlint 1.86.0 (the repo's version) with eslint/no-unused-vars, plus anti-slop @ c44ef22ca116d0ba62a3ff663a0bd13a3f3fa40b. The repo's default .oxlintrc.json reports none of these.

Evidence

Code references are linked above. All of them were checked against main @ 95a3ab78e924c3270d7b4e2e0b144e3341fa7029.

Oxlint output for items 1–2 (pnpm exec oxlint -A all -D eslint/no-unused-vars <files> -f unix):

packages/effect/src/ai/AnthropicStructuredOutput.ts:17:13: Identifier 'LanguageModel' is imported but never used. [Error/eslint(no-unused-vars)]
packages/effect/src/ai/AnthropicStructuredOutput.ts:18:13: Identifier 'OpenAiStructuredOutput' is imported but never used. [Error/eslint(no-unused-vars)]
packages/ai/anthropic/src/AnthropicLanguageModel.ts:1163:31: Variable 'type' is declared but never used. Unused variables should start with a '_'. [Error/eslint(no-unused-vars)]

Additional context

  • Confirmed: items 1 and 2 are unused bindings or imports. Item 3 compares _tag strings by hand. Item 4 uses an as unknown as cast.
  • Not claimed: none of these changes runtime behavior. Items 3 and 4 are refactoring suggestions, and I haven't checked whether the existing combinators can express item 3 exactly.
  • For context, the rest of the anti-slop output (about 55k diagnostics, mostly spacing, safety comments on type assertions, and _tag style) looked intentional or stylistic: the non-empty array casts in Socket, DatagramSocket, Channel, and Stream are guarded by length checks, and Reflect.* in the Proxy traps is correct. I'm not raising any of that.

Written by Devin

Correction after a duplicate search: I'm withdrawing the SqlEventJournal.ts:246 part of item 3. Closed PR #8314 (which followed #7843 / #7844) proposed removing this same catchIf(e => e._tag !== "EventJournalError", ...) wrapping in writeFromRemote, and it was closed with the note that these methods don't need generic errors. The wrapping is intentional.

Items 1, 2, 4, and the HttpStaticServer.ts:425 part of item 3 still stand. I found no existing issues or PRs that cover them.

gpu004 avatar Oct 11 '26 19:10 gpu004