Use only stderr for code auto-fix error detection

Update code execution error detection to use stderr exclusively
instead of checking both stdout and stderr. This aligns with the
Unsandbox API's proper stream separation where:
- stdout is for program output
- stderr is for errors/warnings

Changes:
- Remove stdout from error detection logic
- Only trigger auto-fix when exit_code != 0 AND stderr is non-empty
- Send only stderr to /api/fix-code endpoint

This prevents false positives where stdout contains normal output
that was previously being treated as error content.
This commit is contained in:
Russell Ballestrini 2025-12-01 11:49:33 -05:00
parent 22ed72da7e
commit 030b1cc447

View file

@ -1594,11 +1594,9 @@ async function executeCodeBlock(code, blockElement, playButton) {
// Check if execution failed and attempt auto-fix // Check if execution failed and attempt auto-fix
const exitCode = job.exit_code; const exitCode = job.exit_code;
const stderr = job.stderr || ''; const stderr = job.stderr || '';
const stdout = job.stdout || '';
// Error messages can be in either stderr OR stdout (Python puts tracebacks in stdout) // Only use stderr for error detection (stdout/stderr properly separated now)
const errorOutput = stderr.trim() || stdout.trim(); const shouldAutoFix = exitCode !== 0 && stderr.trim() !== '';
const shouldAutoFix = exitCode !== 0 && errorOutput !== '';
// Track attempts per code block (store in resultsContainer dataset) // Track attempts per code block (store in resultsContainer dataset)
if (!resultsContainer.dataset.fixAttempts) { if (!resultsContainer.dataset.fixAttempts) {
@ -1629,7 +1627,7 @@ async function executeCodeBlock(code, blockElement, playButton) {
body: JSON.stringify({ body: JSON.stringify({
code: code, code: code,
language: language, language: language,
stderr: errorOutput, // Send combined error output (stderr or stdout) stderr: stderr, // Send only stderr (properly separated now)
exit_code: exitCode, exit_code: exitCode,
attempt: currentAttempts + 1 attempt: currentAttempts + 1
}) })