feat(agent-builder): log the silent generation/join pipeline failures#1161
Conversation
Diagnosing a prod "agent never joins" report was nearly blind: every terminal failure in the AgentTemplateRepository generation stage (markFailed), the submit/poll retry loops, and the agents/join HTTP outcomes left no trace in device logs. This adds logging across the build -> generate -> provision -> direct-add pipeline so the next repro shows exactly where it died: - AgentTemplateRepository: generation start, status transitions, submit/poll retry errors, backend-reported generation failures, invite start/success, and every markFailed with its message - warn loudly if the raw join fallback (no direct-add) runs outside tests, since it provisions an agent that never joins - ConvosAPIClient: log non-2xx bodies from the generation endpoints and agents/join; log join success with instanceId/inboxId presence - SessionManager: log the provision -> addMembers handoff - behavior fix: 401/403 from generation endpoints are now terminal with the server's message (e.g. "Account required") instead of retrying through the .server path and surfacing a generic "Couldn't reach the builder" Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Claude finished @yewreeka's task —— View job Code Review Complete ✅
SummarySolid observability improvement. The logging additions will dramatically improve debugging of production agent generation failures. The 401/403 behavior fix correctly treats auth failures as terminal instead of retryable. The new test coverage validates the critical behavior change. Minor recommendations below. Strengths
Issues Found1. Logging PII Risk (Minor - Security)Location: The error logging includes the full HTTP response body: Log.error("agents/join failed [\(httpResponse.statusCode)]: \(String(data: data, encoding: .utf8) ?? "nil data")")Concern: If the backend ever includes PII (user prompts, email addresses, names) in error responses, this will log it to device logs, which are uploaded to Sentry and can be pulled from devices. While backend error messages are typically safe, logging raw response bodies is risky. Recommendation: Either:
2. Missing Logging Context (Very Minor - Code Quality)Location: case .server(let message):
Log.error("AgentTemplateRepository: submit server error (attempt \(attempt + 1)/\(Constant.maxSubmitAttempts)): \(message ?? "no message")")Missing the Recommendation: Log.error("AgentTemplateRepository: generation \(row.idempotencyKey) submit server error (attempt \(attempt + 1)/\(Constant.maxSubmitAttempts)): \(message ?? "no message")")Same issue at line 330 (general submit error catch). 3. Test Gap (Minor - Test Coverage)Location: The new test validates Recommendation: Add an integration test that verifies:
(Not blocking - the behavioral change is correct and the unit test validates the error mapping) Performance ConsiderationsNo performance concerns. String interpolation for logging is lazy-evaluated in Swift, and the log volume is reasonable (one log per major state transition, bounded retry attempts). Best Practices✅ Follows project logging conventions ( RecommendationApprove with minor improvements. The PII risk is low but worth addressing. The missing context in error logs is very minor. The test gap is optional. All issues are safe to fix in a follow-up if you want to ship this immediately. |
ApprovabilityVerdict: Approved This PR adds logging throughout the agent generation/join pipeline for debugging, plus a targeted bug fix that makes 401/403 errors fail terminally instead of silently retrying. The behavioral change is a straightforward fix with clear intent, limited scope, and test coverage. You can customize Macroscope's approvability policy. Learn more. |
Why
Diagnosing today's prod "creating a new agent fails" report (logs bundle
convos-logs-BB7ACDAB, 17:56Z attempts) was nearly blind: both failing builds produced zero device-log lines between thebuilt_agentevent and the agent never appearing. Every terminal failure in the generation stage is a silentmarkFailed, the submit/poll retry loops swallow errors, and the generation +agents/joinendpoints skip the response logging every other endpoint gets. The one same-day successful build (15:19Z) was only traceable because its direct-add happened to retry.What
Logging (no behavior change):
AgentTemplateRepository: generation start (idempotencyKey + conversation), status transitions, submit/poll retry errors with attempt counts, backend-reported generation failures with the server's error message, invite start/success, and everymarkFailedwith its messageConvosAPIClient: non-2xx status + body from the generation endpoints andagents/join; join success logsinstanceIdand whetherinboxIdcame back inlineSessionManager: the provision →addMembershandoff (instance, agent inbox, conversation)Behavior fix:
.badRequestcarrying the server's message (e.g. "Account required") instead of the retryable.serverpath, which silently retried 5x and then surfaced a generic "Couldn't reach the builder". A surfaced 401 has already exhausted the re-auth retry insideperformAuthenticatedRequest, so plain retries can't heal it.Tests
badRequestwith the parsed server message; 5xx stays retryable.server🤖 Generated with Claude Code
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Note
Log silent failures in agent generation and join pipeline
AgentTemplateRepositoryandConvosAPIClientto surface previously silent failures during generation start, polling, and invite steps.decodeGenerationResponsetoAgentGenerationError.badRequestwith a parsed message instead of the genericAgentGenerationError.server, so callers can distinguish authorization failures.AgentTemplateRepositoryTestsasserting that 401 and 403 map to.badRequestand 500 maps to.server.AgentGenerationError.serverfor 401/403 responses will now receiveAgentGenerationError.badRequest.Macroscope summarized d374bae.