Skip to content

fix(activity:log): drop stray query params from log stream URL#56

Merged
miguelsanchez-upsun merged 2 commits intomainfrom
fix/activity-log-count-param
Apr 29, 2026
Merged

fix(activity:log): drop stray query params from log stream URL#56
miguelsanchez-upsun merged 2 commits intomainfrom
fix/activity-log-count-param

Conversation

@pjcdawkins
Copy link
Copy Markdown
Contributor

Summary

When activity:log (or any waited activity) opens its log stream, the URL it fopens comes from Platformsh\Client\Model\Activity::getLink('log'). The client library's ApiResourceBase::makeAbsoluteUrl() resolves the relative log link against the activity's base URL by swapping in the relative target's path, but keeps the base's query string. So when the activity was loaded via /projects/<id>/activities?count=1 (e.g. --all, or any default-activity selection), the resulting log URL is .../activities/<id>/log?count=1.

The log endpoint rejects count with HTTP 400. Without verbose mode the fopen warning is hidden, but the streaming retry loop in ActivityMonitor::getLogStream() still spins until its 2-minute timeout. With -vv, the user sees a flood of Warning: fopen(...): Failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request.

This PR works around the issue in the legacy CLI by stripping the query string from the log URL before opening the stream. The non-streaming Activity::readLog() path goes through Guzzle with the query request option, which already replaces the URL's query string, and is unaffected.

A second commit fixes a long-standing operator-precedence bug in the same retry loop: (int) $interval * 1000000 evaluated as ((int) 0.5) * 1000000 = 0, so usleep(0) was called instead of the intended 0.5-second sleep, causing the loop to spin as fast as PHP could re-issue fopen on the failing endpoint. Wrapping the multiplication in parentheses restores the intended delay.

The underlying link-resolution bug should also be fixed upstream in platformsh-client-php; that's tracked separately.

pjcdawkins and others added 2 commits April 29, 2026 09:47
The activity log link, resolved via Platformsh\Client\Model\Activity::getLink('log'),
inherits the query string of the base URL the activity was loaded with. When the
activity collection is fetched with a 'count' parameter, that parameter is carried
into the absolute log URL by ApiResourceBase::makeAbsoluteUrl(), which only swaps
the path. The log endpoint rejects 'count' with HTTP 400, producing repeated fopen
warnings in verbose mode and breaking the streaming retry loop.

Strip the query string before opening the stream. The non-streaming readLog() path
(Activity::fetchLog -> Guzzle 'query' option) already replaces the query string and
is unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Operator precedence made (int) $interval * 1000000 evaluate as ((int) 0.5) * 1000000,
so the retry loop in getLogStream() called usleep(0) and spun as fast as PHP could
re-issue fopen on a failing log endpoint. Wrap the multiplication in parentheses so
the intended 500000 microsecond delay is applied.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 29, 2026 08:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes log streaming for activity:log (and other waited activities) in the legacy CLI by ensuring the log stream URL does not include inherited query parameters that the log endpoint rejects, and by correcting a retry-loop sleep timing bug that caused rapid spinning on failure.

Changes:

  • Strip any query string from the activity log stream URL before opening the stream (avoids HTTP 400 due to inherited params like count).
  • Fix operator precedence in the retry loop so usleep() waits the intended 0.5 seconds between retries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@miguelsanchez-upsun miguelsanchez-upsun merged commit 0ddb9d6 into main Apr 29, 2026
8 checks passed
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.

3 participants