fix(credits): keep cold-start account seed in the session profile - #113595
Open
poijygfdyy wants to merge 2 commits into
Open
poijygfdyy wants to merge 2 commits into
poijygfdyy wants to merge 2 commits into
Conversation
poijygfdyy
marked this pull request as ready for review
September 16, 2026 23:41
Contributor
@rob-maron Tagging you on this credits-notice item as the soft maintainer (follow-up to #43669). |
This branch has not been deployed
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.
Invariant
A session-open credits seed must read the Nous account under the same routed profile context that owns the agent being hydrated. A fire-and-forget seed thread must not fall back to the process-launch
HERMES_HOME/ auth state.Current-main RED
Current
main(260da4ef6251b29aa830c8c949dbe7c92d58df5f) starts the cold-start portal lookup as a bare daemon thread:HERMES_HOMErouting is context-local. A freshthreading.Threadstarts with an emptyContext, so a served profile can enterseed_credits_at_session_start()under its own profile and then perform the account lookup under the launch profile instead.The regression commit sets process
HERMES_HOMEto a launch home, binds a different served-profile override around the realseed_credits_at_session_start()call, replaces only the portal network lookup with a deterministic local fake, waits for the real background thread to finish, and asserts the lookup observed the served home. On current main that assertion is RED: the bare worker observes the launch home.A standalone
ContextVar/real-thread probe also reproduces the mechanism deterministically: caller=served, bare child thread=launch.Fix
Capture the caller's full
contextvars.Contextat the existing spawn boundary and execute the unchanged_bg_seedbody inside it:This matches the repository's existing profile-sensitive background-thread pattern. It changes no account mapping, notice policy, retry behavior, session lifecycle, or portal API behavior.
Collision audit
Re-ran mechanism-level collision checks immediately before marking this ready: current/recent PRs, issues, commits, exact function name,
credits-seed,agent/credits_tracker.py, profile/context propagation, and account-lookup call sites.mainis still260da4ef6251b29aa830c8c949dbe7c92d58df5f; the affected source has not moved since discovery.seed_credits_at_session_start()/ thecredits-seedthread.agent/credits_tracker.pyresidual: a served-profile agent can hydrate credit state from the launch profile's account. It did not modify this path.Final diff
agent/credits_tracker.py: importcontextvarsand wrap the one existing background-thread hop in the copied caller Context.tests/agent/test_credits_seed_profile_scope.py: deterministic real-thread regression for launch-home vs served-profile routing.No unrelated runtime behavior is included.
Validation
seed_credits_at_session_start()spawn path; only the remote portal lookup is replaced with a local deterministic fake.contextvars.copy_context().runthread-hop pattern.26565332206fee4b86a9c627dc748438f6c3126bare currentlyaction_required; the jobs did not execute behind the external-contributor approval gate, so CI is not claimed as passing.