Repository navigation
Keep new ongoing duties in the current Goal and preserve proposal provenance #8716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loopx-agent
wants to merge
3
commits into
main
Choose a base branch
from
codex/audit-goal-objective-routing-pr-20261114
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+774
−101
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
402be79
Keep new ongoing duties in the current Goal and preserve proposal pro…
huangruiteng 1361abe
Integrate current main for objective proposal recovery validation
loopx-agent 4028891
Reuse pending objective proposals only for the current objective basis
loopx-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Callable | ||
| from datetime import datetime, timedelta, timezone | ||
| import hashlib | ||
| import json | ||
|
|
@@ -166,7 +167,11 @@ def __init__(self, root: Path) -> None: | |
| self.root.mkdir(parents=True, exist_ok=True, mode=0o700) | ||
| os.chmod(self.root, 0o700) | ||
| if not self.path.exists(): | ||
| atomic_write_json(self.path, self._empty_payload()) | ||
| with exclusive_file_lock( | ||
| self.path, agent_id="loopx-chat", operation="initialize_chat_action_store" | ||
| ): | ||
| if not self.path.exists(): | ||
| atomic_write_json(self.path, self._empty_payload()) | ||
| os.chmod(self.path, 0o600) | ||
|
|
||
| @staticmethod | ||
|
|
@@ -293,6 +298,87 @@ def create_preview( | |
| self._write(payload) | ||
| return proposal | ||
|
|
||
| def replay_or_reuse_preview( | ||
| self, | ||
| *, | ||
| action_kind: str, | ||
| context: Mapping[str, Any], | ||
| normalized_parameters: Mapping[str, Any], | ||
| idempotency_key: str, | ||
| shared_fields: tuple[str, ...], | ||
| reusable_states: set[str], | ||
| matches_review_basis: Callable[[object], bool] | None = None, | ||
| require_exact_context: bool = False, | ||
| summary: str | None = None, | ||
| ) -> dict[str, Any] | None: | ||
| """Resolve an accepted request or bind it to an equivalent pending review.""" | ||
| if summary is not None: | ||
| _safe_json_value(_bounded_text(summary, field="summary"), path="preview.summary") | ||
| key = normalize_idempotency_key(idempotency_key) | ||
| request = _safe_json_value({ | ||
| "action_kind": action_kind, | ||
| "context": context, | ||
| "normalized_parameters": normalized_parameters, | ||
| }) | ||
| digest = _canonical_digest(request) | ||
|
|
||
| def matches_scope(row: dict[str, Any]) -> bool: | ||
| row_context = row.get("context") | ||
| return ( | ||
| row.get("action_kind") == action_kind and isinstance(row_context, dict) | ||
| and all(row_context.get(field) == value for field, value in context.items()) | ||
| ) | ||
|
|
||
| with exclusive_file_lock( | ||
| self.path, agent_id="loopx-chat", operation="reuse_chat_action_preview" | ||
| ): | ||
| payload = self._read() | ||
| proposals = payload["proposals"] | ||
| bindings = payload["idempotency"] | ||
| if key in bindings: | ||
| binding = bindings[key] | ||
| row = proposals.get(binding["proposal_id"]) | ||
| if not isinstance(row, dict): | ||
| raise ValueError("typed Chat action idempotency index is inconsistent") | ||
| # Original previews already carry their full normalized request. | ||
| # Reused previews keep the later request's identity in the index. | ||
| previous_digest = binding.get("reused_request_digest") | ||
| if previous_digest is not None: | ||
| same_request = previous_digest == digest | ||
| else: | ||
| same_request = row["normalized_parameters"] == request["normalized_parameters"] and ( | ||
| not require_exact_context or row.get("context") == request["context"] | ||
| ) | ||
| if not matches_scope(row) or not same_request: | ||
| raise ActionConflictError("idempotency key already belongs to another preview") | ||
| return row | ||
|
|
||
| if not reusable_states or matches_review_basis is None: | ||
| return None | ||
| pending = max( | ||
| ( | ||
| row for row in proposals.values() | ||
| if isinstance(row, dict) and row.get("status") in reusable_states | ||
| and matches_scope(row) | ||
| and isinstance(row.get("normalized_parameters"), dict) | ||
| and all( | ||
| row["normalized_parameters"].get(field) == normalized_parameters[field] | ||
| for field in shared_fields | ||
| ) | ||
| and matches_review_basis(row.get("expected_state_fingerprint")) | ||
| ), | ||
| key=lambda row: (row.get("updated_at") or "", row["proposal_id"]), | ||
| default=None, | ||
| ) | ||
| if pending is None: | ||
| return None | ||
| bindings[key] = { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 匹配了 objective、reason 和 source 之后,这里直接写下新 ID。用真实 File/SQLite 先准备 A、应用 B、再以新 ID 提交 A,当前 head 将新 ID 绑定到随后被判 stale 的旧提案,原样重试也无法恢复。基线没有这个持久别名,重试可创建当前预览并应用。请将最新 objective basis 放入待审复用的资格判断,保留已受理旧 ID 的读回路径。 |
||
| "proposal_id": pending["proposal_id"], | ||
| "reused_request_digest": digest, | ||
|
loopx-agent marked this conversation as resolved.
Resolved
|
||
| } | ||
| self._write(payload) | ||
| return pending | ||
|
|
||
| def record_review_card_delivery( | ||
| self, | ||
| proposal_id: str, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.