Skip to content

fix(agent): enable single-component debug for Agent in Go backend - #16606

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
euvre:fix/agent-single-debug-go
Jul 6, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
euvre:fix/agent-single-debug-go

Conversation

@euvre

@euvre euvre commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two issues that prevented the Agent component's single-component debug/test run from working under the Go backend:

  1. Dynamic input_form generation: Some components (e.g. Agent) do not store a static input_form in the DSL. The Go handler now falls back to the runtime component's GetInputForm() method, matching Python's Canvas.get_component_input_form behavior. This resolves the frontend 102 error: component has no input_form.

  2. Tenant ID injection for debug: Single-component debug runs use a fresh CanvasState that previously lacked tenant_id. AgentComponent.Invoke resolves LLM credentials via the tenant tables, so the debug run failed with api key is required. The handler now seeds state.Sys["tenant_id"] with the authenticated user's ID, mirroring Python's @add_tenant_id_to_kwargs decorator.

Changes

  • internal/handler/agent_component.go:
    • Added componentInputForm helper that first reads the static input_form and, if missing, instantiates the component and calls GetInputForm().
    • In DebugComponent, set debugState.Sys["tenant_id"] = user.ID before invoking the component.

- Generate input_form dynamically when DSL lacks static one
- Inject tenant_id into debug CanvasState for LLM credential resolution
@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 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR modifies the agent component handler to add a runtime fallback for resolving a component's input form when the DSL lacks it, and sets tenant_id in the debug canvas state prior to component invocation.

Changes

Agent Component Handler Updates

Layer / File(s) Summary
Runtime fallback for component input form
internal/handler/agent_component.go
Adds componentInputForm helper: tries DSL-based extraction first, and if input_form is missing, builds the runtime component via runtime.DefaultFactory and calls GetInputForm(), normalizing a nil result to an empty map; updates imports (context, fmt) and switches GetComponentInputForm to use this helper.
Debug invocation tenant_id fix
internal/handler/agent_component.go
Sets debugState.Sys["tenant_id"] to the canvas owner's user.ID before constructing invokeCtx for comp.Invoke in DebugComponent.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AgentHandler
  participant DSL
  participant RuntimeFactory
  participant Component

  Client->>AgentHandler: GetComponentInputForm request
  AgentHandler->>DSL: ExtractComponentInputForm
  alt input_form present
    DSL-->>AgentHandler: schema
  else input_form missing
    AgentHandler->>RuntimeFactory: create component (name, params)
    RuntimeFactory-->>AgentHandler: Component instance
    AgentHandler->>Component: GetInputForm()
    Component-->>AgentHandler: schema or nil
  end
  AgentHandler-->>Client: input form schema
Loading

Poem

A rabbit hopped through DSL trees so wide,
When input_form was gone, it wouldn't hide!
With runtime magic, schemas bloom anew,
And tenant_id joins the debug crew.
🐇✨ Hop on, code review, we're through!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: enabling single-component debug for the Agent backend.
Description check ✅ Passed The description matches the template's Summary section and provides clear context plus change details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

@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: 1

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

87-114: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Drop the unused ctx and userID parameters. componentInputForm doesn’t use them, and the only GetInputForm implementation in the repo doesn’t need request or tenant state either.

🤖 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/agent_component.go` around lines 87 - 114, The
componentInputForm helper in AgentHandler currently accepts ctx and userID but
never uses them, so remove those unused parameters from the function signature
and from any call sites to keep the API minimal. Update the componentInputForm
method and any references to its signature around dsl.ExtractComponentInputForm,
dsl.ExtractComponentName, and runtime.DefaultFactory usage so the code still
compiles cleanly.
🤖 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/agent_component.go`:
- Line 87: componentInputForm should guard against runtime.DefaultFactory()
being nil before calling it, just like DebugComponent does. Update the factory
lookup in AgentHandler.componentInputForm to check for a nil factory and return
a clean error/500 path instead of invoking runtime.DefaultFactory()(name,
params) directly, so the GET component input-form request cannot panic when the
runtime factory is uninitialized.

---

Nitpick comments:
In `@internal/handler/agent_component.go`:
- Around line 87-114: The componentInputForm helper in AgentHandler currently
accepts ctx and userID but never uses them, so remove those unused parameters
from the function signature and from any call sites to keep the API minimal.
Update the componentInputForm method and any references to its signature around
dsl.ExtractComponentInputForm, dsl.ExtractComponentName, and
runtime.DefaultFactory usage so the code still compiles cleanly.
🪄 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

Run ID: 2bd9f58a-5886-4d57-b137-30197043217f

📥 Commits

Reviewing files that changed from the base of the PR and between 7951897 and 1b5e9a0.

📒 Files selected for processing (1)
  • internal/handler/agent_component.go

// it instantiates the runtime component and calls its GetInputForm method.
// This mirrors Python's Canvas.get_component_input_form which invokes the
// component's own get_input_form when the static field is absent.
func (h *AgentHandler) componentInputForm(ctx context.Context, dslMap map[string]any, componentID, userID string) (map[string]any, error) {

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Missing nil check on runtime.DefaultFactory().

DebugComponent (Line 188-192) explicitly guards against runtime.DefaultFactory() returning nil before invoking it. componentInputForm calls runtime.DefaultFactory()(name, params) directly at Line 101 without the same guard — if the factory isn't initialized, this panics on a reachable request path (GET component input-form) instead of returning a clean 500 like its sibling handler does.

🐛 Proposed fix
 	params, _ := dsl.ExtractComponentParams(dslMap, componentID)
-	comp, err := runtime.DefaultFactory()(name, params)
+	factory := runtime.DefaultFactory()
+	if factory == nil {
+		return nil, fmt.Errorf("%w: component factory not initialised", dsl.ErrMalformedDSL)
+	}
+	comp, err := factory(name, params)
 	if err != nil {
 		return nil, fmt.Errorf("%w: component factory: %v", dsl.ErrMalformedDSL, err)
 	}

Also applies to: 101-104

🤖 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/agent_component.go` at line 87, componentInputForm should
guard against runtime.DefaultFactory() being nil before calling it, just like
DebugComponent does. Update the factory lookup in
AgentHandler.componentInputForm to check for a nil factory and return a clean
error/500 path instead of invoking runtime.DefaultFactory()(name, params)
directly, so the GET component input-form request cannot panic when the runtime
factory is uninitialized.

@euvre euvre added the ci Continue Integration label Jul 3, 2026
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit 0265ffb into infiniflow:main Jul 6, 2026
12 checks passed
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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants