Skip to content

app-server: Only unload threads which were unused for some time#17398

Merged
euroelessar merged 3 commits intomainfrom
codex/do-not-unload-active-threads
Apr 13, 2026
Merged

app-server: Only unload threads which were unused for some time#17398
euroelessar merged 3 commits intomainfrom
codex/do-not-unload-active-threads

Conversation

@euroelessar
Copy link
Copy Markdown
Collaborator

@euroelessar euroelessar commented Apr 11, 2026

Currently app-server may unload actively running threads once the last connection disconnects, which is not expected.
Instead track when was the last active turn & when there were any subscribers the last time, also add 30 minute idleness/no subscribers timer to reduce the churn.

@euroelessar
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown
Contributor

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

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: 3b1bcf8548

ℹ️ 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 codex-rs/app-server/src/codex_message_processor.rs Outdated
Comment thread codex-rs/app-server/src/codex_message_processor.rs Outdated
@euroelessar euroelessar marked this pull request as draft April 13, 2026 04:21
@euroelessar
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown
Contributor

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

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: 51e1849342

ℹ️ 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 on lines 3831 to 3833
self.thread_state_manager
.remove_connection(connection_id)
.await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Restore stale-thread teardown on connection close

connection_closed now discards the remove_connection result, so it never reconciles threads whose last subscriber disconnected but whose core thread is already gone. The previous logic called finalize_thread_teardown in that case. Without it, stale app-server state (thread state/watch bookkeeping and pending request mappings) can persist indefinitely.

Useful? React with 👍 / 👎.

Comment on lines +7507 to +7514
let Some(mut unloading_state) = UnloadingState::new(
&listener_task_context,
conversation_id,
THREAD_UNLOADING_DELAY,
)
.await
else {
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Fail subscription when listener setup cannot start

ensure_listener_task_running_task silently returns when UnloadingState::new is None, but its caller still reports Attached. In a concurrent teardown window this yields a successful subscribe response without any listener task, so the client misses turn/item/status events until it retries.

Useful? React with 👍 / 👎.

const LOGIN_CHATGPT_TIMEOUT: Duration = Duration::from_secs(10 * 60);
const LOGIN_ISSUER_OVERRIDE_ENV_VAR: &str = "CODEX_APP_SERVER_LOGIN_ISSUER";
const APP_LIST_LOAD_TIMEOUT: Duration = Duration::from_secs(90);
const THREAD_UNLOADING_DELAY: Duration = Duration::from_secs(30 * 60);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this mean that the issue would still happen on a task that runs for 30 minutes?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Never mind just caught up on the Slack thread

@euroelessar euroelessar marked this pull request as ready for review April 13, 2026 17:18
@euroelessar euroelessar merged commit a5507b5 into main Apr 13, 2026
27 of 30 checks passed
@euroelessar euroelessar deleted the codex/do-not-unload-active-threads branch April 13, 2026 19:25
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants