@@ -937,7 +937,7 @@ async def trigger_workflow(client: httpx.AsyncClient, ctx: TaskContext, task_tex
937937 # 检查上下文大小
938938 context_str = ctx .to_json_string ()
939939 logger .info (f"Context size: { len (context_str )} chars" )
940-
940+
941941 # 调试信息
942942 if ctx .comments_history :
943943 logger .info (f"Comments history: { len (ctx .comments_history )} items" )
@@ -951,35 +951,66 @@ async def trigger_workflow(client: httpx.AsyncClient, ctx: TaskContext, task_tex
951951 logger .info (f" ReviewComment[{ i } ]: @{ comment .get ('user' )} - { comment .get ('path' )} : { comment .get ('body' , '' )[:50 ]} ..." )
952952 if ctx .is_truncated is not None :
953953 logger .info (f"Context was truncated: { ctx .is_truncated } " )
954-
954+
955955 # 检查是否有重复/空字段
956956 logger .info (f"diff_content present: { bool (ctx .diff_content )} " )
957957 logger .info (f"clone_url: { ctx .clone_url } " )
958958 logger .info (f"head_ref: { ctx .head_ref } , base_ref: { ctx .base_ref } " )
959959 logger .info (f"head_repo: { ctx .head_repo } , base_repo: { ctx .base_repo } " )
960-
960+
961961 # 记录任务描述
962962 logger .info (f"LLM_TASK to send: '{ task_text [:200 ]} { '...' if len (task_text ) > 200 else '' } '" )
963-
964- if len (context_str ) > 60000 : # GitHub限制
965- logger .warning (f"Context too large ({ len (context_str )} chars), truncating..." )
966- # 简化上下文
967- ctx .diff_content = "[Diff truncated due to size limits]"
968- if ctx .comments_history and len (ctx .comments_history ) > 10 :
969- logger .info (f"Reducing comments history from { len (ctx .comments_history )} to 10 items" )
970- ctx .comments_history = ctx .comments_history [- 10 :] # 只保留最近10条
971- context_str = ctx .to_json_string ()
963+
964+ # 检查是否需要将数据存储到 issue(因为 repository_dispatch 的 payload 也有 64KB 限制)
965+ issue_number = None
966+ use_repository_dispatch = True
967+
968+ # 如果数据太大,需要先创建 issue 存储数据
969+ if len (context_str ) > 50000 or len (task_text ) > 10000 :
970+ logger .warning (f"Data too large (context: { len (context_str )} , task: { len (task_text )} ), storing in issue..." )
971+
972+ # 创建 issue 来存储数据
973+ issue_body = f"""<!-- TASK_START -->{ task_text } <!-- TASK_END -->
974+ <!-- CONTEXT_START -->{ context_str } <!-- CONTEXT_END -->
975+
976+ > 这个 issue 用于存储 workflow 的上下文数据,由 repository_dispatch 触发。
977+ > Run ID: { os .getenv ('GITHUB_RUN_ID' , 'unknown' )}
978+ > Triggered by: { ctx .trigger_user }
979+ """
980+
981+ issue_url = await create_issue (client , f"[数据存储] Context for node { node_id } " , issue_body )
982+ if issue_url :
983+ issue_number = issue_url .split ('/' )[- 1 ]
984+ logger .info (f"Created issue #{ issue_number } to store context data" )
985+ # 清空数据,因为将从 issue 读取
986+ context_str = ""
987+ task_text = ""
988+ else :
989+ logger .error ("Failed to create issue for large data, falling back to truncation" )
990+ # 回退到截断方案
991+ use_repository_dispatch = False
972992
973993 url = f"{ REST_API } /repos/{ CONTROL_REPO } /actions/workflows/llm-bot-runner.yml/dispatches"
974994 headers = {"Authorization" : f"token { GQL_TOKEN } " , "Accept" : "application/vnd.github.v3+json" }
975995
996+ # 构建 payload
976997 payload = {
977998 "ref" : "main" ,
978- "inputs" : {
999+ "client_payload" : {}
1000+ }
1001+
1002+ if use_repository_dispatch :
1003+ # 使用 repository_dispatch
1004+ payload ["client_payload" ]["task" ] = task_text [:2000 ] if task_text else ""
1005+ payload ["client_payload" ]["context" ] = context_str if context_str else ""
1006+ if issue_number :
1007+ payload ["client_payload" ]["issue_number" ] = issue_number
1008+ else :
1009+ # 回退到 workflow_dispatch(数据已截断)
1010+ payload ["inputs" ] = {
9791011 "task" : task_text [:2000 ],
9801012 "context" : context_str
9811013 }
982- }
9831014
9841015 try :
9851016 r = await client .post (url , headers = headers , json = payload )
@@ -1012,6 +1043,32 @@ async def trigger_workflow(client: httpx.AsyncClient, ctx: TaskContext, task_tex
10121043 logger .error (f"Exception during workflow dispatch: { e } " )
10131044 return False
10141045
1046+
1047+ async def create_issue (client : httpx .AsyncClient , title : str , body : str ) -> Optional [str ]:
1048+ """
1049+ 创建 GitHub Issue 并返回 URL
1050+ """
1051+ url = f"{ REST_API } /repos/{ CONTROL_REPO } /issues"
1052+ headers = {"Authorization" : f"token { GQL_TOKEN } " , "Accept" : "application/vnd.github.v3+json" }
1053+
1054+ payload = {
1055+ "title" : title ,
1056+ "body" : body ,
1057+ "labels" : ["context-data" ]
1058+ }
1059+
1060+ try :
1061+ r = await client .post (url , headers = headers , json = payload )
1062+ if r .status_code == 201 :
1063+ data = r .json ()
1064+ return data .get ("html_url" )
1065+ else :
1066+ logger .error (f"Failed to create issue: { r .status_code } - { r .text } " )
1067+ return None
1068+ except Exception as e :
1069+ logger .error (f"Exception creating issue: { e } " )
1070+ return None
1071+
10151072# --- 轮询逻辑 ---
10161073async def poll_loop ():
10171074 """
0 commit comments