Async fsync, so writes from PTY to host terminal are fast again.

This commit is contained in:
Mario Zechner 2025-06-24 00:52:27 +02:00
parent e9b395b726
commit bb17f4adcd
3 changed files with 28 additions and 11 deletions

View file

@ -1,8 +1,5 @@
# Claude Development Notes # Claude Development Notes
**IMPORTANT**: BEFORE YOU DO ANYTHING, READ spec.md IN FULL USING THE READ TOOL!
**IMPORTANT**: NEVER USE GREP. ALWAYS USE RIPGREP!
## Updating spec.md ## Updating spec.md
As code changes, the spec.md might get outdated. If you detect outdated information, ask the user if they want to regenerate the spec.md file. As code changes, the spec.md might get outdated. If you detect outdated information, ask the user if they want to regenerate the spec.md file.
@ -15,6 +12,8 @@ As code changes, the spec.md might get outdated. If you detect outdated informat
- API endpoints and protocols - API endpoints and protocols
- Binary buffer format and WebSocket implementation - Binary buffer format and WebSocket implementation
- HQ mode and distributed architecture - HQ mode and distributed architecture
- Activity tracking
- Anything else not covered above
3. Focus on capturing: 3. Focus on capturing:
- File locations with key line numbers for important functions - File locations with key line numbers for important functions
- Component responsibilities and data flow - Component responsibilities and data flow
@ -26,7 +25,7 @@ As code changes, the spec.md might get outdated. If you detect outdated informat
## Build Process ## Build Process
- **Never run build commands** - the user has `npm run dev` running which handles automatic rebuilds - **Never run build commands** - the user has `npm run dev` running which handles automatic rebuilds
- Changes to TypeScript files are automatically compiled and watched - Changes to TypeScript files are automatically compiled and watched
- Do not run `npm run build:client` or similar build commands - Do not run `npm run build` or similar build commands
## Development Workflow ## Development Workflow
- Make changes to source files in `src/` - Make changes to source files in `src/`
@ -38,8 +37,19 @@ As code changes, the spec.md might get outdated. If you detect outdated informat
- Always fix all linting and type checking errors, including in unrelated code - Always fix all linting and type checking errors, including in unrelated code
- Never run the tests, unless explicitely asked to. `npm run test` - Never run the tests, unless explicitely asked to. `npm run test`
**CRITICAL** ## Code References
- **NEVER EVER USE SETTIMEOUT FOR ANYTHING IN THE FRONTEND UNLESS EXPLICITLY PERMITTED** **THIS IS OF UTTER IMPORTANCE THE USERS HAPPINESS DEPENDS ON IT!**
When referencing code locations, you MUST use clickable format that VS Code recognizes:
- `path/to/file.ts:123` format (file:line)
- `path/to/file.ts:123-456` (ranges)
- Always use relative paths from the project root
- Examples:
- `src/server/fwd.ts:92` - single line reference
- `src/server/pty/pty-manager.ts:274-280` - line range
- `web/src/client/app.ts:15` - when in parent directory
## Server Execution NEVER give a code reference or location in any other format.
- NEVER RUN THE SERVER YOURSELF, I ALWAYS RUN IT ON THE SIDE VIA NPM RUN DEV!
## CRITICAL
**IMPORTANT**: BEFORE YOU DO ANYTHING, READ spec.md IN FULL USING THE READ TOOL!
**IMPORTANT**: NEVER USE GREP. ALWAYS USE RIPGREP!

View file

@ -8,6 +8,9 @@
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { AsciinemaHeader, AsciinemaEvent, PtyError } from './types.js'; import { AsciinemaHeader, AsciinemaEvent, PtyError } from './types.js';
import { createLogger } from '../utils/logger.js';
const logger = createLogger('AsciinemaWriter');
export class AsciinemaWriter { export class AsciinemaWriter {
private writeStream: fs.WriteStream; private writeStream: fs.WriteStream;
@ -162,7 +165,11 @@ export class AsciinemaWriter {
// Force immediate disk write to trigger file watchers // Force immediate disk write to trigger file watchers
if (this.fd !== null) { if (this.fd !== null) {
try { try {
fs.fsyncSync(this.fd); fs.fsync(this.fd, (err) => {
if (err) {
logger.error(`Failed to fsync asciinema file: ${err.message}`);
}
});
} catch (_e) { } catch (_e) {
// Ignore sync errors // Ignore sync errors
} }

View file

@ -350,10 +350,10 @@ export class PtyManager extends EventEmitter {
} }
} }
// Write to asciinema file // Write to asciinema file (now async, non-blocking)
asciinemaWriter?.writeOutput(Buffer.from(data, 'utf8')); asciinemaWriter?.writeOutput(Buffer.from(data, 'utf8'));
// Forward to stdout if requested (for fwd.ts) // Forward to stdout if requested (for fwd.ts) with batching
if (forwardToStdout) { if (forwardToStdout) {
process.stdout.write(data); process.stdout.write(data);
} }