refactor(session): trim RetentionResult to only fields callers read
Remove retained and new_last_consolidated from RetentionResult. Both were populated but never read by any caller. The authoritative state remains self.messages and self.last_consolidated, which the method mutates in place. Update docstring accordingly.
This commit is contained in:
@@ -112,10 +112,8 @@ def _metadata_title(metadata: Any) -> str:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RetentionResult:
|
class RetentionResult:
|
||||||
retained: list[dict]
|
|
||||||
dropped: list[dict]
|
dropped: list[dict]
|
||||||
already_consolidated_count: int
|
already_consolidated_count: int
|
||||||
new_last_consolidated: int
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -300,25 +298,22 @@ class Session:
|
|||||||
) -> RetentionResult:
|
) -> RetentionResult:
|
||||||
"""Keep a legal recent suffix, optionally extending it back to a user turn.
|
"""Keep a legal recent suffix, optionally extending it back to a user turn.
|
||||||
|
|
||||||
Returns a RetentionResult describing retained messages, removed messages,
|
Returns a RetentionResult with dropped messages and how many of those
|
||||||
and how the last_consolidated cursor changed.
|
were in the already-consolidated prefix. This method mutates
|
||||||
|
self.messages and self.last_consolidated in place.
|
||||||
"""
|
"""
|
||||||
if max_messages <= 0:
|
if max_messages <= 0:
|
||||||
dropped = list(self.messages)
|
dropped = list(self.messages)
|
||||||
lc = self.last_consolidated
|
lc = self.last_consolidated
|
||||||
self.clear()
|
self.clear()
|
||||||
return RetentionResult(
|
return RetentionResult(
|
||||||
retained=self.messages,
|
|
||||||
dropped=dropped,
|
dropped=dropped,
|
||||||
already_consolidated_count=min(lc, len(dropped)),
|
already_consolidated_count=min(lc, len(dropped)),
|
||||||
new_last_consolidated=self.last_consolidated,
|
|
||||||
)
|
)
|
||||||
if len(self.messages) <= max_messages:
|
if len(self.messages) <= max_messages:
|
||||||
return RetentionResult(
|
return RetentionResult(
|
||||||
retained=self.messages,
|
|
||||||
dropped=[],
|
dropped=[],
|
||||||
already_consolidated_count=0,
|
already_consolidated_count=0,
|
||||||
new_last_consolidated=self.last_consolidated,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
original = list(self.messages)
|
original = list(self.messages)
|
||||||
@@ -386,10 +381,8 @@ class Session:
|
|||||||
self.last_consolidated = new_lc
|
self.last_consolidated = new_lc
|
||||||
self.updated_at = datetime.now()
|
self.updated_at = datetime.now()
|
||||||
return RetentionResult(
|
return RetentionResult(
|
||||||
retained=retained,
|
|
||||||
dropped=dropped,
|
dropped=dropped,
|
||||||
already_consolidated_count=already_consolidated,
|
already_consolidated_count=already_consolidated,
|
||||||
new_last_consolidated=new_lc,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def enforce_file_cap(
|
def enforce_file_cap(
|
||||||
|
|||||||
Reference in New Issue
Block a user