Skip to content

refactor(architecture): Processes dispatches its own task terminal event - #10997

Open
rubenvdlinde wants to merge 1 commit into
mainfrom
cloud/mod-X96-task-terminal-event
Open

rubenvdlinde wants to merge 1 commit into
mainfrom
cloud/mod-X96-task-terminal-event

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Package X96 (round 14, kernel.md K5-04, key K-task-terminal)

Processes dispatches its own task terminal event.

What changed and why this is the right dependency

  • lib/Db/TaskMapper.php (Processes) dispatches TaskTerminalEvent through IEventDispatcher at the same point as before (the private announceTerminality(), called from update() and from a winning updateIfOpen()), with the same committed: false, instead of calling EntityEventsInterface::taskTerminal(). The optional ?EntityEventsInterface $entityEvents constructor dependency becomes an optional ?IEventDispatcher $dispatcher. The mapper is autowired (no registrar builds it), so the container now injects the Nextcloud dispatcher. Without a dispatcher it is still constructible and stays silent.
  • taskTerminal() leaves lib/Kernel/Contracts/EntityEventsInterface.php and lib/Service/Registers/EntityEventPublisher.php. A GitHub code search across the org finds no fleet app that names EntityEventsInterface or builds TaskMapper. The publisher no longer imports TaskTerminalEvent or TaskInterface.
  • csv rows: Event/TaskTerminalEvent.php and Event/AbstractTaskEvent.php go from Kernel to Processes. Processes is the only area that dispatches the event, and the payload is its own task. The class name, namespace and payload stay the same, so the 7 fleet apps that listen are unaffected. sigrid.components.yaml and tools/sig/deptrac/areas.yaml were regenerated.

Behaviour stays the same: the dispatch is synchronous at the same point, a non-terminal task, a lost conditional update and insert() still dispatch nothing, and the event is the same class with the same payload. No listener was added or removed, so the listener order pins do not move.

Re-measured on fresh main (e158c36a)

  • refactor(architecture): the task terminal event carries the Kernel task contract #10921 (the task terminal event carries the Kernel task contract) has already landed. TaskTerminalEvent takes TaskInterface, and the publisher narrowed to TaskInterface. That means the 4 references against the order the design counted for K5-04 (EntityEventPublisher → Db/Task and the Kernel task event pairs) were already gone before this PR. They do not appear in modularity_check.py's against_order list on main. What this PR still achieves is the exposure move and the removal of the Core → task event dependency.

Exposed lines per area (measure()['exposed_loc'])

Area Before After Δ
Kernel 6,027 5,989 −38
Core 35,024 35,024 0
Notifications 1,760 1,760 0
Search 1,349 1,349 0
Compliance 14,300 14,300 0
Files 1,263 1,263 0
Integrations 17,689 17,689 0
Processes 27,041 27,042 +1 (TaskMapper, already exposed, gained one import line)
Configuration 874 874 0
Platform 0 0 0
Total 105,327 105,290 −37

Expected from the package file: Kernel −24 (5,984 → 5,960). Measured: Kernel −38, total −37. AbstractTaskEvent and TaskTerminalEvent are no longer exposed at all, because every file that names them now counts to Processes.

  • References against the order: 37 before, 37 after (none added; the task-event ones were already gone, see above).
  • Newly exposed files: none. New Kernel files: none (2 Kernel files leave: the two events).
  • tools/sig/deptrac.sh areas --check: 38 class pairs in violation, the same as on main. The "852 gone" note prints on main too.
  • rate_component_views.py requires a --report input that this checkout does not have, so it was not run.

Baseline (tools/sig/modularity-baseline.json, re-recorded with --write-baseline as the routine instructs)

  • exposed_files: lib/Event/AbstractTaskEvent.php and lib/Event/TaskTerminalEvent.php removed (no longer named by another area).
  • kernel_files: the same two removed (they now count to Processes).
  • exposed_loc: Kernel 6,027 → 5,989, Processes 27,041 → 27,042. kernel_loc 7,631 → 7,593, total_loc 462,400 → 462,395.
  • tools/sig/deptrac/areas.baseline.json was not touched.

Tests

  • New golden test TaskMapperTerminalityTest::testATerminalUpdateDispatchesExactlyOneTerminalEventWithTheTaskUncommitted: one terminal update() dispatches exactly one TaskTerminalEvent (via dispatchTyped, never dispatch), carrying the persisted task and committed: false.
  • TaskMapperTerminalityTest and MapperEntityEventsTest now build the mapper with the dispatcher. The recorded event sequence and payload (committed: false, the given task) are unchanged.
  • tests/Unit/Kernel/EntityEventsBindingTest.php (outside the package's file list, changed because this change needs it; no other round-14 package lists it): the two publisher taskTerminal tests were removed with the method. Their refusal of a non-task entity is still covered by TaskMapper::update(), which throws InvalidArgumentException for anything that is not a Task. TaskMapper.php was also added to DB_NAMING_EVENTS, the list of lib/Db files that name a lib/Event class. That list was documented as "only shrinks". The design deliberately makes TaskMapper name its own area's event, so the docblock now states that exception. Flagged for the reviewer.

What ran

  • php -l on every changed file: clean.
  • vendor/bin/phpcs on the three changed lib files: clean.
  • vendor/bin/phpstan analyse --no-progress on all of lib: 38 errors, identical to main (none in a touched file). On the three changed files alone: no errors. phpstan was installed by fetching the locked commit from github.com/phpstan/phpstan into the composer cache, because the proxy blocks the api.github.com zipball.
  • vendor/bin/psalm --no-cache on the three changed lib files: no errors (46 info issues, the same as on main).
  • python3 tools/sig/modularity_check.py --check: passed.
  • tools/sig/deptrac.sh areas --check: passed.
  • vendor/bin/phpunit -c phpunit.xml --no-coverage tests/Unit/Architecture: OK (2,378 tests).
  • All of tests/Unit, per directory. Every failure below also fails on main without this change:
    • Db/AreaMapperRegistrarsTest::testEachInterfaceIsBoundOnce (the Translation mapper interfaces are bound twice).
    • 9 errors in Middleware/AnonymousEnvelopeReadPathsTest and Migration/ReservedColumnNamesTest (an ObjectsControllerFactory argument mismatch, then reserved-word lists).
    • 5 failures in Service/Chat/ResponseGenerationGoldenTest.
    • Everything else passes: Db/Kernel/Event/Listener/Service/Task 8,675 tests, Controller 10,321, Service 36,407, other directories 6,478.

Written with Claude Code (claude-opus-5-5)


Generated by Claude Code

TaskMapper now dispatches TaskTerminalEvent through IEventDispatcher at the
same point (both update() and a winning updateIfOpen()), with the same
committed: false, instead of calling EntityEventsInterface::taskTerminal().
The method leaves EntityEventsInterface and EntityEventPublisher (no fleet
app names the interface), so Core no longer names a Processes event, and
Event/TaskTerminalEvent and Event/AbstractTaskEvent count to Processes.

A golden test pins that a terminal update dispatches exactly one
TaskTerminalEvent carrying the persisted task and committed: false.

Assisted-by: ClaudeCode:claude-opus-5-5
@rubenvdlinde
rubenvdlinde requested a review from a team as a code owner November 21, 2026 19:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant