fix: eliminate redundant metadata_dict fetch in loglines() and _log_s…#3035
fix: eliminate redundant metadata_dict fetch in loglines() and _log_s…#3035sakshisemalti wants to merge 4 commits intoNetflix:masterfrom
Conversation
Greptile SummaryThis PR eliminates a redundant Key points:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Task
participant MetadataService
Note over Caller,MetadataService: BEFORE (2 HTTP requests)
Caller->>Task: task.stdout
Task->>Task: _load_log("stdout")
Task->>MetadataService: metadata_dict (HTTP call 1)
MetadataService-->>Task: meta_dict
Task->>Task: loglines(stream, meta_dict=meta_dict)
Task->>Task: self.current_attempt
Task->>MetadataService: metadata_dict (HTTP call 2 – redundant)
MetadataService-->>Task: meta_dict (duplicate)
Task-->>Caller: log content
Note over Caller,MetadataService: AFTER (1 HTTP request)
Caller->>Task: task.stdout
Task->>Task: _load_log("stdout")
Task->>MetadataService: metadata_dict (HTTP call 1)
MetadataService-->>Task: meta_dict
Task->>Task: loglines(stream, meta_dict=meta_dict)
Task->>Task: attempt = self._attempt ?? meta_dict["attempt"]
Note right of Task: No extra HTTP call
Task-->>Caller: log content
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
PR Type
Summary
loglines()and_log_size()calledself.current_attemptinternally even whenmeta_dictwas already fetched and passed in by_load_log(), triggering a redundantmetadata_dictHTTP request on every log access.Issue
Fixes #3034
Reproduction
Runtime:
Commands to run:
Where evidence shows up:
Before:
After:
Root Cause
loglines()and_log_size()both callself.current_attemptto get the attempt number.current_attemptis a property that callsself.metadata_dict, which issues an HTTP request to the metadata service.However,
_load_log()already fetchesmetadata_dictand passes it asmeta_dictto both methods. The attempt number is available inmeta_dictunder the key "attempt", making theself.current_attemptcall completely redundant.Why This Fix Is Correct
The fix reads attempt from meta_dict when it is available:
This uses the meta_dict passed into the method for the call. The fallback to self.current_attempt preserves full backward compatibility for any caller that does not pass meta_dict.
The fix is minimal. One line changed in two methods, no new imports, no interface changes.
Failure Modes Considered
Tests
Non-Goals
AI Tool Usage
AI tools were used to generate polished comments + for generating the reproducing issue test
yes