Skip to content

Fallback agent client#2072

Merged
Litarnus merged 8 commits intomasterfrom
fallback-agent-client
Apr 28, 2026
Merged

Fallback agent client#2072
Litarnus merged 8 commits intomasterfrom
fallback-agent-client

Conversation

@Litarnus
Copy link
Copy Markdown
Contributor

Extends the AgentClient so that it can receive a fallback client in case the agent is unavailable. The fallback client is constructed through a factory to allow frameworks and other processes to set the necessary information.

Comment thread src/Agent/Transport/AgentClient.php
Comment thread src/Agent/Transport/AgentClient.php
Comment thread src/Agent/Transport/AgentClient.php
Comment thread src/Agent/Transport/AgentClient.php Outdated
$socket = $this->socket;
$payloadLength = \strlen($payload);
$totalWrittenBytes = 0;
$writeDeadline = microtime(true) + self::SOCKET_TIMEOUT_SECONDS;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The fixed 10ms write timeout in writePayload is likely insufficient for large payloads, causing unnecessary fallbacks to the HTTP transport even with a healthy agent.
Severity: MEDIUM

Suggested Fix

Introduce a separate, more generous timeout for the payload writing operation. Alternatively, make the write timeout configurable or calculate it dynamically based on the payload size to ensure sufficient time is allocated for large data transfers without affecting the quick connection timeout.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Agent/Transport/AgentClient.php#L149

Potential issue: The `AgentClient` uses the same 10ms timeout (`SOCKET_TIMEOUT_SECONDS`)
for both the initial socket connection and for writing the entire payload in
`writePayload`. For large payloads, such as events with attachments, or when the agent
is under load, the non-blocking write operation may require multiple iterations that
collectively take longer than 10ms. This will cause the write to fail and trigger a
fallback to the standard HTTP transport, even if the agent is healthy and capable of
receiving the data. This leads to inefficient transport usage in certain valid
scenarios.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Attachments is a good point, maybe we should have an attachment and non attachment path

@Litarnus Litarnus merged commit be76fb7 into master Apr 28, 2026
46 checks passed
@Litarnus Litarnus deleted the fallback-agent-client branch April 28, 2026 12:24
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.

2 participants