Skip to content

backends: reverse-geocode config and the state-room exclusion list are copied across packages #2492

Open

Description

@schlessera

Context

Small pieces of configuration and protocol logic are copied across packages with no shared source:

  1. Reverse-geocode configuration. resolveLocationReverseGeocodeConfig is identical in packages/ui-backend-claude/src/location-tool.ts:18-26 and packages/ui-backend-pi/src/bridge-tools.ts:74-82. The env descriptors behind it are also duplicated, including the literal defaults: BRAIN_UI_REVERSE_GEOCODE, the three NOMINATIM_* variables, "https://nominatim.openstreetmap.org" and "brain-kit-ui/1.0" (packages/ui-backend-claude/src/config/env.ts:128, :172; packages/ui-backend-pi/src/config/env.ts:117, :139). If one default changes, the two backends geocode differently.
  2. State-room exclusion list. The rule "attach stateRoom to a result unless failure.errorClass is worker_state_busy, session_too_large or worker_state_exceeded" is the same inline string array in three packages: packages/ui-backend-claude/src/turn-runner.ts:217, packages/ui-backend-pi/src/turn-runner.ts:81 and packages/ui-react/src/hooks/websocket-handlers/chat.ts:383. The protocol already exports the class names as FIRST_PARTY_FAILURE_CLASSES (packages/ui-sdk/src/protocol.ts:1201).
git grep -n '"worker_state_busy", "session_too_large", "worker_state_exceeded"' -- packages ':!**/tests/**'
git grep -n 'function resolveLocationReverseGeocodeConfig' -- packages

Scope

  • Export stateRoomEligible(failure), or an equivalent constant set built from FIRST_PARTY_FAILURE_CLASSES, from @schlessera/brain-ui-sdk/protocol. Use it at the three sites.
  • Export the reverse-geocode env descriptors and resolveReverseGeocodeConfig(env) from @schlessera/brain-ui-sdk/server, which already owns ReverseGeocodeConfig. Each backend's env chokepoint spreads the descriptors and passes its own process.env read, so the "only file that reads process.env" rule still holds. Delete both resolveLocationReverseGeocodeConfig copies.

Out of scope

Acceptance criteria

  • The first grep above returns no src/ hits; the three sites use the shared helper.
  • git grep -n 'brain-kit-ui/1.0' -- packages/ui-backend-claude/src packages/ui-backend-pi/src returns nothing.
  • A ui-sdk unit test covers the state-room rule for each first-party failure class, and one covers resolveReverseGeocodeConfig defaults and overrides.
  • Both backends' location-tool tests and the ui-react state-room tests pass unchanged.

Verification

bun run test packages/ui-sdk packages/ui-backend-claude packages/ui-backend-pi packages/ui-react
bun run api-report
bun run env-docs
bun run typecheck

Contract impact

Additive @experimental exports on @schlessera/brain-ui-sdk/protocol and /server: CONTRACT: commit, with the API report and contract updated. Env variable names and defaults are unchanged.

Found by a repository review on 2026-10-22.

Activity

  1. added
    type: refactorStructure changes; behaviour does not. No changeset-visible effect.
    area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.
    area: ui-reactReact chat/files/voice components, stores, WebSocket transport.
    area: backendsAgentBackend implementations and the seam they share.
    priority: p3Someday. Needs a driving use case before it starts.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: backendsAgentBackend implementations and the seam they share.area: ui-reactReact chat/files/voice components, stores, WebSocket transport.area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.priority: p3Someday. Needs a driving use case before it starts.type: refactorStructure changes; behaviour does not. No changeset-visible effect.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions