Skip to content

fix(proxy): abandon unavailable owner on thread-scoped goal restart - #1764

Open
mastertyko wants to merge 5 commits into
Soju06:mainfrom
mastertyko:fix/goal-restart-thread-abandonment
Open

fix(proxy): abandon unavailable owner on thread-scoped goal restart#1764
mastertyko wants to merge 5 commits into
Soju06:mainfrom
mastertyko:fix/goal-restart-thread-abandonment

Conversation

@mastertyko

@mastertyko mastertyko commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Current Codex sends both a shared process session-id and a distinct thread-id on a self-contained goal restart. Affinity classified that request as thread_header, so the one-shot abandon_unavailable_legacy_owner flag never set and retirement CAS never ran. The restart stayed fail-closed on the unavailable legacy owner.

Type of change

  • fix: — bug fix (no behavior change beyond the bug)

Linked issue: None — leftover composition hole after #1680 and #1703; no matching open issue.

OpenSpec

  • This PR includes / updates an OpenSpec change

Change directory: openspec/changes/goal-restart-thread-header-abandonment/

Changes

  • Grant goal-restart abandonment when a thread-scoped request still carries a process session.
  • Allow retirement CAS from thread_header requests. The write stays scoped to session_header interpretation.
  • Consult the raw process-session row as session_header interpretation so a scoped tombstone cannot revive the retired owner on later thread-id turns.
  • Keep explicit turn_state, incremental, file-pinned, conversation-bound, and unresolved tool-state requests fail-closed.

Test plan

uv run pytest tests/unit/test_proxy_utils.py::test_goal_restart_affinity_can_abandon_only_legacy_session_owner \
  tests/unit/test_proxy_utils.py::test_goal_restart_affinity_preserves_owner_for_account_dependent_thread_payloads \
  tests/unit/test_proxy_utils.py::test_goal_restart_affinity_preserves_owner_for_account_dependent_payloads \
  tests/unit/test_load_balancer_concurrency.py::test_goal_restart_with_thread_header_retires_unavailable_legacy_owner \
  tests/unit/test_load_balancer_concurrency.py::test_goal_restart_does_not_repin_retired_owner_from_stale_selection_snapshot \
  tests/integration/test_proxy_sticky_sessions.py::test_codex_goal_restart_retires_unavailable_legacy_owner_and_stays_on_replacement -q
# 16 passed

openspec validate goal-restart-thread-header-abandonment --strict
# valid

Intentionally not run locally: full pre-commit / local-ci, ty check of the whole tree, and dashboard/browser suites. Those stay on required GitHub CI.

Related work

Checklist

  • Title is in Conventional Commits format.
  • Added or updated tests covering the change.
  • Focused unit/integration checks and scoped OpenSpec validation passed.
  • CHANGELOG is not edited by hand.

Summary by CodeRabbit

  • New Features

    • Self-contained goal restarts with session and thread continuity can move to an eligible replacement when the previous owner is unavailable.
    • Subsequent turns remain associated with the replacement account.
  • Bug Fixes

    • Prevented retired ownership from being revived during later thread activity.
    • Preserved fail-closed behavior for account-dependent requests and explicit turn ownership.
    • Maintained existing behavior for session-based continuity.
  • Tests

    • Added regression coverage for replacement selection, tombstones, continuity, and owner preservation.

Current Codex sends thread-id with the process session, so affinity
classified the restart as thread_header and never retired the raw
legacy owner.

Grant the one-shot abandonment flag when a process session is present,
allow retirement CAS from thread_header requests, and consult the raw
row as session_header interpretation so later thread turns stay on the
replacement.
@mastertyko

Copy link
Copy Markdown
Contributor Author

@codex review

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mastertyko, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8013073c-8d80-4f07-b632-aba890e3af47

📥 Commits

Reviewing files that changed from the base of the PR and between 13f5201 and f0e7a83.

📒 Files selected for processing (2)
  • app/modules/proxy/_service/http_bridge/request_submit.py
  • tests/unit/test_proxy_utils.py

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 169eeb80-e38b-44fd-8ff8-2273cac046ae

📥 Commits

Reviewing files that changed from the base of the PR and between 076f0c7 and 13f5201.

📒 Files selected for processing (7)
  • app/modules/proxy/_service/codex_control.py
  • app/modules/proxy/_service/websocket/mixin.py
  • app/modules/proxy/affinity.py
  • app/modules/proxy/load_balancer.py
  • app/modules/proxy/service.py
  • tests/integration/test_proxy_sticky_sessions.py
  • tests/unit/test_proxy_utils.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/test_proxy_utils.py

📝 Walkthrough

Walkthrough

Thread-header goal restarts can abandon unavailable raw process-session owners. Retirement and lookup use session_header semantics. Explicit turn_state ownership and account-dependent requests remain fail-closed.

Changes

Sticky restart routing

Layer / File(s) Summary
Restart abandonment contract
openspec/changes/goal-restart-thread-header-abandonment/*, openspec/specs/sticky-session-operations/*
OpenSpec defines thread-scoped restart abandonment, session-header retirement and lookup, explicit turn_state preservation, replacement continuity, and fail-closed cases.
Affinity and legacy lookup
app/modules/proxy/affinity.py, app/modules/proxy/_load_balancer/sticky_selection.py, app/modules/proxy/load_balancer.py
Affinity records continuity provenance. Qualifying thread-header requests can abandon unavailable legacy owners. Legacy continuity rows use session_header interpretation.
Account-selection propagation
app/modules/proxy/_service/codex_control.py, app/modules/proxy/_service/websocket/mixin.py, app/modules/proxy/service.py
Account-selection paths forward the affinity continuity source through initial selection, failover, retry, WebSocket, and budget-aware routing.
Restart routing regression coverage
tests/unit/test_load_balancer_concurrency.py, tests/unit/test_proxy_utils.py, tests/integration/test_proxy_sticky_sessions.py
Tests cover retirement, tombstones, replacement thread mappings, policy selection, owner preservation, fail-closed turn-state handling, and distinct raw mappings.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 13f52

The change enables recovery for the affected goal-restart requests while preserving fail-closed handling for other request types. Focused tests and validation pass, and no actionable merge-blocking risk remains.

Suggested reviewers: leventov, soju06, komzpa

Sequence Diagram(s)

sequenceDiagram
  participant GoalRestartRequest
  participant Affinity
  participant AccountSelection
  participant StickySelection
  participant ReplacementAccount
  GoalRestartRequest->>Affinity: Send process-session and thread-header identity
  Affinity->>AccountSelection: Forward legacy continuity source
  AccountSelection->>StickySelection: Interpret raw key as session_header
  StickySelection->>StickySelection: Retire unavailable owner
  AccountSelection->>ReplacementAccount: Select eligible replacement
  ReplacementAccount->>GoalRestartRequest: Continue thread on replacement
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes abandoning an unavailable owner during a thread-scoped goal restart, which is the main change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

ty rejects subscripting account_ids_by_key because the stub field is
optional. Compare the whole mapping like the existing session-header test.
@mastertyko

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 076f0c77a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/load_balancer.py Outdated
Comment thread tests/unit/test_load_balancer_concurrency.py
Codex review: a hardcoded session_header lookup hid thread-only raw
rows after a process-session tombstone, and the restart path lacked
/backend-api/codex/responses coverage for session-id plus thread-id.

Look up the raw key with the source that actually wrote it, and add
the route-level restart plus follow-up continuity test.
@mastertyko

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 13f5201626

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mastertyko

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7082250a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/affinity.py
Security-authorized replacement still looked up the raw process-session
row with thread_header, so a session_header tombstone resurrected the
retired owner as a continuity conflict.

Lookup the raw key with legacy_continuity_source instead.
@mastertyko

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: f0e7a83d97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant