Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions loopx/file_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,14 +1271,12 @@ def exclusive_mutation_file_lock(
try:
yield effect_lock_path
finally:
_release_effect_mutation_lock(
effect_lock_path,
token,
# Lock cleanup is secondary to the durable body result. A cleanup
# failure must not replace either a successful result or its
# original exception; stale-owner recovery handles a later retry.
suppress_errors=True,
)
# A transient cleanup error can strand the marker while its process is
# still alive. Retry once for the marker this context created and let
# the release operation recheck its token and claim before retiring it.
released = _release_effect_mutation_lock(effect_lock_path, token, suppress_errors=True)
if not released and _same_effect_file_identity(identity, _effect_file_identity(effect_lock_path)):
_release_effect_mutation_lock(effect_lock_path, token, suppress_errors=True)


@contextmanager
Expand Down
1 change: 1 addition & 0 deletions skills/loopx-self-repair/references/repair-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ teaches a reusable control-plane lesson.
| `status_cache_decode_failure` | Opt-in cached status or quota readback fails with a UTF-8 decoding error while live collection works. | Cache miss metadata and a disposable malformed-cache reproduction through both CLI consumers. | The shared cache reader handles JSON and filesystem errors but lets text decoding abort live fallback. | Classify invalid UTF-8 as an unreadable cache miss in the existing IO owner; preserve damaged bytes on reads, collect live facts, and rewrite only with the explicit cache-write option. Test current Todo selection and successful reuse after repair; never suppress canonical source failures. |
| `desktop_readiness_deadline_reset` | Desktop remains on connecting when a loopback readiness response arrives in slow fragments. | Time a single real socket read and its enclosing startup retry with a disposable listener. Include a healthy Core and the legacy Chat 404 fallback. | Per-read socket timeouts renew after activity. A compatibility request can also start a fresh timeout, so the outer supervisor never observes a timely probe result. | Spend one monotonic allowance across connect, writes, reads and the compatibility request. Keep identity, response bounds and ownership checks. Verify automatic retry against qualified Core and confirm that an unverified listener is rejected. |
| `lock_holder_decode_hides_timeout` | Lock diagnostics or a contended acquisition raises `UnicodeDecodeError` instead of reporting unreadable metadata or the typed timeout. | Synthetic damaged holder bytes, liveness readback, and a real held-lock timeout followed by normal reacquisition. | Holder text decoding fails before the JSON/error guard, masking advisory failure and incident recording. | Treat invalid UTF-8 as unreadable at the shared holder reader; retain valid alternate records and kernel ownership. Cover the incident, inspection guidance and recovery after the actual holder exits; never delete the lock as repair. |
| `mutation_marker_cleanup_failure` | A result remains queued after a Goal lifetime lock timeout. The kernel lock is available, and the mutation marker retains a live owner. | Match the affected result and retry time to the exact timeout incident. Check the marker's owner and the kernel lock separately. | A failed retirement can leave the file that coordinates Python and TypeScript in place after the kernel lock is released. The current owner may still be alive. | Retry retirement only for the same file and ownership token at the owning scope's exit. Reproduce a transient retirement error and confirm the original result arrives once. For an existing marker owned by a live process, follow the service owner's recovery and verify the retained result after the retry. |
| `scheduler_deadline_bucket_reset_gap` | A generated tighter deadline ACK fails with `progression_regression`, even after the host applies the requested RRULE. | Saved failed ACK, originating Turn, prior/current progression buckets and reset tokens, current host readback, and exact generated argv. | The deadline changes the effective progression while an override reset profile omits those buckets, so index zero still carries the old identity. | Bind effective buckets through the existing reset-profile digest; keep time within a bucket stable. Preserve native monotonic, host-readback, receipt-freshness, CAS and replay guards. Reproduce 30-minute/index-one to 15-minute/index-zero through disposable File/SQLite CLI and separately qualify the installed artifact; never edit active scheduler state or infer runtime adoption from source tests. |
| `quiet_receipt_turn_start_context_loss` | A delegated request is delivered, but a quiet heartbeat reports no required inbox read and leaves it unassessed. | Original inbox delivery and assessment readback, initial hook dispatch, the captured final guard packet, and the automatic no-spend receipt reconstruction path. | The CLI observes pending context, then rebuilds the decision after stall writeback without forwarding that same Turn's hook dispatch. | Forward the original dispatch through the existing live-decision owner during reconstruction; preserve pending, empty and failed observations without re-running hooks or granting delivery/spend. Cover first and replayed stall receipts through final capture and CLI projection, including negative authority checks. Assess and link the original request, execute its admitted work, and report the actual result through its native return route; delivery or adoption alone is not completion. |
| `benchmark_planning_clock_projection_gap` | A resumed task closes work using an earlier Host deadline even though a continuation was explicitly authorized; readable history and an old ready plan are mistaken for current executable work. | Original task constraints, Host phase receipts, saved model input, current authorized continuation, actual quota/frontier readback and terminal dispositions; keep private trajectories outside public artifacts. | Historical Host timing and closure context survived recovery without the new continuation intent; ordinary planning should not inject Host countdowns. | Keep Host deadlines, remaining time and execution reserves out of ordinary model input; retain external enforcement and task-owned time constraints. At the explicitly authorized archive-recovery boundary, preserve old history and closure records, identify earlier Host clocks as historical in the new continuation request, and reuse Goal/Todo/replan with a stable operation identity. Read back actionable work or review before calling continuation ready; an old plan or exit code zero is insufficient. Do not renew budgets on retry, reopen without authorization, clear a user stop, filter task deadlines or bypass evaluation cooldowns. Cover clock-free fresh/resumed input, idempotent recovery and legitimate stopping; qualify real model adoption and score gains separately. |
Expand Down
2 changes: 1 addition & 1 deletion tests/test_file_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def fake_release(*args: object, **kwargs: object) -> bool:
with exclusive_cross_runtime_file_lock(target, timeout_seconds=0.2):
pass

assert calls == [True]
assert calls == [True, True]


@pytest.mark.skipif(os.name != "nt", reason="Win32 extended path regression")
Expand Down
44 changes: 44 additions & 0 deletions tests/test_manager_context_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,50 @@ def sender(route, session, turn, text):
assert reply_status(root, receipt)[0]["status"] == "delivered"


def test_original_return_survives_transient_goal_marker_release_failure(flow, monkeypatch):
import errno

from loopx.control_plane.collaboration.goal_instance_scope import collaboration_goal_scope
from loopx.control_plane.goals.source_session_registry_state import guard_path
from loopx.file_lock import _effect_mutation_lock_path

root, registry, _, create = flow
store = ChatSessionStore(root / "source-chat")
session, turn, receipt = create(external=True, source_store=store)
request_id = receipt["request_id"]
acknowledge(root, "research", "worker", request_id, "adopt", "Accepted the original request")
report(root, "research", "worker", request_id, "conclusion", "The original request is complete.")
marker = _effect_mutation_lock_path(guard_path(registry, "research"))
retire = Path.replace
failed = False

def fail_once(path, target):
nonlocal failed
if path == marker and not failed:
failed = True
raise OSError(errno.ENOSPC, "simulated transient failure retiring the goal marker")
return retire(path, target)

monkeypatch.setattr(Path, "replace", fail_once)
with collaboration_goal_scope(registry, goal_id="research", agents=("worker",)):
assert marker.exists()
assert failed

calls = []

def sender(route, original_session, original_turn, text):
calls.append((route["return_message_id"], original_session["session_id"], original_turn["turn_id"]))
return {"reply_verified": True, "idempotency_key": "fixture-confirmation"}

assert drain(root, registry, store, sender) == 1
assert reply_status(root, receipt)[0]["status"] == "delivered"
assert drain(root, registry, store, sender) == 0
messages = [item for item in store.messages(session["session_id"]) if item.get("origin") == "manager_followup"]
assert len(messages) == 1
assert calls == [(messages[0]["message_id"], session["session_id"], turn["turn_id"])]
assert not marker.exists()


def test_exact_return_skips_other_host_before_admission(flow):
from loopx.control_plane.projects.registry_codec import SOURCE_SESSION_PROFILE_ID

Expand Down
Loading