Skip to content

fix: unable to get prologue in agent bot - #17299

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
Haruko386:master
Jul 23, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
Haruko386:master

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Summary

As title

image

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change migrates DSL extraction from top-level fields to obj.params, updates related handler errors and fixtures, removes API-token storage from beta authentication context, and makes agentbot logs validate the URL agent_id against the token-bound identifier.

Changes

DSL params migration

Layer / File(s) Summary
Nested params extraction
internal/agent/dsl/errors.go, internal/agent/dsl/extract.go
Input forms, prologues, and modes are read from nested params fields with explicit validation and updated errors.
DSL fixtures and propagation
internal/agent/dsl/extract_test.go, internal/handler/agent_component.go, internal/handler/agent_component_test.go, internal/service/bot_completion_history_test.go
Fixtures, handler messages, schema expectations, and service coverage use the new params-based DSL shape.

Bot authentication and log routing

Layer / File(s) Summary
Beta authentication context
internal/handler/auth.go, internal/handler/bot_test.go
Beta authentication retains user and bound-agent resolution while no longer storing api_token in request context.
Agentbot log route authorization
internal/handler/bot.go, internal/handler/bot_test.go
Agentbot logs validate the route agent_id, require a token-bound agent, and reject cross-agent requests with updated tests.

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
Loading

Suggested reviewers: jinhai-cn

Poem

A rabbit hops through params neat,
Inputs, mode, and prologue meet.
Tokens leave the context light,
Logs check agents by route just right.
Carrots cheer the changed code flow! 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description only says "As title" and includes an image, so it lacks the required summary and background context. Add a brief Summary explaining the bug, the DSL path change, and any relevant context or rationale instead of "As title".
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main fix: retrieving the agent bot prologue now works through params-based DSL extraction.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Haruko386 Haruko386 left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are more bugs🐞 come in agent-bots, drafted

@Haruko386

Copy link
Copy Markdown
Member Author

There are more bugs🐞 come in agent-bots, drafted

not now

@Haruko386 Haruko386 added the ci Continue Integration label Jul 23, 2026
@Haruko386
Haruko386 marked this pull request as draft July 23, 2026 08:48
@Haruko386
Haruko386 marked this pull request as ready for review July 23, 2026 08:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 win

Do not turn malformed nested params into successful empty values.

Both extractors discard the type-assertion result. A non-map obj.params, or non-string prologue/mode, returns ("", nil) and prevents callers from distinguishing malformed DSL from an intentionally absent optional value. Validate params and present scalar values, returning ErrMalformedDSL for 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 win

Remove Python implementation-history from this Go doc.

Keep the current raw DSL path and error contract; lines 29-33 describe Python internals/private _param initialization 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6467df3 and e32ffa7.

📒 Files selected for processing (9)
  • internal/agent/dsl/errors.go
  • internal/agent/dsl/extract.go
  • internal/agent/dsl/extract_test.go
  • internal/handler/agent_component.go
  • internal/handler/agent_component_test.go
  • internal/handler/auth.go
  • internal/handler/bot.go
  • internal/handler/bot_test.go
  • internal/service/bot_completion_history_test.go

Comment thread internal/handler/auth.go Resolved
Comment thread internal/handler/bot_test.go Resolved
Comment thread internal/handler/bot.go
Comment on lines +259 to +265
// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/handler/bot_test.go (1)

858-861: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Correct the stub documentation.

GetAPITokenByBeta now defaults to an error, not CodeUnauthorized, 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

📥 Commits

Reviewing files that changed from the base of the PR and between e32ffa7 and 2778d7a.

📒 Files selected for processing (3)
  • internal/handler/auth.go
  • internal/handler/bot.go
  • internal/handler/bot_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/handler/bot.go

@Haruko386 Haruko386 removed the ci Continue Integration label Jul 23, 2026
@Haruko386
Haruko386 marked this pull request as draft July 23, 2026 11:00
@Haruko386
Haruko386 marked this pull request as ready for review July 23, 2026 11:01
@Haruko386 Haruko386 added the ci Continue Integration label Jul 23, 2026
@JinHai-CN
JinHai-CN merged commit 5d8dfa6 into infiniflow:main Jul 23, 2026
9 checks passed
@Haruko386
Haruko386 deleted the master branch July 24, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants