Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Event stream decoder drops the final event when reading it reaches EOF

Abierto
#3,374 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@lazerg ya está trabajando en esto.

Desde el 14/10/2026.

  • #3375 de @lazerg — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
aws, php
Área
api, backend

Línea de trabajo

Start with valid() in the NonSeekableStreamDecodingEventStreamIterator class, which currently checks the stream's EOF state after the event is parsed. Run the reproduction in the issue against a BufferStream holding one event frame; it should print int(1) once the fix is in. Done means the final event is yielded even when the read hits EOF, and the existing decoder tests still pass. A test using BufferStream rather than php://temp would cover the regression.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the bug

NonSeekableStreamDecodingEventStreamIterator drops the final event when reading it also reaches the end of the stream. If the stream contains just one event, nothing is returned.

valid() checks the stream’s EOF state after the event has already been parsed, so it can return false even though there’s a complete event ready to yield.

Expected Behavior

I think the decoder should still yield the last complete event, even if reading it reached the end of the stream.

Current Behavior

The example below prints int(0) instead of int(1). No exception is thrown.

Reproduction Steps

This example doesn’t need an AWS account or make any network requests.

Install aws/aws-sdk-php version 3.399.2, then run:

<?php

require 'vendor/autoload.php';

use Aws\Api\Parser\NonSeekableStreamDecodingEventStreamIterator;
use GuzzleHttp\Psr7\BufferStream;

$headers = '';

foreach ([
    ':message-type' => 'event',
    ':event-type' => 'messageStop',
    ':content-type' => 'application/json',
] as $name => $value) {
    $headers .= chr(strlen($name)).$name.chr(7)
        .pack('n', strlen($value)).$value;
}

$payload = '{"stopReason":"end_turn"}';
$prelude = pack('NN', 16 + strlen($headers) + strlen($payload), strlen($headers));
$frame = $prelude.hash('crc32b', $prelude, true).$headers.$payload;
$frame .= hash('crc32b', $frame, true);

$stream = new BufferStream;
$stream->write($frame);

$iterator = new NonSeekableStreamDecodingEventStreamIterator($stream);

var_dump(count(iterator_to_array($iterator)));

Possible Solution

Have valid() check whether there’s a parsed event available, rather than whether the underlying stream has reached EOF.

Additional Information/Context

I also reproduced this through BedrockRuntimeClient::converseStream() using a local HTTP server. It sent messageStop followed by metadata, but only messageStop was returned. Bedrock sends token usage in that final metadata event. ConverseStream documentation.

The existing decoder tests use a php://temp body, which only reports EOF after another read is attempted. BufferStream reports EOF as soon as its last byte is read, exposing the problem.

The same valid() implementation is still present on master. This is separate from #3371; #3373 changes the same decoder to address partial checksum reads.

SDK version used

3.399.2

Environment details

PHP 8.4.25, Ubuntu 24.04.

Generated by Codex, and reviewed by @binaryfire.

Lenguaje dominante
PHP
Estrellas
6.2k
Forks
1.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
10

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws/aws-sdk-php

Todos los issues de aws/aws-sdk-php

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.