88
99What a request sends
1010--------------------
11- One JSON object of named files, compressed with xz. Both requests send the same files:
11+ One JSON object of named files, compressed with xz. Both requests send the same files, and the same
12+ bytes unless architecture's carries source:
1213
1314- head.json and base.json: one side document per commit (see side_document). It holds what the
1415 service reads from that commit's analysis.json and call graph (static_analysis.pkl), each fact once:
3536-----------
3637- The service sets two limits on every request, and _encode checks both before anything is sent: the
3738 JSON, measured first because that is cheap, against MAX_FEATURE_JSON_BYTES (MAX_BRIEFING_JSON_BYTES
38- for the problem history), then the xz once against MAX_COMPRESSED_BYTES. Past either a feature request
39- is skipped, after first dropping source.json if architecture carried it.
39+ for the problem history), then the xz once against MAX_COMPRESSED_BYTES. The JSON limit is 62 times
40+ the compressed one, so the cheap check already turns away whatever could only fit at better than 62:1.
41+ These bundles compress about 10:1, but no tighter cut-off holds for every request.
42+ - xz at this preset takes about 700 MB and seconds per 10 MB, so a run compresses one body at a time and
43+ each at most once: the body without source, which both features send, and architecture's with source
44+ when there is source. When that one does not fit, architecture sends the shared one.
4045- MAX_FILES: how many changed files have their contents sent; past it a feature reads diffs only.
4146- MAX_FILE_BYTES: a larger file is sent neither in files.json nor in source.json.
4247- MAX_SOURCE_BYTES: the most source.json holds; past it source is not sent.
@@ -634,12 +639,24 @@ def _encode(body: dict, max_json_bytes: int, what: str = "bundle") -> bytes:
634639 return data
635640
636641
637- def _pack (ctx : dict , files : dict [str , str ], omitted : dict [str , str ]) -> bytes :
638- """A feature request: the named files, and why any optional one is missing."""
639- body = {"version" : 1 , "repo" : ctx ["repo" ], "pr" : ctx ["pr" ], "files" : files }
640- if omitted :
641- body ["omitted" ] = omitted
642- return _encode (body , MAX_FEATURE_JSON_BYTES )
642+ def _requests (ctx : dict , inputs : dict [str , str ], env : dict ) -> tuple [bytes , bytes ]:
643+ """The review guide's request and architecture's, compressed one after the other. Both can send the
644+ body without source, so it is compressed once; it says why source is missing, which only architecture
645+ reads. Architecture's body with source is compressed only when there is source, and the shared one
646+ stands in when it does not fit. TooLarge when not even the shared one fits."""
647+ try :
648+ source , why = collect_source (env )
649+ except Exception as error :
650+ source , why = None , f"reading it failed: { type (error ).__name__ } "
651+ body = {"version" : 1 , "repo" : ctx ["repo" ], "pr" : ctx ["pr" ], "files" : inputs }
652+ missing = (why or "the source was not collected" ) if source is None else "the repository is too large to send"
653+ shared = _encode ({** body , "omitted" : {"source.json" : missing }}, MAX_FEATURE_JSON_BYTES )
654+ if source is None :
655+ return shared , shared
656+ try :
657+ return shared , _encode ({** body , "files" : {** inputs , "source.json" : source }}, MAX_FEATURE_JSON_BYTES )
658+ except TooLarge :
659+ return shared , shared
643660
644661
645662def _no_architecture (ctx : dict , status : str , reason : str ) -> dict :
@@ -658,11 +675,10 @@ def _no_architecture(ctx: dict, status: str, reason: str) -> dict:
658675 }
659676
660677
661- def run_review_guide (service_url : str , ctx : dict , inputs : dict , headers : dict , artifact : Path ) -> None :
678+ def run_review_guide (service_url : str , data : bytes , headers : dict , artifact : Path ) -> None :
662679 try :
663680 if "x-llm-provider" in headers and "x-llm-api-key" not in headers :
664681 raise Skip ("the service cannot call this run's provider" )
665- data = _pack (ctx , inputs , {})
666682 answer = _post (f"{ service_url .rstrip ('/' )} /v1/review-guide" , data , headers )
667683 guide = answer .get ("guide" )
668684 if not isinstance (guide , dict ):
@@ -672,25 +688,8 @@ def run_review_guide(service_url: str, ctx: dict, inputs: dict, headers: dict, a
672688 print (f"::notice::review-guide { 'skipped' if isinstance (error , Skip ) else 'failed' } : { error } " )
673689
674690
675- def run_architecture (service_url : str , ctx : dict , inputs : dict , headers : dict , env : dict ) -> dict :
691+ def run_architecture (service_url : str , ctx : dict , data : bytes , headers : dict ) -> dict :
676692 try :
677- try :
678- source , why = collect_source (env )
679- except Exception as error :
680- source , why = None , f"reading it failed: { type (error ).__name__ } "
681- files , omitted = dict (inputs ), {}
682- if source is None :
683- omitted ["source.json" ] = why or "the source was not collected"
684- else :
685- files ["source.json" ] = source
686- try :
687- data = _pack (ctx , files , omitted )
688- except TooLarge :
689- if "source.json" not in files :
690- raise
691- del files ["source.json" ]
692- omitted ["source.json" ] = "the repository is too large to send"
693- data = _pack (ctx , files , omitted )
694693 answer = _post (f"{ service_url .rstrip ('/' )} /v1/architecture" , data , headers )
695694 envelope = answer .get ("envelope" )
696695 if not isinstance (envelope , dict ) or envelope .get ("status" ) not in ("ok" , "partial" , "skipped" , "failed" ):
@@ -711,15 +710,18 @@ def main(env: dict | None = None) -> int:
711710 return 0
712711 try :
713712 headers = {** _bearer (env ), ** model_headers (env )}
714- inputs = collect (env )
713+ guide_request , architecture_request = _requests (ctx , collect (env ), env )
714+ except TooLarge as error :
715+ print (f"::notice::review-guide skipped: { error } " )
716+ architecture = _no_architecture (ctx , "skipped" , str (error ))
715717 except Exception as error :
716718 reason = f"collecting inputs or credentials failed: { type (error ).__name__ } : { error } "
717719 print (f"::notice::review-guide failed: { reason } " )
718720 architecture = _no_architecture (ctx , "failed" , reason )
719721 else :
720722 with ThreadPoolExecutor (max_workers = 2 ) as pool :
721- guide = pool .submit (run_review_guide , service_url , ctx , inputs , headers , artifact )
722- result = pool .submit (run_architecture , service_url , ctx , inputs , headers , env )
723+ guide = pool .submit (run_review_guide , service_url , guide_request , headers , artifact )
724+ result = pool .submit (run_architecture , service_url , ctx , architecture_request , headers )
723725 architecture = result .result ()
724726 guide .result ()
725727 path = artifact / "closed" / "architecture.json"
0 commit comments