Repository navigation
fix: unable to get prologue in agent bot - #17299
Conversation
📝 WalkthroughWalkthroughThe change migrates DSL extraction from top-level fields to ChangesDSL params migration
Bot authentication and log routing
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant BetaAuthMiddleware
participant TokenResolver
participant GetAgentbotLogs
participant Redis
Client->>BetaAuthMiddleware: send beta authorization
BetaAuthMiddleware->>TokenResolver: resolve user and bound agent_id
TokenResolver-->>BetaAuthMiddleware: return user and agent_id
Client->>GetAgentbotLogs: provide route agent_id and message_id
GetAgentbotLogs->>GetAgentbotLogs: compare route and bound agent_id
GetAgentbotLogs->>Redis: read agentbot logs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
not now |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/agent/dsl/extract.go (1)
187-205: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDo not turn malformed nested params into successful empty values.
Both extractors discard the type-assertion result. A non-map
obj.params, or non-stringprologue/mode, returns("", nil)and prevents callers from distinguishing malformed DSL from an intentionally absent optional value. Validateparamsand present scalar values, returningErrMalformedDSLfor invalid types.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/dsl/extract.go` around lines 187 - 205, Update the prologue extractor and ExtractMode to validate the obj and params type assertions instead of ignoring their success flags. Return ErrMalformedDSL when params is not a map or when a present prologue/mode value is not a string, while preserving the successful empty result for genuinely absent optional fields.
🧹 Nitpick comments (1)
internal/agent/dsl/extract.go (1)
27-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove Python implementation-history from this Go doc.
Keep the current raw DSL path and error contract; lines 29-33 describe Python internals/private
_paraminitialization rather than this function’s runtime behavior.As per coding guidelines, “keep package and documentation comments aligned with the current runtime path rather than migration history” and “Remove … stale documentation.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/dsl/extract.go` around lines 27 - 41, Remove the Python implementation-history comments from the documentation for the component input-form extraction function, including the Canvas, Begin component, and private _param initialization references. Retain the current raw DSL path and the documented return values and error contract.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/handler/auth.go`:
- Around line 98-102: Bind beta credentials to their authoritative agent during
the beta resolver flow in internal/handler/auth.go lines 98-102, exposing that
binding through the authentication context or resolver contract. In
internal/handler/bot.go lines 271-273, compare the requested route agent_id
against the bound agent and reject mismatches before constructing the Redis key;
add coverage proving cross-agent log requests are denied.
In `@internal/handler/bot_test.go`:
- Line 787: Restore context.Context parameters across the callback fields and
stub methods used by AuthHandler, including getUserByTokenFn and the related
methods at the referenced sections, so they satisfy userTokenResolver. Update
the inline middleware invocation to pass c.Request.Context() when calling the
resolver.
In `@internal/handler/bot.go`:
- Around line 259-265: Update the endpoint comment associated with
GetAgentbotLogs to remove the “Mirrors python bot_api.py:agent_bot_logs”
migration-history reference, while preserving the current behavior and
authentication details documented above it.
---
Outside diff comments:
In `@internal/agent/dsl/extract.go`:
- Around line 187-205: Update the prologue extractor and ExtractMode to validate
the obj and params type assertions instead of ignoring their success flags.
Return ErrMalformedDSL when params is not a map or when a present prologue/mode
value is not a string, while preserving the successful empty result for
genuinely absent optional fields.
---
Nitpick comments:
In `@internal/agent/dsl/extract.go`:
- Around line 27-41: Remove the Python implementation-history comments from the
documentation for the component input-form extraction function, including the
Canvas, Begin component, and private _param initialization references. Retain
the current raw DSL path and the documented return values and error contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9290fcc1-5540-4fa0-91db-ae724ef852c0
📒 Files selected for processing (9)
internal/agent/dsl/errors.gointernal/agent/dsl/extract.gointernal/agent/dsl/extract_test.gointernal/handler/agent_component.gointernal/handler/agent_component_test.gointernal/handler/auth.gointernal/handler/bot.gointernal/handler/bot_test.gointernal/service/bot_completion_history_test.go
| // GetAgentbotLogs GET /api/v1/agentbots/<agent_id>/logs/<message_id> | ||
| // | ||
| // Beta-token sibling of GetAgentLogs. The shared/embedded chat | ||
| // page's "Thinking" button hits this endpoint because the share | ||
| // flow authenticates with a beta APIToken (no session JWT) and | ||
| // the regular /api/v1/agents/<id>/logs/<msg> requires @login_required. | ||
| // Mirrors python bot_api.py:agent_bot_logs (PR #15238). | ||
| // | ||
| // The <shared_id> path segment is the value the client passed in | ||
| // the URL (typically the beta token in the share flow); the real | ||
| // agent_id used to build the Redis key | ||
| // (`<agent_id>-<message_id>-logs`) is read from the APIToken | ||
| // looked up by the beta middleware and stashed in the gin | ||
| // context as "agent_id". The endpoint never trusts the URL | ||
| // segment for the data lookup — using the middleware-resolved | ||
| // agent_id prevents a probe that swaps a victim's shared_id to | ||
| // read another agent's logs. | ||
| // Mirrors python bot_api.py:agent_bot_logs. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove the migration-history reference from this endpoint comment.
Mirrors python bot_api.py:agent_bot_logs does not describe the current Go runtime behavior and will drift independently.
As per coding guidelines, “keep package and documentation comments aligned with the current runtime path rather than migration history.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/handler/bot.go` around lines 259 - 265, Update the endpoint comment
associated with GetAgentbotLogs to remove the “Mirrors python
bot_api.py:agent_bot_logs” migration-history reference, while preserving the
current behavior and authentication details documented above it.
Source: Coding guidelines
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/handler/bot_test.go (1)
858-861: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCorrect the stub documentation.
GetAPITokenByBetanow defaults to an error, notCodeUnauthorized, and its failure does not itself short-circuit the request. Update or remove this now-inaccurate “unset methods” claim.Suggested update
-// Each call site sets only the methods it needs; unset methods -// return safe defaults (CodeUnauthorized so the middleware -// short-circuits to 401). +// User lookups default to CodeUnauthorized. The optional beta-token +// lookup returns an error when it is not configured.As per coding guidelines, “Remove dead tests, commented-out code, stale documentation, and ‘move later’ notes.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/bot_test.go` around lines 858 - 861, Update the documentation for stubUserTokenResolver to remove the inaccurate claim that all unset methods return CodeUnauthorized and short-circuit middleware; accurately describe the current default behavior of GetAPITokenByBeta, or remove the unset-methods explanation entirely.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/handler/bot_test.go`:
- Around line 858-861: Update the documentation for stubUserTokenResolver to
remove the inaccurate claim that all unset methods return CodeUnauthorized and
short-circuit middleware; accurately describe the current default behavior of
GetAPITokenByBeta, or remove the unset-methods explanation entirely.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9842a276-e13f-432b-8a69-de5205e7398b
📒 Files selected for processing (3)
internal/handler/auth.gointernal/handler/bot.gointernal/handler/bot_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/handler/bot.go
Summary
As title