Skip to content

Audit: Type safety violations and logic bugs #644

@Spongeacer

Description

@Spongeacer

Summary

Automated audit found type-safety violations and logic bugs across packages/app/src/ and packages/opencode/src/.

as any / as unknown casts hiding real type mismatches

File Line Issue
packages/opencode/src/tool/apply_patch.ts 35 (error as any).reason?._tag === "NotFound" — casts unknown error to any to access deeply-nested property without narrowing
packages/opencode/src/tool/registry.ts 173 def.execute(args as any, pluginCtx) — tool arguments cast to any before passing to plugin-defined execute
packages/opencode/src/tool/bash.ts 472 (process as any).resourcesPath — accesses Node/Electron-specific property not in NodeJS Process type
packages/opencode/src/session/session.ts 700–701 existing as unknown as Record<string, unknown> — casts typed message parts to plain records
packages/opencode/src/provider/transform.ts 191 msg.content = (msg.content as any[]).map(...) — redundant cast after Array.isArray check
packages/opencode/src/provider/provider.ts 1357 bridge.promise(...) as any — hides real return type of Effect pipeline
packages/opencode/src/lsp/client.ts 48–49 input.server.process.stdout as any — LSP stream types forced to any
packages/opencode/src/server/instance/experimental.ts 261 (t.parameters as any)?._def — checks Zod internal _def via any
packages/opencode/src/mcp/index.ts 524 (client.transport as any)?.pid — accesses implementation-detail property
packages/opencode/src/lsp/server.ts 671 (await releaseResponse.json()) as any — GitHub release JSON cast to any without schema parsing
packages/app/src/components/prompt-input/workspace-chip.tsx 53 { ... } as any — casts button props to any
packages/app/src/pages/session/file-tabs.tsx 451 onScroll={scrollSync.handleScroll as any} — event handler cast to any
packages/app/src/utils/server-health.ts 28 (AbortSignal as unknown as { timeout?: ... }).timeout — feature-detects via cast

@ts-ignore / @ts-expect-error and what they hide

File Line Issue
packages/opencode/src/session/session.ts 431–434 Hides access to provider-specific metadata keys not in official Usage type
packages/opencode/src/session/llm.ts 409 Hides mutation of AI SDK args.params.prompt inside middleware
packages/opencode/src/session/prompt.ts 64 Missing global declaration for AI_SDK_LOG_WARNINGS
packages/opencode/src/provider/provider.ts 1147, 1153, 1568 mergeDeep type mismatches; Bun timeout: false for fetch
packages/opencode/src/lsp/server.ts 17 Global assignment to silence AI SDK warnings
packages/opencode/src/file/watcher.ts 2 Import of @parcel/watcher without types
packages/opencode/src/plugin/index.ts 159 Dynamic hook invocation with unknown signature
packages/app/src/components/prompt-input.tsx 584 JSX prop type mismatch for custom event handler

Boolean parameter order risks

File Line Function
packages/app/src/context/command.tsx 51 signature(key, ctrl, meta, shift, alt) — 5 consecutive booleans
packages/opencode/src/cli/cmd/github.ts 1127 pushToNewBranch(summary, branch, commit, isSchedule) — 2 trailing booleans
packages/opencode/src/tool/bash.ts 189, 203 dynamic(text, ps) and pathArgs(list, ps) — ambiguous ps param
packages/opencode/src/id/id.ts 37, 58 generateID(prefix, descending, given?) and create(prefix, descending, timestamp?)

Off-by-one / edge case errors

File Line Issue
packages/opencode/src/config/parse.ts 22 beforeOffset[beforeOffset.length - 1].length + 1 without empty-array guard
packages/opencode/src/config/paths.ts 155 Same pattern
packages/opencode/src/tool/edit.ts 316–318 Drops trailing empty line from split("\n"); empty string becomes empty array
packages/opencode/src/patch/index.ts 325–327, 333–335 Trailing newline handling may add/remove lines incorrectly
packages/app/src/pages/session/terminal-panel.tsx 84 probe.focus(delays.length + 1) — potential out-of-bounds
packages/app/src/context/local.tsx 325, 394 Empty-array wrap sets next = -1

Mutable default parameters

File Line Issue
packages/app/src/components/session/session-context-metrics.ts 69, 109 config: Config = {}
packages/app/src/context/global-sync/child-store.ts 242, 252 options: ChildOptions = {}
packages/app/src/utils/scoped-cache.ts 13 options: ScopedCacheOptions<T> = {}
packages/opencode/src/tool/truncate.ts 99 options: Options = {}
packages/opencode/src/util/process.ts 65, 133, 298, 306 Multiple opts: Options = {}
packages/opencode/src/config/config.ts 499 path: string[] = []
packages/opencode/src/provider/pawwork-providers.ts 18 extra: Partial<Model> = {}
packages/opencode/src/cli/cmd/github.ts 937 files: PromptFiles = []

Loose equality (==)

File Line Issue
packages/app/src/components/terminal.tsx 445 key.key == "Enter" should be ===
packages/opencode/src/session/projectors.ts 23 obj == undefined — if obj is null, passes through to field1 in obj which throws

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions