Skip to content

fix(cosh): set run_id before UserPromptSubmit hook fires#537

Merged
samchu-zsl merged 1 commit into
alibaba:mainfrom
kongche-jbw:fix/cosh/user-prompt-submit-run-id
May 15, 2026
Merged

fix(cosh): set run_id before UserPromptSubmit hook fires#537
samchu-zsl merged 1 commit into
alibaba:mainfrom
kongche-jbw:fix/cosh/user-prompt-submit-run-id

Conversation

@kongche-jbw
Copy link
Copy Markdown
Collaborator

Description

UserPromptSubmit hook input was carrying a stale run_id (or undefined
on the very first prompt). GeminiClient.sendMessageStream() used to fire
the hook through messageBus.request BEFORE calling
config.setCurrentRunId(prompt_id), so when
hookEventHandler.createBaseInput() read config.getCurrentRunId() it
saw the previous prompt's value.

Fix:

  • Promote setCurrentRunId(prompt_id) to run right after the
    isContinuation guard, before any UserPromptSubmit hook activity.
  • Remove the now-duplicate setCurrentRunId from the later non-continuation
    initialization block.
  • Continuations (tool-result follow-ups, Stop hook, next-speaker
    Please continue.) still skip the call so they keep the original
    prompt's run_id, consistent with the [cosh] bug: UserPromptSubmit Hook 在单次prompt 运行过程中会被调用多次 #530 fix.

recordUserMessage and stripThoughtsFromHistory are intentionally NOT
moved earlier — block / ask / additionalContext semantics on
UserPromptSubmit must keep working.

Related Issue

closes #531

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional change)
  • Performance improvement
  • CI/CD or build changes

Scope

  • cosh (copilot-shell)
  • sec-core (agent-sec-core)
  • skill (os-skills)
  • sight (agentsight)
  • tokenless (tokenless)
  • Multiple / Project-wide

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • For cosh: Lint passes, type check passes, and tests pass
  • For sec-core (Rust): cargo clippy -- -D warnings and cargo fmt --check pass
  • For sec-core (Python): Ruff format and pytest pass
  • For skill: Skill directory structure is valid and shell scripts pass syntax check
  • For sight: cargo clippy -- -D warnings and cargo fmt --check pass
  • For tokenless: cargo clippy -- -D warnings and cargo fmt --check pass
  • Lock files are up to date (package-lock.json / Cargo.lock)

Testing

Three new regression tests in
src/core/client.test.ts → sendMessageStream → UserPromptSubmit hook firing semantics:

  1. sets currentRunId before firing UserPromptSubmit so hook input has the right run_id
    Uses invocationCallOrder to assert setCurrentRunId(prompt_id) runs
    before the UserPromptSubmit request hits the bus.
  2. exposes the current run_id to hook handlers at UserPromptSubmit request time
    Links setCurrentRunId / getCurrentRunId and has the bus subscriber
    capture getCurrentRunId() exactly as createBaseInput() would,
    asserting the captured id equals the prompt id.
  3. keeps the original run_id during a continuation call — Pre-seeds the
    run id, calls with { isContinuation: true }, asserts
    setCurrentRunId is not invoked and the run id is untouched.

Commands run:

cd src/copilot-shell && npm run test --workspace=packages/core -- src/core/client.test.ts
# 56/56 tests pass

Additional Notes

Only client.ts and client.test.ts are changed. No dist/,
coverage/, package.json, or package-lock.json modifications.
This stacks on top of the #530 fix as
0764474 fix(cosh): fire UserPromptSubmit hook only on real user prompts.

    - 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
@kongche-jbw kongche-jbw self-assigned this May 15, 2026
@kongche-jbw kongche-jbw requested a review from samchu-zsl as a code owner May 15, 2026 03:18
@kongche-jbw kongche-jbw added the component:cosh src/copilot-shell/ label May 15, 2026
Copy link
Copy Markdown
Collaborator

@samchu-zsl samchu-zsl left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@samchu-zsl samchu-zsl merged commit c05d88b into alibaba:main May 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh src/copilot-shell/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cosh] bug: UserPromptSubmit Hook 中拿不到正确的runId

2 participants