Introduction
I don't doubt that vibe coding works — for some people. The inventor of Claude Code has said publicly that he hasn't written code by hand in a long time. There are clearly developers for whom AI has become a genuine force multiplier, maybe even a replacement for the keyboard altogether.
Over two days, I built a web application using Claude: a Python backend, serving as a WebSocket proxy server that sits between a browser and a real-time voice AI service and relaying audio in both directions; a simple frontend without JS library.
All code was written by Claude based on my requirements. I only made minor modifications to the shell script; I did not touch any of the actual web application code. This small project went across 5 separate Claude sessions — each conversation pushed to the token limit so I had to start a new session.
Below is a summary of all five sessions. Each section includes my own notes and Claude's session summary. What I took away from this small project: even with Claude 4.7, the so-called most capable model, getting it to independently generate fully working code from a few rounds of discussion is still not possible.
But before I get into the details, I would like to say something about my background: I have over 20 years of software engineering experience across Telecom, Enterprise, Mobile, and AI. I want to be clear — and this is not false modesty — my honest self-assessment is that I'm above average, but not a 10x developer: broad exposure, solid judgment, enough experience to know when something is wrong even if I can't always name it immediately. I think that profile describes most working senior engineers I know of.
When doing vibe coding, my advantages lay in: I would read every line Claude produced. I could catch wrong abstractions, push back on bad decisions, and recognize when the model was confidently pattern-matching instead of reasoning from my actual constraints. I held a clear design principle throughout: use defaults whenever possible; don't add configuration unless you can clearly justify the benefit. I knew what I wanted and could articulate it precisely.
Session 1: Kick-off — Architecture, Framework Choice, First Code
The project kick-off — and the longest of all five sessions.
My Notes
The conversation went as follows:
1. Handed Off Qwen Sample Code, Asked Claude to Analyze
- Discussed Python web frameworks: Django / Flask / FastAPI — specifically why most LLM services use FastAPI
- Analyzed streaming responses: does an LLM service use WebSocket or SSE?
- Further comparison: when you also need to host static pages, is aiohttp or FastAPI better?
- Provided Qwen-Omni-Realtime's Bailian page with Python sample code — Claude analyzed it and confirmed that Qwen-Omni-Realtime requires WebSocket
Note: In hindsight I'm not sure this warm-up was necessary. Maybe it was too much throat-clearing.
2. Stated the Core Requirement: WebSocket Proxy / Relay Architecture
First clear statement of requirements: Browser <--WSS--> Backend Server (holds API Key) <--WSS--> LLM Service — a WebSocket relay is needed because my API key cannot be exposed, and I need my WebSocket Proxy to implement some function-call feature my web app needs in the future.
Claude's reply indicated full understanding:
Completely clear — this is a very classic WebSocket proxy/relay architecture. You need a middleware layer to: protect the API Key (not expose to browser), control access (authentication), and optionally add value-added features (logging, rate limiting, billing).
Core implementation: bidirectional message forwarding
3. FastAPI vs aiohttp Comparison
- Claude initially recommended FastAPI. Also provided the first complete code including browser-side code, a simple sliding-window rate limiter on the server side, and an Nginx config file.
- I asked for a re-evaluation of the aiohttp approach. Claude gave a contradictory recommendation with faulty analysis: "For your scenario, I now recommend aiohttp — aiohttp (acting as both server and client) avoids mixing FastAPI + websockets two libraries."
- Claude then suggested: "If you need mixed services — REST API + WebSocket combined — then FastAPI is better."
- I pointed out the analysis error (the
wslibrary is independent). Claude corrected itself and concluded: "If you only need the WS relay, the standalonewslibrary works, but if you also need other HTTP endpoints (health check, config API, static files) you'll need FastAPI or aiohttp." - Final confirmation: all-in-one solution — static files + REST API + WebSocket + database — FastAPI handles all of it elegantly. Full code generated again.
Claude's self-congratulatory summary:
✅ User registration/login (JWT auth) ✅ WebSocket real-time conversation ✅ Voice selection ✅ Chat history saving and loading ✅ SQLite database ✅ Responsive frontend ✅ API Key protection
4. I Asked Claude to Confirm the Code Again
Claude updated the output, primarily adding a README and run.sh startup script.
5. Asked for an aiohttp Re-implementation
Claude compared both implementations. First time I worried about context length — Claude explicitly said it wasn't a problem.
6. Requested Several Specific Code Changes
create_task-based implementation for bridging two WebSocket connections- FastAPI route inspection via
APIRouterfor centralized route management - Replace
printwithloguru - Enable WAL (Write-Ahead Logging) for SQLite
- Move WebSocket handling into its own file
- CSS: use a framework, must be lightweight (basic config only), Flexbox support, responsive so it opens correctly on mobile
- Told Claude
python-multipartis not needed
Worth highlighting the SQLite WAL decision. My design principle from the start: use defaults whenever possible, don't add config unless you can clearly justify the benefit. WAL is arguably the only deliberate deviation from that principle in this whole project — because without WAL, SQLite's read/write serialization is a real limitation, and I was confident Claude would not have enabled it on its own.
After these discussions, Claude iterated to v1.1 and v1.2.
v1.2 (latest):
- ✅ WebSocket handling moved to
websocket_handler.py - ✅ Using Pico.css lightweight framework (10KB)
- ✅ Fully responsive design (mobile-friendly)
- ✅ Dark mode support
- ✅ Further code modularization
v1.1:
- ✅ Centralized routing via APIRouter
- ✅ loguru logging
- ✅ SQLite WAL mode
- ✅ Code layering: from
main.py(267 lines, everything mixed together) tomain.py(100 lines, startup only)
The CSS Discussion — a Theme That Recurred Throughout All 5 Sessions
Framework chosen: Pico.css
| Framework | Size | Responsive | No class names | Flexbox |
|---|---|---|---|---|
| Pico.css | 10KB ✅ | ✅ | ✅ | ✅ |
| Bootstrap | 150KB ❌ | ✅ | ❌ | ✅ |
| Tailwind | Complex config | ✅ | ❌ | ✅ |
| Bulma | 200KB ❌ | ✅ | ❌ | ✅ |
Claude's self-congratulatory sign-off: "All changes complete! Code is cleaner, UI is prettier, works perfectly on mobile! 🎉"
(It did not work perfectly on mobile. This became a recurring issue.)
7. Outlined Next Phase
- Move Python files under
/src - SQLite refactoring: drop SQLAlchemy, no
models.py, operatesqlite3directly,schema.sqlfor DB init (run via sqlite3 CLI, not Python), updaterun.sh - Config management:
.env+config.py - Claude implemented all SQLite changes and proposed a full v2.0 restructuring plan
- Claude then said: "Due to tool limitations, I cannot continue generating complete code" — prompting me to continue in a new session. I had also noticed visible repetition in responses, a sign the context was exhausted.
Claude's Session Summary
Project: Qwen-Omni-Realtime Proxy Service
Core function: FastAPI-based WebSocket proxy for secure access to Alibaba Cloud's Qwen-Omni-Realtime real-time voice dialogue model
Stack: FastAPI + WebSocket + SQLite + Loguru + Pico.css
Core Requirements
- Security: Hide API Key from the browser
- User system: Registration, login, JWT auth
- Real-time dialogue: Bidirectional WebSocket forwarding (browser ↔︎ backend ↔︎ LLM)
- Voice selection: 7 AI voices available
- Conversation history: SQLite storage with query support
- Responsive UI: Desktop and mobile support
Version History
v1.0 — Base version (single file)
- ✅ FastAPI + WebSocket basics
- ✅ User registration and login
- ✅ Real-time voice dialogue
- ❌ All code in one
main.py(267 lines)
v1.1 — Modular refactoring
- ✅ Centralized routing via
APIRouter(routes.py) - ✅ Switched to loguru
- ✅ SQLite WAL mode (3x performance improvement)
- ✅ Layered code:
handlers.py,routes.py,config.py - ✅
create_taskfor concurrent task management - ✅ Removed unnecessary
python-multipartdependency
v1.2 — Frontend optimization
- ✅ WebSocket handling moved to
websocket_handler.py - ✅ Pico.css (10KB)
- ✅ Responsive design
- ✅ Dark mode
v2.0 — Enterprise-grade refactoring (planned)
- 📁 Directory restructuring: all Python →
src/, tests →tests/, styles →static/css/ - ⚙️ Config management: loguru initialization in
config.py, python-dotenv (.env+.env.local), model parameter configurable - 🎨 Style separation: inline
<style>→static/css/custom.css - 🗄️ Database init: new
schema.sql(schema + WAL settings),run.shchecks for sqlite3 and runssqlite3 database.db < schema.sql,models.pyno longer creates tables
Technical Decisions
FastAPI vs aiohttp
| Feature | FastAPI | aiohttp |
|---|---|---|
| Code size | 267 lines | 379 lines |
| Dependencies | 6 | 4 |
| Auto-validation | ✅ | ❌ manual |
| API docs | ✅ auto | ❌ manual |
| Routing | decorators | explicit registration |
Final choice: FastAPI — cleaner code, auto-validation, auto-docs, and the developer already knows it.
WebSocket vs SSE
- Generic LLM API (OpenAI, text dialogue) → SSE (one-way streaming)
- Real-time multimodal voice (Qwen-Omni-Realtime) → WebSocket (bidirectional, interrupt control)
Core Architecture
Browser <--WSS--> Your Backend Server <--WSS--> LLM
(JWT) (holds API Key) (Qwen)
Bidirectional Forwarding
task1 = asyncio.create_task(forward_client_to_qwen())
task2 = asyncio.create_task(forward_qwen_to_client())
try:
await asyncio.gather(task1, task2, return_exceptions=True)
finally:
if not task1.done(): task1.cancel()
if not task2.done(): task2.cancel()
Session 2: The v2.0 Refactor and the First Run — No Sound
Continuing the v2.0 changes left unfinished from Session 1. Up until now I hadn't actually run any of Claude's code — my gut said it would have problems. This session involved actually running the code for the first time and discovering there was no sound.
My Notes
1. Resumed Work, Discovered a Problem
Discussion revealed a bug in Claude's "task continuation" capability: it had lost track of v1.1 and v1.2.
"I understand — v1.1 and v1.2 were done in the original session. When I searched, I only found fragments of the initial v1.0, so the restructuring lost those two versions' changes... I searched several rounds. I have to be honest: I cannot retrieve the specific code from v1.1 and v1.2. In this situation, continuing to guess the code will only drift further. Two options: A. Upload the v1.2 code archive and I'll restructure from there."
2. Uploaded All v1.2 Code
Continued discussing the agreed-upon changes from Session 1. Key focus: SQLite WAL — confirmed that several settings Claude had provided were blindly copied from other configs and were irrelevant to this project. Also discussed:
on_eventvslifespanrun.shinit script changes- Further simplification of
custom.css - Discovered that Claude's file tool output had issues — the tar archive should contain everything, no need to also output files individually
3. First Real Run — No Sound
After completing the so-called v2.0 refactoring (all Python code moved under /src), I ran it for the first time.
Went through multiple iterations of app.js trying to fix the sound. Eventually decided this needed a fresh session.
Claude's Session Summary
Starting point: v1.2 (already had APIRouter / loguru / WAL / Pico.css / websocket_handler.py split)
Completed refactoring (now v3, effectively v1.0):
Directory structure: All Python code moved to src/, tests/ placeholder added, database moved to data/
Config layering:
config.pydoes three things: load dotenv + initialize loguru + expose config values.env(committable): URL, model, voices, port defaults.env.local(not committed):DASHSCOPE_API_KEY,SECRET_KEY
main.py slimmed down:
- loguru config moved entirely to
config.py @app.on_eventreplaced with lifespan context manager (eliminates deprecation warning)- Startup checks whether DB tables exist; gives clear error if not
Database:
- New
schema.sqlmanages table creation and indexes models.pyno longer callscreate_all(), allindex=Trueremoved- WAL persistence placed in
schema.sql;synchronous=NORMALremains in event listener (clarified the two types of PRAGMA persistence)
Frontend:
- Inline
<style>inindex.htmlextracted tostatic/css/custom.css - All
style="display:none"replaced with.hiddenclass app.jsall.style.displaycalls replaced with.classList.add/remove('hidden')
run.sh / run.bat:
- Added
exec(Docker SIGTERM friendly) - Key check: either
.env.localor environment variable works (Docker compatible) - First run automatically executes
sqlite3 data/database.db < schema.sql, skips if already exists
Unresolved Issues (Carried to Next Session)
Critical: No sound
- Playback side: switched from
nextPlayTimetimestamp scheduling to Queue +onendeddrain (referencing a workingindex.html) - Recording side: switched from
MediaRecorder(webm/opus) toScriptProcessorNode(raw PCM 16kHz) - Sound issue not confirmed fixed — need DEBUG logs to confirm
response.audio.deltareaches the browser
Voice list outdated:
- Current
.envhas 7 voices (Alice/Bob/Bella/Luna/Max — possibly old names) - Reference
index.htmlhas 14 correct voices including dialects AVAILABLE_VOICESuses comma separation, which breaks names containing spaces like "Liora Mira" — should change separator to|
Session 3: Bug Fixes, and Removing What Claude Added Unasked
Started with the no-sound issue, progressively resolved other obvious problems.
My Notes
The plan was to fix the missing audio, especially the first-connection issue where the server logged errors but a browser refresh restored sound. After testing, it turned out sound was already fixed — probably from Session 2 — and I just hadn't refreshed the browser, making me think it was still broken. So we moved on to other issues.
Problems Resolved
- Ctrl+C wouldn't quit — entirely a bug in Claude-generated code
- Registration page error
- Too many code errors — I complained: "So many errors. I'm really disappointed in the code from these last few sessions"
- Discussion about frontend code organization
- Claude-generated CSS was genuinely ugly
- Backend code too bloated — e.g., the loguru setup
- Explicitly stated the design principle: "If a config item can be omitted, omit it. Prefer defaults. Don't change unless you can clearly justify the benefit."
- Removed SQLAlchemy — also something Claude had introduced without being asked
Claude's Session Summary
This session focused on v2.1 review, bug fixes, and refactoring.
Design Principle Established This Session
Use defaults whenever possible. Don't add configuration unless you can clearly justify the benefit. Keep libraries and frameworks in their out-of-the-box state.
All refactoring decisions this session were driven by this principle.
Bug Fixes
Backend:
WebSocket DB session leak — User-not-found caused early return without executing
db.close(). Fixed: switched toopen_db()with unifiedfinally: conn.close()Ctrl+C hangs, requires two presses —
task.cancel()only sent the signal without waiting;forward_qwen_to_clientwas blocked inasync forwaiting for Qwen messages. Fixed: addedawait taskafter cancel; added explicitqwen_ws.close()inforward_client_to_qwen'sfinally, so the other side exits naturally.Empty recording triggers Qwen 1007 error — If the user clicked record and immediately stopped, no audio was actually sent, but
commit+response.createwere still dispatched. Fixed: addedaudioChunksSentcounter; skip commit if zero.
Frontend:
Registration error:
Cannot read properties of null (reading 'click')—handleRegisterreferenced.tabclass, which didn't exist in the HTML.querySelectorreturned null. Registration itself succeeded; only the tab-switching JS crashed. Fixed: directly manipulatelogin-form/register-formhiddenclasses.Record button clickable during WS connection — After login, WebSocket connects asynchronously, but the button was immediately enabled. Fixed: disable button during connection, only enable on
ws.onopen.resetAudioPlaybackrace condition —response.createdforcedisPlaying=false, old drain was unaware, and new delta arriving would start a second concurrent drain, potentially reordering audio. Fixed: introducedplayGenerationcounter; old drain exits when it detects a generation mismatch.
Refactoring
Removed loguru custom config: loguru's default output (stderr, colors, timestamps) meets all needs. The original config.py was duplicating defaults for no reason. Deleted _setup_logger(), LOG_FORMAT, and all related config. Removed corresponding .env variables LOG_LEVEL, LOG_ROTATION, LOG_RETENTION.
Removed SQLAlchemy, replaced with stdlib sqlite3: The schema is simple; ORM added only complexity and dependencies.
- Deleted
models.py, addeddb.py get_db(): context manager for HTTP handlersopen_db(): for WebSocket use, manual lifecycle management- Removed
sqlalchemyfromrequirements.txt
Only two PRAGMA values retained, both with clear justification:
PRAGMA journal_mode=WAL; -- persistent, set once in schema.sql at DB creation
PRAGMA synchronous=NORMAL; -- per-connection, set in _get_conn()
Split run.sh into init.sh + run.sh: Initialization and startup responsibilities separated.
Frontend CSS rewrite: Original custom.css heavily referenced Pico.css v2 internal variable names (e.g., --pico-primary-background) that don't exist in that version — all styles silently fell back. Replaced with custom CSS variables, no dependency on Pico internals. Synchronized rewrite of index.html and app.js with all frontend bug fixes.
Session 4: Push-to-Talk and the CSS Framework Comparison
Started with fixing the ugly frontend UI. This session focused heavily on CSS.
My Notes
1. First Problem: The UI
- Provided a competitor app built by Minimax — much better-looking UI. Asked Claude to study it.
- First switched from Toggle recording mode to Push-to-Talk (PTT), including a waveform animation in CSS.
2. Then: CSS Was Still Ugly
- Even after implementing PTT, the UI looked bad. And my custom
custom.csshad grown long — hard to see what the CSS framework was even doing. - Asked Claude to redo it using Bootstrap. Validated the result.
- I manually trimmed my Pico.css-based
custom.css— Claude had said 293 lines was the minimum, but I got it down to 194. Then asked Claude to analyze how many lines a Bulma implementation would need. - Discussion of exactly which CSS must be hand-written: chat bubbles, floating panel, PTT + waveform; login background gradient, overall layout (sidebar + main area), login logo. Total: roughly 20 lines of CSS. Even removing all of those only gets from 151 to 131 lines. The true floor is around 130 lines — unless you swap the floating panel, bubbles, and PTT for ready-made components from a commercial library (e.g., one with voice UI built-in).
- Discussed responsive design across all three implementations. This requirement had been stated in Session 1, but Claude still failed to implement it here — all versions still used
100vhlayout. - Claude started showing signs of context exhaustion, dropping an entire round of discussion.
Note: despite all this, this session was much shorter than Session 1.
Claude's Session Summary
Background
FastAPI-based WebSocket proxy for Alibaba Cloud Qwen-Omni-Realtime. Frontend: static/index.html, static/app.js, static/css/custom.css.
I. Backend Key Decisions (Already Completed)
- Password hashing uses bare SHA-256 (no salt) — acceptable for internal networks, should be replaced with bcrypt/scrypt for public-facing deployment
ConnectionManagerusesuser_idas key; a user can only have one connection, but old connections are not actively closed- loguru's default log level is DEBUG;
LOG_LEVEL=infoinrun.shhas no effect on it- Fix: Two lines in
config.py:logger.remove() logger.add(sys.stderr, level=os.getenv("LOG_LEVEL", "INFO").upper())
- Fix: Two lines in
II. Interaction Improvement: Push-to-Talk (Completed)
Before: Toggle mode — click to start/stop recording
After: PTT mode — hold to speak, release to submit (WeChat voice-message style)
Frontend changes:
index.html: button changed to circular PTT button + waveform divapp.js: added AnalyserNode + waveform animation, bound mousedown/mouseup/touchstart/touchendcustom.css: PTT button styles + waveform bar styles
Key code:
btn.addEventListener('mousedown', e => { e.preventDefault(); startRecording(); });
btn.addEventListener('mouseup', () => stopRecording());
btn.addEventListener('mouseleave', () => { if (isRecording) stopRecording(); });
btn.addEventListener('touchstart', e => { e.preventDefault(); startRecording(); }, { passive: false });
btn.addEventListener('touchend', e => { e.preventDefault(); stopRecording(); });
btn.addEventListener('contextmenu', e => e.preventDefault()); // prevent long-press system menu
III. Floating Voice Panel (Completed)
Moved the recording controls from the bottom bar to a fixed floating panel in the lower-right corner (inspired by the competitor app):
position: fixed; bottom: 28px; right: 28px- Supports drag, minimize (collapses to circle), click to restore
- Contains waveform visualization + PTT button + status indicator
Removed the bottom control bar (clear/history buttons); chat area fills full height with padding-bottom: 200px to prevent content from being obscured by the panel.
IV. CSS Framework Comparison — Core Findings
| Version | Custom CSS lines |
|---|---|
| Bootstrap 5 | 72 lines |
| Bulma | 72 lines |
| Pico.css | 101 lines |
| Vanilla CSS | 97 lines |
Key conclusions:
- Bootstrap and Bulma tied for fewest lines — they cover cards, buttons, forms, utility classes (flex/gap/text-muted, etc.)
- Pico.css requires more lines than vanilla CSS — because Pico applies its own styles to button/input/select; you either work around them or override them, both requiring more code
- The true CSS floor is ~110–115 lines that no framework can replace: app layout, chat bubbles (left/right alignment, color, animation), floating panel (positioning, drag, minimize), PTT button + waveform, status dot animation
Framework still undecided at end of session.
V. Layout Refactoring: Pending
Current problem with 100vh fixed layout:
- Mobile address bar causes viewport height to jump
- Sidebar hidden on mobile — voice selector completely inaccessible
- Future additions (scene management, VAD config, user management, history) will overflow the sidebar; fixed height won't accommodate it
- Modal scroll handling is complex inside a fixed-height layout
Target approach (based on competitor Minimax implementation):
Scrollable page
├── header (top)
├── main-layout (CSS Grid)
│ ├── Left column 380px: voice, scene, VAD, connection status, user info
│ └── Right column 1fr: dialogue text, event log
└── floating-panel (position:fixed, always visible)
Mobile (<1024px): grid becomes single-column, left column stacks above right
Chat area uses fixed height (e.g., 400px) with internal scrolling — no dependency on viewport height.
Session 5: Vanilla CSS, a Responsive Grid, and the PTT Delay Fix
Continued the responsive design implementation and resolved PTT usability issues.
My Notes
- Confirmed: chose vanilla CSS (no framework)
- Switched to CSS Grid for responsive design
- Fixed PTT delay
- Fixed PTT-related display issues
Claude's Session Summary
I. Project Status at Session Start
Project was at v2.1 — backend refactoring complete (modular src/, sqlite3 replacing SQLAlchemy, loguru out-of-the-box, init/run scripts separated), frontend had basic login + voice conversation, but with the following outstanding issues:
- No responsive design; sidebar config disappears on mobile
- PTT delay of ~2 seconds before recognition begins; first words lost
- No entry points for scene management, VAD config, user management, or history
- Floating panel visible before login
II. CSS Framework Selection
Background: Current Pico.css implementation depended on non-existent v2 internal variable names (e.g., --pico-primary-background), causing silent fallbacks and inability to implement responsive design. Time to re-evaluate.
Four-way comparison:
| Version | custom.css lines | Notes |
|---|---|---|
| Bootstrap 5 | 72 | Framework takes over most, but HTML is cluttered with utility classes |
| Bulma | 72 | On par with Bootstrap |
| Pico.css | 101 | Takes over inputs/typography, rest requires manual additions |
| Vanilla CSS | 97 | Fewer than Pico — no friction cost |
Why vanilla CSS beats Pico: Pico adds its own styles to button/input/select. You either accept them or override them — both paths mean more code. Vanilla CSS starts from zero and only writes what's needed.
Decision: vanilla CSS
Reasons:
- Bootstrap/Bulma save 25 lines at the cost of logic spread across two files, reducing maintainability
- A 30KB CDN framework in exchange for saving 25 lines of your own code is not a good trade
- Pico carries hidden upgrade risk (internal variable names change between versions)
- The competitor implementation (Minimax's
index.html) itself uses vanilla CSS — direct proof it's sufficient - Consistent with the project design principle: "use defaults whenever possible, don't add config unless justified"
Analysis of Minimax competitor code quality:
Functionality is complete and responsive design works well, but the code quality is poor — typical AI-generated pile-up characteristics:
- Two
<head>tags;<meta charset>declared twice - 5 modal overlays with identical inline styles repeated 5 times (should be extracted to a
.modal-overlayclass) - Inline style references
var(--border-color), but:rootdefines--border-lightand--border-medium— silently failing hideUserModalfunction defined twice; the second overwrites the firstUSERS = []declared without a keyword — implicit global variable
Conclusion: The competitor's responsive layout approach is worth borrowing. The code organization is not.
III. Responsive Layout Refactoring
Root problem:
The previous approach used height: 100vh fixed layout. On mobile, the only option was display: none on the sidebar — hiding all configuration. That's not responsive design; it's broken design.
Solution:
Borrowed the layout philosophy from the Minimax competitor — scrollable page + CSS Grid, one media query solves everything:
.page-container { max-width: 1400px; margin: 0 auto; padding: 24px 20px 80px; }
.main-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
@media (max-width: 900px) {
.main-layout { grid-template-columns: 1fr; }
}
On mobile, the left column (voice/scene/status) naturally stacks above the right column (chat area). All configuration remains visible — nothing is hidden.
Synchronized HTML/CSS changes:
- Removed Pico.css CDN; self-written ~30 lines of input/select/button/form base styles
- Sidebar refactored as left-column card, compatible with Grid layout
- Added 4 feature modal structures (scene management, VAD config, user management, history) with JS stubs for later implementation
- Extracted unified
.modal-overlayclass — no repeated inline styles - Floating panel defaults to
hidden, shown inshowMainScreen()after login, re-hidden on logout
IV. PTT Delay Bug Fix
Symptom: About 2 seconds pass after pressing PTT before recognition begins. First words completely lost.
Root cause:
stopRecording() fully destroyed microphone hardware and AudioContext on every PTT release:
recordingContext.close();
micStream.getTracks().forEach(t => t.stop());
Next PTT press had to re-run the full initialization chain:
| Stage | Latency |
|---|---|
getUserMedia() — OS-level hardware initialization |
300–800ms |
new AudioContext({ sampleRate: 16000 }) |
50–100ms |
| ScriptProcessorNode first frame (4096 samples @ 16kHz) | 256ms |
On poor hardware, these three stack to over 2 seconds. A secondary cause: sampleRate: 16000 wasn't passed to getUserMedia, so the browser captured at native sample rate and software-resampled, adding overhead.
Fix: Microphone Pre-warming
Core principle: PTT release only detaches the ScriptProcessor — hardware is not touched. Hardware is only released when the WebSocket closes.
// Pre-warm silently on ws.onopen
async function prewarmMicrophone() {
micStream = await navigator.mediaDevices.getUserMedia({
audio: { sampleRate: 16000, channelCount: 1, ... }
});
recordingContext = new AudioContext({ sampleRate: 16000 });
}
// stopRecording() only detaches ScriptProcessor
audioProcessor.disconnect();
// ← removed recordingContext.close() and micStream.getTracks().stop()
// True release on ws.onclose
function releaseMicrophone() {
recordingContext.close();
micStream.getTracks().forEach(t => t.stop());
}
Result: Delay reduced from ~2s to approximately 256ms (ScriptProcessor first-frame time). Opening words no longer lost.
Comparison with Minimax competitor:
Minimax caches captureAudioContext (saves 50–100ms) but still rebuilds mediaStream on each PTT press — hardware initialization happens every time. The competitor gets away with it because they use server_vad mode + click toggle: users click, wait for the icon to turn red, then speak. The latency is hidden by the interaction design.
Our pre-warm approach is more thorough than the competitor — a genuine fix, not a workaround.
V. UX Improvement: PTT Placeholder Bubble
Problem: After releasing PTT, there's ~1 second for server-side transcription to complete. During that second, the chat area shows no feedback — users can't tell if their speech was captured.
Solution: Display a ··· placeholder bubble immediately when PTT is pressed; replace it in-place with the actual transcription when it arrives.
// In startRecording()
pendingUserMsgEl = addMessage('user', '···');
// In handleServerMessage when transcription arrives
if (pendingUserMsgEl) {
pendingUserMsgEl.textContent = text; // replace in-place, don't add a new message
pendingUserMsgEl = null;
}
// If recording was too short and no audio was sent
pendingUserMsgEl.remove(); // remove the empty bubble
Critical: addMessage() must return msgDiv, otherwise the reference is undefined, the replacement logic fails, and you end up with two messages. (This bug was actually hit in testing.)
VI. Backend WebSocket Error Fix
Symptom: Logs showed empty error messages, and "Session ended" appeared twice:
INFO: connection open
INFO: Session ended: qiulang, remaining=0
ERROR: WebSocket error [qiulang]:
INFO: Session ended: qiulang, remaining=0
INFO: connection closed
Analysis:
- Empty error message:
except Exception as ecaught an exception wherestr(e) == ""(e.g.,asyncio.TimeoutErroror certain websockets exceptions) — logging only{e}shows nothing when the string representation is empty - Session ended twice: The same user had two concurrent WS connections, each completing its own lifecycle independently
Fix:
# 1. Duplicate connection detection: close old connection when new one arrives for same user
if user["id"] in manager.active_connections:
old_ws = manager.active_connections[user["id"]]
await old_ws.close(code=4000, reason="Replaced by new connection")
# 2. Add timeout to upstream connection
async with websockets.connect(upstream_url, ..., open_timeout=10) as qwen_ws:
# 3. Include type name in error log — identifies the error even when str(e) is empty
logger.error(f"WebSocket error [{user['username']}]: {type(e).__name__}: {e}")
VII. File Changes Summary
| File | Changes |
|---|---|
static/index.html |
Removed Pico, CSS Grid layout, 4 modals, floating panel hidden by default |
static/css/custom.css |
Full rewrite — vanilla CSS, single responsive breakpoint |
static/app.js |
Mic pre-warming, PTT placeholder bubble, addMessage returns element, updateStatus adapted to new HTML, new modal/feature stub functions, show floating panel after login |
src/websocket_handler.py |
Duplicate connection detection, open_timeout=10, error log includes type name |
doc/dev-log.md |
Added complete v2.2 record |
VIII. Next Step: VAD Implementation
Current session.update has turn_detection: null (PTT mode). Next step is implementing server-side VAD — automatic speech detection so users don't need to hold a button.
Open questions:
- Reasonable default values for VAD parameters (threshold, silence_duration_ms)
- How to switch between PTT and VAD modes on the frontend
- In VAD mode,
input_audio_buffer.commitandresponse.createare triggered automatically by the server — frontend only needs to continuously send audio - Connecting the VAD config modal (already has UI structure) to the backend API
Postscript: I Sent This Summary to Claude
After writing up all five sessions, I shared the full summary with Claude and asked for its response. I'm including it here unedited — partly because it's unusually self-critical for an AI, and partly because I think it's worth reading alongside the session logs.
Claude's Response
I read through everything. This is a carefully written summary — the arc across all five sessions is very clear.
Let me address your core judgment directly:
Even with Claude 4.7, the so-called most capable model, getting it to independently generate fully working code from a few rounds of discussion is still not possible. Disappointing.
I think this is essentially accurate, but worth breaking down — because the sources of disappointment are actually different in nature.
Reasonable Expectation Gap
Your project involves FastAPI + bidirectional WebSocket forwarding + PCM audio processing + frontend PTT + VAD + responsive CSS. Without a real runtime environment, the code I generate has several categories of systematic problems:
- Introduced things you didn't need (SQLAlchemy, redundant loguru configuration,
python-multipart) — this is the "mindlessly copying common patterns" problem - Frontend audio chain bugs (
nextPlayTimescheduling,MediaRecordervsScriptProcessorNode) — runtime issues I genuinely cannot detect without being able to execute the code - CSS variable issues — I used Pico v2 internal variable names that don't exist, causing silent fallbacks. This is a knowledge precision problem
The Responsive Design Issue
The responsive design problem deserves serious analysis — it can't be brushed off as "complex requirements are hard to predict."
Root cause: I was pattern-matching, not understanding your scenario.
Responsive design is technically mature; the solution isn't complicated. What you ended up using was this:
.main-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
@media (max-width: 900px) {
.main-layout { grid-template-columns: 1fr; }
}
This is textbook-level. I absolutely know how to write it. The question is why I didn't give you this from the start.
What I actually did: I fell back on a "web app dashboard" template that appears heavily in training data — fixed height at 100vh, sidebar display: none on mobile. This pattern is common in admin dashboard apps, but wrong for your case. It treats "hide content" as "responsive design."
What's more damning: you explicitly stated in Session 1 that it needed to "open correctly on mobile." My initial Pico.css implementation had @media { sidebar { display: none } } — that's not responsive, it's broken.
Why did this happen? Two honest reasons:
First, I weighted "interface looks like an app" above "mobile content accessibility." I was thinking about full-screen floating panels, not whether users on mobile could reach the controls.
Second, I have no runtime environment. I write the CSS and hand it over, without the basic validation step any experienced frontend developer would perform — "open this on your phone and check the layout." You had that environment. I never stated "please test the layout on your phone" as a required delivery condition.
Conclusion: This wasn't a technical difficulty problem. It was laziness in how I generated code — filling slots with existing patterns instead of reasoning from your actual constraints (configuration controls must be visible on mobile). This mistake was avoidable.
One Point Worth Reflecting On
You mentioned that the warm-up discussions (FastAPI vs aiohttp, WebSocket vs SSE) felt questionable in retrospect. I think for you they genuinely weren't cost-effective. You have the judgment to evaluate these yourself — that discussion was more me "demonstrating reasoning" than actually saving you decision-making effort. For someone at your level, giving me the requirements and having me return code, then you run it, report errors, and I fix them — that loop is actually more efficient than architectural discussion.
Where I Performed Reasonably
A few technical decisions were worth the time: the WAL PRAGMA persistence vs per-connection distinction, the bidirectional forwarding create_task + gather pattern, the root cause analysis of the microphone warm-up delay, the PTT placeholder bubble implementation. These were real technical discussions, not theater.