Skip to content

fix(torghut): stabilize scheduler dependency health - #13011

Open
gregkonush wants to merge 2 commits into
mainfrom
codex/torghut-align-scheduler-freshness
Open

fix(torghut): stabilize scheduler dependency health#13011
gregkonush wants to merge 2 commits into
mainfrom
codex/torghut-align-scheduler-freshness

Conversation

@gregkonush

@gregkonush gregkonush commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

  • Raise the shared API/scheduler success-freshness window from 30 to 300 seconds because measured production cycles take 35 to 169 seconds.
  • Reuse one serialized TigerBeetle status client per process instead of creating an uncancellable disposable client for every /trading/status request; apply the existing cancellable RPC deadline and discard failed clients before retry.
  • Close the status client during API and scheduler shutdown while preserving fail-closed protocol and capital-control behavior.

Related Issues

PROOMPT-393

Testing

  • cd services/torghut && .venv/bin/pytest -q tests/test_tigerbeetle_client.py tests/test_tigerbeetle_status.py tests/test_process_roles.py — 60 passed.
  • cd services/torghut && .venv/bin/pytest -q tests/test_tigerbeetle*.py tests/live_config_manifest_contract/test_single_writer_scheduler_manifest.py — 63 passed.
  • cd services/torghut && .venv/bin/pyright -p pyrightconfig.json — 0 errors.
  • cd services/torghut && .venv/bin/ruff check app/api/health_checks/tigerbeetle_health.py app/trading/tigerbeetle_client.py app/bootstrap.py app/scheduler_main.py tests/test_tigerbeetle_status.py tests/test_tigerbeetle_client.py — passed.
  • cd services/torghut && .venv/bin/python scripts/run_pylint_torghut_quality_diff_gate.py --base e0036184dab3442218ff4e08c63d76ab89d1d6a9 app/api/health_checks/tigerbeetle_health.py app/bootstrap.py app/scheduler_main.py app/trading/tigerbeetle_client.py tests/test_tigerbeetle_client.py tests/test_tigerbeetle_status.py — passed.
  • bun run lint:argocd — all rendered Argo resources passed kubeconform.
  • Live baseline on digest sha256:e6448c4c476344eea647f4926872169c25adaa011a5d69c60dfc017cff8d05d9: TigerBeetle reached clients=64/64 with client eviction roughly every 5–6 seconds while scheduler threads remained stable at 74; natural cycle completions ranged from 35 to 169 seconds.

Breaking Changes

None

Checklist

  • Testing section documents the exact validation performed (or N/A with justification).
  • Screenshots and Breaking Changes sections are handled appropriately (removed or filled in).
  • Documentation, release notes, and follow-ups are updated or tracked.

@gregkonush

Copy link
Copy Markdown
Member Author

:shipit:

@gregkonush gregkonush changed the title fix(torghut): align scheduler freshness with cycle duration fix(torghut): stabilize scheduler dependency health Jul 21, 2026

@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: 4b15ee54c8

ℹ️ 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".

}
finally:
executor.shutdown(wait=False, cancel_futures=True)
with _protocol_health_lock:

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 Bound every caller's wait on the probe lock

When TigerBeetle is unresponsive and status requests overlap, the first caller can hold this global lock for the configured 5-second RPC timeout while every later caller waits without any deadline; after acquiring it, each waiter starts another full timeout. Three concurrent /trading/status reads can therefore exceed the 12-second _TradingStatusReadBudget, and a larger burst can occupy the shared FastAPI worker pool even after API proxies have timed out. Use a timed acquisition or share/cache the in-flight probe result so each request has an end-to-end bound, and cover the concurrent-outage case with a regression test.

AGENTS.md reference: AGENTS.md:L94-L96

Useful? React with 👍 / 👎.

@gregkonush
gregkonush force-pushed the codex/torghut-align-scheduler-freshness branch from 4b15ee5 to 36c75a8 Compare July 21, 2026 19:19

@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: 36c75a86df

ℹ️ 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".

finally:
executor.shutdown(wait=False, cancel_futures=True)
with _protocol_health_lock:
client = _protocol_health_client_for_settings(timeout_seconds)

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 Keep client construction inside the health deadline

On the first probe after startup, a failed probe, or a configuration change, this factory call runs synchronously before the timeout-protected client.nop(). RealTigerBeetleClient.__init__ performs socket.getaddrinfo and constructs ClientSync, so a slow Kubernetes DNS resolver or client initialization can now block /trading/status and dependency readiness beyond TORGHUT_TIGERBEETLE_HEALTH_TIMEOUT_SECONDS; the removed executor deadline previously bounded the whole operation. Construct the client within the same end-to-end deadline rather than applying the timeout only to the RPC.

Useful? React with 👍 / 👎.

@gregkonush
gregkonush force-pushed the codex/torghut-align-scheduler-freshness branch from 36c75a8 to 1fea9cd Compare July 21, 2026 19:24
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