-
Notifications
You must be signed in to change notification settings - Fork 412
fix(http-bridge): re-check liveness before retiring a stale pending session #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Komzpa
wants to merge
6
commits into
main
Choose a base branch
from
fix-retire-stale-preaeait-snapshot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37592b8
fix(http-bridge): recheck stale retirement liveness
Komzpa ec11e7e
fix(http-bridge): reopen healthy stale sessions
Komzpa c13f381
fix(api-keys): retain explicit last-used compatibility touch
Komzpa 2cfaeab
fix: serialize stale bridge liveness rechecks safely
Komzpa c009b95
docs: clarify bridge liveness lock ordering
Komzpa 378bd09
fix(http-bridge): revalidate stale-retire liveness
Komzpa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
openspec/changes/fix-retire-stale-preawait-liveness/.openspec.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| schema: spec-driven | ||
| created: 2026-08-06 |
35 changes: 35 additions & 0 deletions
35
openspec/changes/fix-retire-stale-preawait-liveness/design.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## Context | ||
|
|
||
| `_retire_stale_pending_http_bridge_session` awaits retry-circuit persistence before marking the session closed. During that suspension, upstream event handling can update a pending request's response-event count. The current close path never observes that update. | ||
|
|
||
| ## Goals / Non-Goals | ||
|
|
||
| **Goals:** | ||
|
|
||
| - Make the close decision use fresh pending-turn liveness after all suspension points. | ||
| - Keep registry removal and session close mutually exclusive with concurrent event bookkeeping. | ||
| - Retain genuine stale-session retirement and existing retry-circuit behavior. | ||
|
|
||
| **Non-Goals:** | ||
|
|
||
| - Redesign retry-circuit persistence or bridge event routing. | ||
| - Change stale thresholds, retry details, or public response behavior. | ||
|
|
||
| ## Decisions | ||
|
|
||
| - Hold `_http_bridge_lock` while acquiring `session.pending_lock` for the final decision. This keeps registry identity and pending liveness from being observed as a mixed snapshot. | ||
| - Compute the final response-event signal from the current pending request states, while retaining the caller's explicit signal as a lower bound for callers that already observed an event. If any current request has a response id or response-created latency, treat it as healthy too. | ||
| - Only then set `session.closed`, unregister the session, and claim the upstream close. If liveness is present, return without mutating retirement state. | ||
|
|
||
| ## Risks / Trade-offs | ||
|
|
||
| - [Lock ordering] Nested locks could deadlock if another path acquires them in reverse order. Existing bridge registry cleanup uses bridge-lock-then-pending-lock ordering; keep the new critical section consistent. | ||
| - [Completed request removed] A terminal event removed before the final sample is no longer available in pending state; this change does not invent durable session-wide event history. | ||
|
|
||
| ## Migration Plan | ||
|
|
||
| Deploy as a normal application change. Rollback is a revert of the single commit; no data migration is required. | ||
|
|
||
| ## Open Questions | ||
|
|
||
| None. |
22 changes: 22 additions & 0 deletions
22
openspec/changes/fix-retire-stale-preawait-liveness/proposal.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ## Why | ||
|
|
||
| Stale HTTP bridge retirement currently decides from a pre-await zero-event snapshot. A healthy pending turn can receive its first response event while retry-circuit bookkeeping suspends, then be closed and removed anyway. | ||
|
|
||
| ## What Changes | ||
|
|
||
| - Re-sample pending-turn liveness immediately before stale retirement closes a session. | ||
| - Perform the registry identity, pending-state liveness, and close decision under the existing bridge/session locks. | ||
| - Preserve retirement for sessions that remain genuinely eventless. | ||
| - Add regression and control coverage for both outcomes. | ||
|
|
||
| ## Capabilities | ||
|
|
||
| ### New Capabilities | ||
|
|
||
| ### Modified Capabilities | ||
|
|
||
| - `responses-api-compat`: stale HTTP bridge retirement must not kill a turn that became healthy during retry-circuit suspension. | ||
|
|
||
| ## Impact | ||
|
|
||
| The change is limited to `request_submit.py`, HTTP bridge unit coverage, and the Responses API compatibility OpenSpec delta. No public endpoint or schema changes are introduced. |
18 changes: 18 additions & 0 deletions
18
...c/changes/fix-retire-stale-preawait-liveness/specs/responses-api-compat/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ## ADDED Requirements | ||
|
|
||
| ### Requirement: Stale bridge retirement rechecks liveness after suspension | ||
|
|
||
| Before closing and unregistering a stale HTTP bridge session, the service MUST re-sample pending request liveness after retry-circuit bookkeeping awaits. A response event, response id, or equivalent response-created signal newly observed after the caller's pre-suspension snapshot MUST prevent stale retirement. A session that remains eventless MUST still be retired. | ||
|
|
||
| #### Scenario: First response event arrives during retry-circuit suspension | ||
|
|
||
| - **WHEN** stale retirement samples zero response events and then suspends for retry-circuit bookkeeping | ||
| - **AND** a pending turn receives its first response event before the close decision | ||
| - **THEN** the final decision observes the event under the bridge and pending-state locks | ||
| - **AND** the session remains registered, open, and reusable | ||
|
|
||
| #### Scenario: Session remains eventless during retry-circuit suspension | ||
|
|
||
| - **WHEN** stale retirement samples zero response events and suspends for retry-circuit bookkeeping | ||
| - **AND** no pending turn receives a response or response-created signal | ||
| - **THEN** the final decision retires and unregisters the session |
16 changes: 16 additions & 0 deletions
16
openspec/changes/fix-retire-stale-preawait-liveness/tasks.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ## 1. Regression coverage | ||
|
|
||
| - [x] 1.1 Add a deterministic unit regression that injects a response event during retry-circuit suspension and asserts no retirement. | ||
| - [x] 1.2 Add a control assertion that an eventless stale session is still retired. | ||
| - [x] 1.3 Run the new regression on origin/main and record the expected failure before implementation. | ||
|
|
||
| ## 2. Implementation | ||
|
|
||
| - [x] 2.1 Re-sample response-event and response-created liveness under the bridge/pending locks immediately before the close decision. | ||
| - [x] 2.2 Preserve registry cleanup, close idempotence, retry-circuit accounting, and stale-retire logging. | ||
|
|
||
| ## 3. Verification | ||
|
|
||
| - [x] 3.1 Run the targeted unit regression and control. | ||
| - [x] 3.2 Run the HTTP bridge unit and integration suites, recording the known reconnect baseline failures. | ||
| - [x] 3.3 Validate OpenSpec and commit the focused change without pushing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.