Skip to content

Fix error handling and edge cases across auth, keys, and agent systems#207

Merged
alexkroman merged 1 commit into
mainfrom
claude/happy-davinci-tg7r46
Jun 17, 2026
Merged

Fix error handling and edge cases across auth, keys, and agent systems#207
alexkroman merged 1 commit into
mainfrom
claude/happy-davinci-tg7r46

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

This PR hardens error handling and fixes edge cases across multiple subsystems to prevent crashes and improve user experience.

Summary

Fixes malformed API responses, corrupt configuration handling, invalid base64 audio frames, and platform-specific upgrade detection. Also improves sentence splitting logic to preserve decimals and abbreviations, and corrects environment variable resolution for Voice Agents.

Key Changes

Auth & Keys

  • Split find_or_create_cli_key tests into a dedicated module to keep test_auth_flow.py under the 500-line gate
  • Add validation in keys create to reject API responses missing or with empty api_key field, surfacing clean APIError instead of KeyError
  • Improve find_or_create_cli_key to use the first project entry that actually has a project object (not just the first entry), handling accounts where the first membership lacks a project

Configuration & Startup

  • Guard the onboarding wizard offer against corrupt config.toml by checking deferred_config_error before attempting to resolve credentials, preventing traceback when config is unparseable
  • Add test coverage for bare assembly command with corrupt config

Agent Session

  • Wrap base64 decoding in on_reply_audio with try-except to gracefully drop corrupt audio frames instead of crashing the live conversation session

Text Processing

  • Refine split_sentences to only treat terminators (., !, ?) as sentence boundaries when they end the text or are followed by whitespace, preserving decimals ("$3.50") and abbreviations, and keeping stacked terminators ("...", "?!") intact

Environment & Deployment

  • Fix _active_env_vars to use the authoritative agents_host field from the environment instead of deriving it via string replacement of streaming_host
  • Fix dev_command to swap both python and python3 leading tokens for the venv interpreter
  • Fix detect_upgrade_command to only treat /usr/local/bin as Homebrew on macOS (darwin), not on Linux where it's a conventional source/manual build prefix
  • Add platform-specific test coverage for upgrade detection

Code Generation

  • Add null-check for LLM gateway message content to prevent crashes during code generation

Testing

  • Added 9 new tests covering malformed responses, corrupt config, corrupt audio frames, sentence splitting edge cases, and platform-specific upgrade detection
  • Moved 7 existing find_or_create_cli_key tests to new test_auth_flow_projects.py module

https://claude.ai/code/session_0119PsP7ZmuXMsoMke7DBBd2

Source fixes (each with a regression test):
- main: bare `assembly` with a corrupt config.toml printed a traceback —
  `_offer_or_help` now skips the key probe/wizard when the config error was
  deferred, so help renders cleanly.
- auth/flow: `find_or_create_cli_key` minted into projects[0]; now picks the
  first entry that actually carries a project, so login no longer fails when an
  earlier membership has a null project.
- code_gen/stream: generated `--llm` chain crashed on a null gateway message
  content; emit `... .content or ""`.
- app/init_exec: derive the Voice Agent host from the authoritative
  `Environment.agents_host` field instead of string-munging `streaming_host`.
- agent_cascade/text: `split_sentences` fragmented decimals/abbreviations
  ("$3.50"); a terminator now only ends a sentence at end-of-text or before
  whitespace.
- init/devserver: the venv-interpreter swap matched only `python`; also match
  `python3` so an edited Procfile still runs inside the project venv.
- commands/keys: `keys create` raised KeyError on a response missing api_key;
  validate and raise a clean APIError instead.
- ui/update_check: gate the `/usr/local/` Homebrew heuristic to macOS (Linux
  pip installs were told to run `brew upgrade`); use `removeprefix("v")`
  instead of `lstrip("v")` for the release tag.
- agent/session: guard `base64.b64decode` so one corrupt audio frame is dropped
  rather than tearing down the live session.

Moved the find_or_create_cli_key tests to tests/test_auth_flow_projects.py to
keep test_auth_flow.py under the 500-line gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0119PsP7ZmuXMsoMke7DBBd2
@alexkroman alexkroman added this pull request to the merge queue Jun 17, 2026
Merged via the queue into main with commit 2cd2dd7 Jun 17, 2026
19 checks passed
@alexkroman alexkroman deleted the claude/happy-davinci-tg7r46 branch June 17, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants