Repository navigation
fix(agent-core-v2): rebuild hook index on config change so late [[hooks]] fire - #2822
SnowingFox wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: d1b469d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1511ef5a9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (this.config.onDidChangeConfiguration !== undefined) { | ||
| this._register( | ||
| this.config.onDidChangeConfiguration(() => { | ||
| void this.reloadSafe(); |
There was a problem hiding this comment.
Await config-change reloads before firing hooks
When a config change is immediately followed by a hook trigger, such as startup loading [[hooks]] and then creating a session that fires SessionStart, this fire-and-forget reload can still be pending: load() yields on config.ready and again on plugins.enabledHooks(), while triggerInner() only waits for the original constructor ready promise. The trigger can therefore read the old empty byEvent and skip the very hook this change is meant to pick up; serialize the current reload into a promise that triggers wait for, or otherwise rebuild the index before the change path returns.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Rebased onto main (4965757). Config-change and plugin reloads now go through one reloadChain promise that triggerInner awaits, so a trigger right after a change reads the new index. The regression test now calls trigger() straight after firing the change, with no waitFor.
| // Rebuild the hook index when the config changes, not just on plugin | ||
| // reload. The user config file (`config.toml`) can be (re)loaded into the | ||
| // layered config service after this runner's initial `loadSafe()` — in the | ||
| // interactive TUI in particular, `[[hooks]]` may arrive late. Without this | ||
| // subscription the index would stay empty forever and every hook would |
There was a problem hiding this comment.
Move inline implementation notes into the header
This package's AGENTS.md requires comments to live solely in the top-of-file header block, never beside methods or statements. This new constructor comment is an inline implementation narrative, so it violates the scoped convention; please fold any durable rationale into the file header or remove it.
AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L36-L38
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Removed all comments from the change. agent-core-v2 is now a comment-free package, and check-no-comments passes.
…s are not missed Address codex P1 review comments on MoonshotAI#2822: fold the config-change rationale into the file header (AGENTS.md header-only comment convention) and serialize reloads into a promise chain that triggerInner awaits, so a hook trigger that lands right after a config change reads the rebuilt index instead of the stale empty one.
…ks]] fire Fixes MoonshotAI#2779. ExternalHooksRunnerService built its event index once at construction and only rebuilt it on plugin reload, so [[hooks]] loaded into the config later never fired. Rebuild on config change too, and serialize rebuilds so a trigger right after a change waits for the new index. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: SnowingFox <[email protected]>
9c29837 to
4965757
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49657577f4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Rebuild the external-hook index when the config changes so `[[hooks]]` that arrive after engine construction (e.g. the interactive TUI loading config.toml) fire instead of silently never running. |
There was a problem hiding this comment.
Keep the changeset user-facing and concise
The release-note sentence names the internal external-hook index and engine construction mechanism and appends a long explanatory clause. This repository requires changesets to be one short, user-facing sentence stating only what changed, so reduce this entry to the observable fix (for example, “Run configured external hooks after config reloads.”) before it is included in the generated changelog.
AGENTS.md reference: AGENTS.md:L89-L90
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Fixes #2779. On 0.34.0 the interactive TUI can silently run zero configured
[[hooks]](SessionStart / UserPromptSubmit / SessionHeartbeat), whilekimi -pon the sameconfig.tomlfires them. The engine gives no warning — the hooks "just never run" — matching the reporter's macOS repro.Root cause
ExternalHooksRunnerService(App scope) builds its event→hooks index exactly once, inloadSafe()at construction, and only ever rebuilds it onplugin.onDidReload. The user config file (config.toml) is (re)loaded into the layeredIConfigServiceasynchronously — in the interactive TUI the[[hooks]]section can arrive after this runner's one-shot index is built. BecauseloadSafe()/trigger()swallow errors andhasHooksFor()falls back to an empty index, every trigger silently returns[]and no hook ever fires, with no diagnostic.This is distinct from #2766 / PR #2772, which address the separate hook-spawn-failure path (logging). This PR targets the hooks-not-firing-at-all load path.
Fix
Subscribe
ExternalHooksRunnerServicetoIConfigService.onDidChangeConfigurationand re-runload()— the same rebuild the plugin-reload path already uses — so a hooks section that is present in, or (re)loaded into, the config is picked up instead of being permanently missed. A member check keeps the subscription a no-op against partialIConfigServicestubs in unit tests.Test
New regression test in
packages/agent-core-v2/test/app/externalHooksRunner/externalHooksRunner.test.ts: builds a runner whose config initially has no hooks, then delivers aSessionStarthook through a config-change event and assertshasHooksFor('SessionStart')becomes true and the hook fires. It fails on the pre-fix code (index never rebuilt) and passes after.Fixes #2779