vxcontrol/pentagi · error

failed to put terminal log (read file cmd): %w

Error message

failed to put terminal log (read file cmd): %w

What it means

Before reading the file, ReadFile echoes the 'cat <path>' command into the terminal transcript via t.tlp.PutMsg with TermlogTypeStdin. This error wraps a failure of that logging write, meaning the read operation is aborted so the transcript stays consistent with executed commands.

Source

Thrown at backend/pkg/tools/terminal.go:341

		results = "Command completed successfully with exit code 0. No output produced (silent success)"
	}

	return results, nil
}

func (t *terminal) ReadFile(ctx context.Context, flowID int64, path string) (string, error) {
	if path == "" {
		return "", fmt.Errorf("path is required and cannot be empty")
	}

	cwd := docker.WorkFolderPathInContainer
	escapedPath := strings.ReplaceAll(path, "'", "'\"'\"'")
	catCommand := fmt.Sprintf("cat '%s'", escapedPath)
	// Format read file command with styling
	styledCommand := fmt.Sprintf("%s $ %s%s%s%s", cwd, ansiColorInputCmd, catCommand, ansiColorReset, ansiLineTerminator)
	_, err := t.tlp.PutMsg(ctx, database.TermlogTypeStdin, styledCommand, t.containerID, t.taskID, t.subtaskID)
	if err != nil {
		return "", fmt.Errorf("failed to put terminal log (read file cmd): %w", err)
	}

	content, err := t.readFileFromContainer(ctx, flowID, path)
	if err != nil {
		return "", err
	}

	// Style file content output
	styledContent := fmt.Sprintf("%s%s%s%s", ansiColorSystemMsg, content, ansiColorReset, ansiLineTerminator)
	_, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdout, styledContent, t.containerID, t.taskID, t.subtaskID)
	if err != nil {
		return "", fmt.Errorf("failed to put terminal log (read file content): %w", err)
	}

	return content, nil
}

// readFileFromContainer copies path out of the flow's container and returns

View on GitHub (pinned to ea665308ba)

Solutions

  1. Check database connectivity and pool health
  2. Retry ReadFile once the DB recovers
  3. Consider degrading gracefully: log the failure but proceed with the actual file read

Example fix

// before
if _, err := t.tlp.PutMsg(ctx, database.TermlogTypeStdin, styledCommand, ...); err != nil {
    return "", fmt.Errorf("failed to put terminal log (read file cmd): %w", err)
}
// after
if _, err := t.tlp.PutMsg(ctx, database.TermlogTypeStdin, styledCommand, ...); err != nil {
    log.Warn("termlog stdin write failed", "err", err) // proceed with read
}
Defensive patterns

Strategy: fallback

Validate before calling

if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("skipping read: termlog store unavailable: %w", err)
}

Try / catch

content, err := term.ReadFile(ctx, flowID, path)
if err != nil && strings.Contains(err.Error(), "failed to put terminal log (read file cmd)") {
    log.Warn("stdin termlog write failed; read aborted", "err", err)
    // retry later or degrade to direct container read
}

Prevention

When it happens

Trigger: PutMsg(ctx, database.TermlogTypeStdin, styledCommand, ...) fails while recording the synthetic cat command — DB unavailable, connection pool exhausted, or the styled command payload is rejected by storage.

Common situations: PostgreSQL outage during agent activity; connection-pool saturation; constraint violations on the termlog table.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/22a06fcf9cf1af4e. Report an issue: GitHub.