Skip to content

fix: retry pusher close admission refusals without write-failure backoff - #24189

Merged
Git-on-my-level merged 5 commits into
mainfrom
lane/closeadmit
Oct 31, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
lane/closeadmit

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Problem and change

At four active close calls, pusher refused admission before submitting a write, then counted that refusal as a finish/seal failure and advanced the exponential retry ladder. Retained drain workers could consequently wait 30–60 seconds for capacity that had already returned.

Count pre-write refusals in omi_pusher_record_close_refusals_total{reason="admission"|"outstanding"} and retry them after 0.5–2 seconds of jitter without advancing the failure ladder or finish/seal failure metrics. Preserve the existing outstanding-cap metric. Actual write exceptions retain the existing exponential backoff. The four active calls, twelve outstanding calls, thirty-second deadline, drain cap and receive queue wait remain unchanged. Tokens clear only after successful durable writes.

The closed-socket ownership predicate includes close_retry_at, so a seal-only admission retry retains its worker after the token clear succeeds or on an empty reconnect. Successful retirement clears that scheduling state.

Validation

  • TZ=UTC BACKEND_PYTEST_WORKERS=1 BACKEND_UNIT_TEST_FILE_LIST=/Volumes/Ephemeral/scratch/closeadmit/tests.txt /Users/dazheng/workspace/omi/bin/omi-heavy run -- nice -n 19 bash backend/test.sh: 109 passed across record barrier executor, pusher queue wait, record seal and the existing reason-label guard tests. Real barrier and strict Firestore cover admission versus real write failures, retry suppression, retained tokens, and a fifth close completing after one of four held slots frees. Real-router cases also cover seal-only refusal past socket drain, same-worker retention and eventual seal for empty reconnects and successfully cleared tokens.
  • Offline real-barrier cost probe with pending token-clear sets, sixty virtual one-second drain scans: 32 workers/one close used 0.09 ms CPU per simulated second; 235 workers/one close used 0.73 ms; 32 workers/128 closes used 5.85 ms (under 0.6% of one core). This measures scheduling-path CPU only. Refusals submit no write, task or timer; the existing drain loop yields one second per scan. Even the 128-close case has bounded retry work, rather than a tight loop.
  • TZ=UTC /Users/dazheng/workspace/omi/bin/omi-heavy run -- nice -n 19 bash backend/testing/e2e/run.sh -q --tb=short -k 'listen_pusher_wire_contract or listen_stt': 20 passed, 165 deselected. Real backend routes and wire contract against hermetic dependencies; not live production acceptance.
  • TZ=UTC BACKEND_PYTEST_WORKERS=1 /Users/dazheng/workspace/omi/bin/omi-heavy run -- nice -n 19 scripts/pr-preflight --lane local --pr-body-file /Volumes/Ephemeral/scratch/closeadmit/pr-body.md: all 34 selected guards passed.

Release acceptance

Lead owns merge and pusher deployment, alongside #24188. No production access or writes in this lane. After the new release serves, compare aggregate five-minute rates of omi_pusher_record_close_refusals_total{reason="admission"}, omi_pusher_record_barrier_failures_total{stage=~"finish|seal"}, and pusher_receive_work_stalled_handlers{stage="drain"}. A positive admission rate directly establishes contention; declining real failure/drain stock tests its operational impact. A quiet window cannot prove the prior wave's cause.

Failure-Class: none

No existing failure-class definition matches pre-dispatch semaphore contention being charged as a storage write failure; this scoped change adds the typed boundary and behavioral guard without expanding the registry.

Retry pre-write capacity refusals on short jitter without consuming the
write-failure ladder, and count the closed admission/outstanding reasons.
Keep durable token proof and all concurrency and deadline bounds intact.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T20:54:31.430941Z 3cc7a7c New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: fec9602fe4

ℹ️ 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 +376 to +380
def _close_admission_refused(self, conversation_id: str) -> bool:
# The drain loop already yields between scans. A positive, jittered
# retry time also bounds admission checks without adding tasks/timers.
self.close_retry_at[conversation_id] = time.monotonic() + random.uniform(0.5, 2.0)
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include admission-only retries in closed-drain ownership

When a durable session has only a seal left to perform (an empty reconnect, or a session whose token clears already succeeded), admission refusals now populate only close_retry_at, leaving upload_sessions, pending_clears, and close_failures empty. If contention persists through the 30-second socket drain timeout—for example, because the outstanding-call cap remains occupied—drain_socket_tasks() in backend/routers/pusher.py:1795–1800 sees no record debt and does not retain the worker; final cleanup then cancels its pending seal. Previously these refusals populated close_failures, preserving worker ownership. Include close_retry_at or pending close requests in the handoff predicate so this change does not abandon admission-only seal retries.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in b4956c1 (ownership delta 0191b2d / 3cc7a7c). The socket-to-process retention condition now includes close_retry_at. Two real-router regressions cover empty reconnects and a successful token clear followed by a real seal admission refusal: the same worker survives the drain budget, seals after capacity returns, and retire_close removes the retry state. The focused shard plus existing label guard passes 109 tests; targeted hermetic listen/pusher E2E passes 20. No concurrency or deadline bounds changed.

Include pending admission retry timestamps in the socket-to-process debt
predicate after token clears succeed. Exercise empty reconnects and cleared
tokens through the real router, retained worker and eventual durable seal.
Keep both reason children statically closed for the existing AST guard,
without extending label debt or changing admission behavior.

@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: 3cc7a7cfa3

ℹ️ 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 +50 to +54
RECORD_CLOSE_REFUSALS = Counter(
'omi_pusher_record_close_refusals_total',
'Close metadata calls refused before any write is submitted',
['reason'],
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the required pusher pipeline contract

backend/AGENTS.md requires listen/pusher WebSocket changes to update backend/docs/listen_pusher_pipeline.mdx in the same PR, but this commit leaves that contract unchanged. Its “Pusher receive work and committed projection capacity” section still specifies seven metric families and the old series budget, omitting the new refusal counter and the distinction between admission retries and write-failure backoff. Update that section with the new metric, retry behavior, and seal-only drain ownership so release verification covers contention that no longer appears in finish/seal failure metrics.

AGENTS.md reference: backend/AGENTS.md:L164-L164

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 28fbce6 into main Oct 31, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/closeadmit branch October 31, 2026 21:09
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