Skip to content

fix(go-agent): align GitHub and Invoke Canvas components - #16849

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-GitHub-and-HTTP
Jul 13, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-GitHub-and-HTTP

Conversation

@Harry-Hz-Zhang

Copy link
Copy Markdown
Contributor

Summary

  • Add the GitHub Canvas component with tool registration and reference propagation.
  • Align the Invoke component with the Python contract for node config, input form, response output, and timing fields.
  • GitHub search and HTTP Invoke now work correctly in the Go Canvas runtime.

Tests

  • bash build.sh --test ./internal/agent/tool/...
  • bash build.sh --test ./internal/agent/component/...

Note: the untracked go_ragflow_cli file is not part of the PR changes.

image image

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d401747a-c26e-4d0a-a528-bebd37846a16

📥 Commits

Reviewing files that changed from the base of the PR and between ad65fa8 and b848403.

📒 Files selected for processing (5)
  • internal/agent/runtime/state.go
  • internal/agent/runtime/state_test.go
  • internal/agent/tool/github.go
  • internal/agent/tool/github_test.go
  • internal/agent/tool/registry.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/agent/tool/registry.go
  • internal/agent/tool/github.go
  • internal/agent/tool/github_test.go

📝 Walkthrough

Walkthrough

Adds a configurable GitHub repository search tool and Canvas component with retrieval references, and changes InvokeComponent to support stored parameters, normalized outputs, timing metadata, headers, and input forms.

Changes

GitHub search integration

Layer / File(s) Summary
GitHub tool contract and configuration
internal/agent/tool/github.go, internal/agent/tool/registry.go, internal/agent/tool/github_test.go
GitHub search now accepts query and configurable top_n, sends updated API parameters, returns raw items, and validates node configuration.
Canvas GitHub component and retrieval output
internal/agent/component/github.go, internal/agent/component/fixture_stubs.go, internal/agent/component/github_test.go, internal/agent/runtime/state.go, internal/agent/runtime/state_test.go
Registers the GitHub component, formats search results as retrieval chunks, returns formalized_content and json, and persists retrieval references in Canvas state.

Invoke component contract

Layer / File(s) Summary
Invoke runtime behavior and outputs
internal/agent/component/invoke.go
InvokeComponent retains parameters, merges inputs, supports flexible headers, returns result with timing metadata, exposes input forms, and updates SSRF errors and outputs.
Invoke contract tests
internal/agent/component/invoke_test.go
Tests validate the normalized result contract, timing fields, node parameters, input forms, SSRF behavior, and redirect handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: ☯️ refactor, 🧪 test

Suggested reviewers: yuzhichang, jinhai-cn

Poem

I’m a rabbit with repos to find,
Search stars and snippets neatly aligned.
Invoke returns results, crisp and bright,
State keeps references tucked just right.
Hop, hop—tests guard the trail tonight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: aligning GitHub and Invoke Canvas components.
Description check ✅ Passed The PR description matches the template with a clear Summary and includes testing context.
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.

@Harry-Hz-Zhang Harry-Hz-Zhang added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 13, 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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
internal/agent/component/github.go (1)

219-223: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

SHA-1 used for non-security ID hashing — consider a non-crypto hash.

githubHashInt only derives deterministic numeric IDs for chunk/document identifiers, not a security boundary, so SHA-1's cryptographic weakness isn't exploitable here. Still, using crypto/sha1 for this will keep tripping SAST tools (see hint below); swapping to hash/fnv (or sha256) removes the recurring flag with a small change.

♻️ Proposed fix: use FNV instead of SHA-1 for non-security ID generation
-import (
-	"crypto/sha1"
+import (
+	"hash/fnv"
 	...
 )
 
 func githubHashInt(value string, modulus int64) int64 {
-	sum := sha1.Sum([]byte(value))
-	number := new(big.Int).SetBytes(sum[:])
-	return new(big.Int).Mod(number, big.NewInt(modulus)).Int64()
+	h := fnv.New64a()
+	_, _ = h.Write([]byte(value))
+	return int64(h.Sum64() % uint64(modulus))
 }
Static analysis flagged this as CWE-327 (broken/risky crypto), but the usage here is non-security ID generation, not signatures/integrity/auth.
🤖 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/component/github.go` around lines 219 - 223, Replace the SHA-1
digest in githubHashInt with a non-cryptographic hash such as FNV, updating the
corresponding import and preserving deterministic modulus-based int64 output.
Keep the function’s existing inputs and behavior unchanged for generating
numeric identifiers.

Source: Linters/SAST tools

internal/agent/tool/github.go (1)

71-75: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the unused constructor — NewGitHubToolWith has no call sites elsewhere in the repo, so keeping it exported only ավելգ the public surface. Remove it or make it unexported.

🤖 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/tool/github.go` around lines 71 - 75, Remove the unused
exported NewGitHubToolWith constructor from the GitHub tool implementation, or
rename it to an unexported symbol if it is needed internally; retain
NewGitHubToolWithDefaults and all existing behavior.

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/agent/runtime/state.go`:
- Around line 392-422: Update CanvasState.SetRetrievalReferences to merge with
the existing Retrieval["chunks"] and Retrieval["doc_aggs"] instead of replacing
them on each call. Preserve prior chunks, append new chunks, and retain the
first aggregate per document name across all calls while keeping the existing
lock-safe behavior.

In `@internal/agent/tool/registry.go`:
- Around line 198-220: The buildGitHubTool function must enforce GitHub’s
maximum top_n value of 100 before constructing githubParams. After validating
that topN is positive, reject or clamp values above 100, ensuring
NewGitHubToolWithDefaults never receives a larger per-page value.

---

Nitpick comments:
In `@internal/agent/component/github.go`:
- Around line 219-223: Replace the SHA-1 digest in githubHashInt with a
non-cryptographic hash such as FNV, updating the corresponding import and
preserving deterministic modulus-based int64 output. Keep the function’s
existing inputs and behavior unchanged for generating numeric identifiers.

In `@internal/agent/tool/github.go`:
- Around line 71-75: Remove the unused exported NewGitHubToolWith constructor
from the GitHub tool implementation, or rename it to an unexported symbol if it
is needed internally; retain NewGitHubToolWithDefaults and all existing
behavior.
🪄 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: 6cf7c9bd-1b05-4d98-8dd7-2452ca000da4

📥 Commits

Reviewing files that changed from the base of the PR and between ed27b5f and ad65fa8.

📒 Files selected for processing (9)
  • internal/agent/component/fixture_stubs.go
  • internal/agent/component/github.go
  • internal/agent/component/github_test.go
  • internal/agent/component/invoke.go
  • internal/agent/component/invoke_test.go
  • internal/agent/runtime/state.go
  • internal/agent/tool/github.go
  • internal/agent/tool/github_test.go
  • internal/agent/tool/registry.go

Comment thread internal/agent/runtime/state.go Resolved
Comment thread internal/agent/tool/registry.go Resolved
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

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 💞 feature Feature request, pull request that fullfill a new feature. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants