Skip to content

feat(events)!: Replace CRAWLER_STATUS with STATUS_MESSAGE - #2542

Open
arsalankhan786777 wants to merge 2 commits into
apify:v2from
arsalankhan786777:fix/status-message-event
Open

arsalankhan786777 wants to merge 2 commits into
apify:v2from
arsalankhan786777:fix/status-message-event

Conversation

@arsalankhan786777

@arsalankhan786777 arsalankhan786777 commented Nov 29, 2026 •

Copy link
Copy Markdown

Description

Ports the generic status message event from Crawlee JS v4 (apify/crawlee#3818). Base branch: v2.

  • Event.CRAWLER_STATUS is replaced by Event.STATUS_MESSAGE ('statusMessage', same value as in JS).
  • EventCrawlerStatusData is replaced by EventStatusMessageData with crawler_id, message, is_status_message_terminal and level. Wire names are camelCase (crawlerId, isStatusMessageTerminal), like the JS payload.
  • The periodic status messages go through one _set_status_message helper that logs and emits them. level is the level the message was logged with (INFO). When a status_message_callback returns None, nothing is logged or emitted.
  • When a run finishes, the crawler logs and emits Finished! Total N requests: X succeeded, Y failed. at INFO with is_status_message_terminal=True, like JS. It is sent in the finally around dispatch_requests(), while the event manager is still active and right before the recurring status task is cancelled, so no periodic message follows it.
  • The change is listed in the v2 upgrading guide, and the events and architecture docs use the new names.

Breaking: Event.CRAWLER_STATUS and EventCrawlerStatusData are gone, and there is a new INFO log message at the end of a run, and a status_message_callback that returns None now also suppresses the event. The Apify SDK listens to Event.CRAWLER_STATUS in _actor.py, so it needs a follow-up that switches to STATUS_MESSAGE and forwards is_status_message_terminal.

Issues

Testing

  • Updated test_status_message_emit: periodic events are non-terminal and carry level='INFO'.
  • New test_status_message_terminal_on_finish: the last event of a run (2 succeeded, 1 failed) is the only terminal one and has the expected message and level.
  • New test_status_message_data_wire_names (in tests/unit/events/test_types.py): the model reads and writes the camelCase names.
  • New test_status_message_emit_with_callback: a returned message is emitted at INFO; None emits nothing.
  • Before the change, the new tests fail at import (EventStatusMessageData doesn't exist). After: uv run pytest tests/unit/crawlers/_basic tests/unit/events gives 298 passed, 1 skipped.
  • ruff check, ruff format --check and ty check pass on the touched files.

Written with Claude Code (AI); tested locally with uv run pytest tests/unit/crawlers/_basic, uv run pytest tests/unit/events, uv run ruff check, uv run ruff format --check and uv run ty check.

Checklist

  • CI passed

🤖 Generated with Claude Code

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 29, 2026
@vdusek vdusek changed the title feat(events)!: Replace CRAWLER_STATUS with STATUS_MESSAGE with a terminal flag and level feat(events)!: Replace CRAWLER_STATUS with STATUS_MESSAGE Nov 30, 2026
…terminal flag and level

Port the generic status message event from Crawlee JS v4. The crawler
emits `Event.STATUS_MESSAGE` with `EventStatusMessageData`, which has
`crawler_id`, `message`, `is_status_message_terminal` and `level`. The
periodic status messages go through it, and when a run finishes the
crawler logs and emits a terminal `Finished! Total N requests: X
succeeded, Y failed.` message at INFO, so integrations such as the Apify
SDK can set it as the final status of the run.

BREAKING CHANGE: `Event.CRAWLER_STATUS` and `EventCrawlerStatusData` are
replaced by `Event.STATUS_MESSAGE` and `EventStatusMessageData`. The
crawler logs a new INFO message `Finished! Total N requests: X
succeeded, Y failed.` when a run finishes.

Closes apify#2337

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
self._log_status_message(message, level='INFO')
self._set_status_message(new_message, level='INFO')
else:
self._set_status_message(message, level=None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Question: The status_message_callback docstring says that returning None "suppresses the status message". Here the default message is still emitted, so the Apify SDK would still set it as the run status. In Crawlee JS, the crawler emits nothing when a callback is set. Should we drop this emit, or change the docstring to say that only the log line is suppressed?

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Dropped the emit, so the docstring now holds: on None the update is neither logged nor emitted. The terminal message is still emitted with or without a callback. Note that v2 emitted the default message in this case before this PR too, so I added the change to the upgrading guide. level is now a required LogLevel on the event data, since it is never None.

Written with Claude Code (AI).



async def test_status_message_terminal_on_finish() -> None:
"""The last `STATUS_MESSAGE` event of a run is a terminal summary of the finished requests."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Please add a test for the callback paths: level='INFO' when the callback returns a message, and level=None when it returns None.

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added test_status_message_emit_with_callback: a returned message is emitted with level='INFO'. Since None no longer emits, that case asserts there is no event.

Written with Claude Code (AI).


events = [call.args[0] for call in status_message_listener.call_args_list]
terminal_events = [event for event in events if event.is_status_message_terminal]
assert terminal_events == [events[-1]]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggestion: EventManager runs sync listeners through asyncio.to_thread, so the Mock call order is not guaranteed to match the emit order. An async def listener keeps the order fixed. The same applies to call_args_list[0] in test_status_message_emit.

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, both tests now use an async def listener.

Written with Claude Code (AI).

# message can follow the terminal one.
state = self._statistics.state
total = state.requests_finished + state.requests_failed
self._set_status_message(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Finished! ... is logged before Error analysis, The crawl was interrupted... and Final request statistics. In Crawlee JS it is the last line. After Ctrl+C, the log says "Finished!" and then "interrupted". Fine to keep if emitting later is not practical.

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'd keep it here. The Error analysis, interrupted and final statistics lines are logged in run(), after _run_crawler has exited the event manager, where emit raises unless someone else keeps it active. Moving the message there would mean restructuring how the contexts are entered.

Written with Claude Code (AI).

self,
message: str,
*,
level: LogLevel | None = 'DEBUG',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: No caller uses the 'DEBUG' default. level can be a required keyword argument.

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Written with Claude Code (AI).

Comment thread src/crawlee/events/_types.py Outdated
message: str
"""A message describing the current status of the crawler."""

is_status_message_terminal: bool | None = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: The crawler never emits False here, so bool = False would be simpler for consumers than bool | None. Fine to keep if you want to match the optional JS field.

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, in the model and in _set_status_message; the upgrading guide says False for periodic messages now.

Written with Claude Code (AI).

)


async def test_status_message_data_wire_names() -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: This test has no await, so it can be a sync def. It tests only the model, so tests/unit/events/ fits it better.

✍️ Drafted by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, it is a sync test in tests/unit/events/test_types.py now.

Written with Claude Code (AI).

…s `None`

Address the review of the `STATUS_MESSAGE` event. A
`status_message_callback` that returns `None` now suppresses the event as
well as the log line, as its docstring says. `level` is therefore always
set, and `is_status_message_terminal` defaults to `False`.

BREAKING CHANGE: No status event is emitted when `status_message_callback`
returns `None`.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

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

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants