fix(cron): deliver profile-store jobs with the owning profile's bot under multiplex - #91795
Closed
vinoth12940 wants to merge 2 commits into
Closed
vinoth12940 wants to merge 2 commits into
vinoth12940 wants to merge 2 commits into
Conversation
…nder multiplex Fixes NousResearch#83182.
Contributor
|
load_gateway_config() reads TELEGRAM_BOT_TOKEN from os.environ, which under multiplex holds the DEFAULT profile's token. The ticking profile's token lives in the secret scope (installed by run_one_job), not os.environ. Patch pconfig.token from get_secret() so the standalone delivery lane sends with the correct profile's bot identity. Fixes NousResearch#83182 (delivery identity)
19 tasks
3 tasks
Collaborator
|
Closing after #99375 (merged, commit 9eb832a) landed the delivery-identity fix via earlier submitters @MuhammadUsamaMX (#73363) and @ghosty93 (#92526), whose versions carried tests. Same root cause, later submission. Thanks for the correct analysis. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes cron delivery identity for secondary profiles under a multiplexed gateway (
multiplex_profiles: true): a job owned by profile X now delivers through profile X's own bot instead of the default profile's bot.Implements the expected behavior from #83182 end-to-end:
Secret scope held through delivery (
cron/scheduler.py) — the job-owning profile's secret scope was previously reset in afinallyaroundrun_jobalone, before_deliver_resultran. Delivery then resolvedTELEGRAM_BOT_TOKENwith no scope active — falling back toos.environ(empty or another profile's value in a multiplex unit). The scope is now installed by therun_one_jobwrapper and reset in the wrapper'sfinally, after the full execute → save → deliver → mark sequence (including the failure-path delivery in the body's outerexcept).Per-profile adapter map for the tick (
cron/scheduler_provider.py) — the multiplex ticker passed the shared default-profile adapter map to every profile'scron_tick. It now resolves each profile's own map via the newprofile_adapterskwarg (_profile_tick_adaptershelper): secondary profiles get_profile_adapters[<name>]; the default profile — and profiles with no secondary adapters — keep the shared map, so single-profile gateways are unchanged.Gateway wiring (
gateway/run.py) —start_gatewaynow passesrunner._profile_adaptersto the cron provider alongside the shared map (additive kwarg; external providers ignore it).Related Issue
Fixes #83182
Type of Change
Changes Made
cron/scheduler.py— move the profile secret-scope install/reset from_run_one_job_body(aroundrun_jobalone) to therun_one_jobwrapper, so the scope spans the entire body including both_deliver_resultcall sitescron/scheduler_provider.py— newprofile_adapterskwarg onInProcessCronScheduler.start/_start_multiplex;_profile_tick_adapters(profile, shared, profile_adapters)resolves each tick's adapter map; the per-profile loop uses itgateway/run.py— passrunner._profile_adapters(when populated) asprofile_adaptersincron_start_kwargsunder multiplextests/cron/test_cron_multiplex_delivery_identity.py— 7 regression tests: scope active at delivery time, scope torn down after completion, per-profile adapter resolution (own / default / unknown / unsupplied), and the multiplex tick passing the profile's own map tocron_tickHow to Test
Unit/regression (repo venv, verified):
E2E reproduction (how the bug was originally observed): on a multiplex gateway with a secondary profile
traderthat owns a Telegram bot token and atelegram:<chat>-delivered cron job in its store, fire the job on the scheduler — before the fix the message arrives from the default profile's bot (visible in the gateway log as a delivery flush keyedagent:main:...); with this PR it arrives from the trader bot's identity, and the log shows the tick's delivery routing through the profile-owned credential. Verified live on a 7-profile multiplex gateway (all scheduled briefings now deliver from their own bots).Checklist
Code
fix(cron):, etc.)pytest tests/ -qand all tests pass (full cron + gateway multiplex suites: 0 new failures vs origin/main baseline; 10 pre-existing environment-dependent failures occur identically on clean origin/main)