Skip to content

[Bug]: Event refresh silently overwrites a modified .specify/events.py #5618

Backlog

Description

@markuswondrak

Bug Description

When Spec Kit writes the shared event dispatcher .specify/events.py, it does not check who owns the file or whether it was modified. install_integration_events always rewrites it from the template (src/specify_cli/events/__init__.py, dispatcher step "1. Generate events.py dispatcher script").

Removal checks both. _cleanup_shared_dispatcher deletes the file only when the departing integration's manifest records it and no other installed integration references it. It preserves a modified dispatcher with a warning unless --force is given, and preserves an unowned one even with --force (design/integration.md, event cleanup). The shared scripts and templates use the same guard when they are refreshed (shared_infra.py, refresh_managed): a file whose hash no longer matches the manifest is kept with a warning, and --force overwrites it.

So a modified dispatcher survives an uninstall, but is silently overwritten by every write path that reaches install_integration_events without the upgrade command's own check_modified() guard. For example, the event refresh after specify extension add or remove overwrites it.

Found during review of #5616, where the finding was deferred. That PR installs a built-in session_start handler for Copilot, so this write path now runs on every Copilot init and upgrade (review comment: #5616 (comment)).

Steps to Reproduce

Run on main at f2010547, Linux:

  1. specify init . --integration claude --script sh --ignore-agent-tools
  2. Give Claude any event handler, for example with .specify/integration-events.yml (integrations.claude.events.session_start.command: speckit.plan), then run specify integration upgrade claude. .specify/events.py is created and recorded in claude.manifest.json.
  3. Append # user customization to .specify/events.py.
  4. specify integration upgrade claude refuses, saying the file was modified (protected by upgrade's check_modified()).
  5. Remove the override, and add a local extension that declares events: {session_start: {command: speckit.evt.hello}} with specify extension add --dev <path>.
  6. grep "user customization" .specify/events.py: no match. The file was regenerated without any warning.

Expected Behavior

Writes use the same ownership rules as removal and as shared infra refresh:

  • An unchanged, Spec Kit-owned dispatcher is regenerated silently.
  • A modified or unowned dispatcher is preserved with a warning that names the remedy, and is overwritten only with --force.

Because the dispatcher and the native hook commands are generated together, a preserved stale dispatcher needs clear reporting. Hooks written by a newer Spec Kit may pass arguments that an older dispatcher does not understand.

Actual Behavior

install_integration_events overwrites .specify/events.py unconditionally on init, install, upgrade (after the integration's own manifest check), and on the event refresh after extension add or remove.

Specify CLI Version

1.4.6.dev0 (main at f2010547)

AI Agent

Not agent-specific; reproduced with Claude Code (claude) and GitHub Copilot (copilot) integrations.

Operating System

Linux

Python Version

3.14

Additional Context

Pre-existing on main, independent of #5533 and #5616. Write-side ownership affects the event lifecycle of every event-capable integration, so it is tracked separately rather than fixed in #5616.

AI Disclosure

Filed on behalf of @markuswondrak by the pi coding agent (provider github-copilot, model claude-opus-5.5, reasoning effort xhigh, interactive and human-supervised). The agent read the code, reproduced the behavior on main with the steps above, and wrote this issue at @markuswondrak's request.

Activity

  1. added
    triage-must-have
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage-must-have

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions