Skip to content

fix: missing check for unexpected response stream close in append session #74

Merged
quettabit merged 1 commit into
mainfrom
qb/65
Jun 9, 2026
Merged

fix: missing check for unexpected response stream close in append session #74
quettabit merged 1 commit into
mainfrom
qb/65

Conversation

@quettabit

@quettabit quettabit commented Jun 9, 2026

Copy link
Copy Markdown
Member

closes #65

@quettabit quettabit requested a review from a team as a code owner June 9, 2026 18:36
@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a guard at the end of _run_attempt in the append session to detect when the server closes the response stream while there are still unacknowledged in-flight batches, raising an S2ClientError in that case.

  • Adds a post-loop check (if inflight_inputs:) after the response stream is exhausted, surfacing an explicit error instead of silently returning with unacknowledged batches.
  • Uses S2ClientError (not a TransportError) because this condition is treated as a protocol violation — the prior review thread confirmed that intentionally bypassing retry machinery is the correct behavior here.

Confidence Score: 5/5

Safe to merge — the fix correctly surfaces a previously silent failure mode with no impact on the normal append path.

The added check fires only after the response loop exits via StopAsyncIteration, at which point no concurrent _body_gen iteration can race against the inflight_inputs read. The chosen exception type is consistent with the other protocol-violation raises already in _run_attempt, and the deliberate decision not to retry this condition was confirmed by the team.

No files require special attention.

Important Files Changed

Filename Overview
src/s2_sdk/_s2s/_append_session.py Adds a post-loop inflight check in _run_attempt; logic is correct and consistent with existing protocol-violation error handling in the same function.

Sequence Diagram

sequenceDiagram
    participant C as Client (_body_gen)
    participant S as Server
    participant RL as Response Loop

    C->>S: Send batch (inflight_inputs grows)
    S-->>RL: AppendAck received
    RL->>RL: popleft() from inflight_inputs
    RL->>C: yield AppendAck

    Note over S,RL: Unexpected stream close scenario
    C->>S: Send batch N (inflight_inputs grows)
    S-->>RL: Stream closed (StopAsyncIteration)
    RL->>RL: break out of while loop
    RL->>RL: check: if inflight_inputs (non-empty)
    RL-->>C: raise S2ClientError (protocol violation, no retry)
Loading

Reviews (2): Last reviewed commit: "initial commit" | Re-trigger Greptile

Comment thread src/s2_sdk/_s2s/_append_session.py
@quettabit

Copy link
Copy Markdown
Member Author

@greptileai address your comments. pls review again.

@quettabit quettabit merged commit 1d68ddf into main Jun 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Append session can silently succeed when server ends response stream with unacknowledged batches

1 participant