fix(cosh): set run_id before UserPromptSubmit hook fires#537
Merged
samchu-zsl merged 1 commit intoMay 15, 2026
Merged
Conversation
- call setCurrentRunId before messageBus UserPromptSubmit request
- drop duplicate setCurrentRunId from later non-continuation block
- keep run_id intact across tool/Stop/next-speaker continuations
- cover ordering and hook-input run_id with regression tests
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.
Description
UserPromptSubmithook input was carrying a stalerun_id(orundefinedon the very first prompt).
GeminiClient.sendMessageStream()used to firethe hook through
messageBus.requestBEFORE callingconfig.setCurrentRunId(prompt_id), so whenhookEventHandler.createBaseInput()readconfig.getCurrentRunId()itsaw the previous prompt's value.
Fix:
setCurrentRunId(prompt_id)to run right after theisContinuationguard, before anyUserPromptSubmithook activity.setCurrentRunIdfrom the later non-continuationinitialization block.
Please continue.) still skip the call so they keep the originalprompt's run_id, consistent with the [cosh] bug: UserPromptSubmit Hook 在单次prompt 运行过程中会被调用多次 #530 fix.
recordUserMessageandstripThoughtsFromHistoryare intentionally NOTmoved earlier — block / ask / additionalContext semantics on
UserPromptSubmitmust keep working.Related Issue
closes #531
Type of Change
Scope
cosh(copilot-shell)sec-core(agent-sec-core)skill(os-skills)sight(agentsight)tokenless(tokenless)Checklist
cosh: Lint passes, type check passes, and tests passsec-core(Rust):cargo clippy -- -D warningsandcargo fmt --checkpasssec-core(Python): Ruff format and pytest passskill: Skill directory structure is valid and shell scripts pass syntax checksight:cargo clippy -- -D warningsandcargo fmt --checkpasstokenless:cargo clippy -- -D warningsandcargo fmt --checkpasspackage-lock.json/Cargo.lock)Testing
Three new regression tests in
src/core/client.test.ts → sendMessageStream → UserPromptSubmit hook firing semantics:sets currentRunId before firing UserPromptSubmit so hook input has the right run_id—Uses
invocationCallOrderto assertsetCurrentRunId(prompt_id)runsbefore the
UserPromptSubmitrequest hits the bus.exposes the current run_id to hook handlers at UserPromptSubmit request time—Links
setCurrentRunId/getCurrentRunIdand has the bus subscribercapture
getCurrentRunId()exactly ascreateBaseInput()would,asserting the captured id equals the prompt id.
keeps the original run_id during a continuation call— Pre-seeds therun id, calls with
{ isContinuation: true }, assertssetCurrentRunIdis not invoked and the run id is untouched.Commands run:
Additional Notes
Only
client.tsandclient.test.tsare changed. Nodist/,coverage/,package.json, orpackage-lock.jsonmodifications.This stacks on top of the #530 fix as
0764474 fix(cosh): fire UserPromptSubmit hook only on real user prompts.