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
2 changes: 1 addition & 1 deletion .secrets.baseline

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions docs/agent-denial-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ an operation without approval.

Completed decisions, including Council and OPA approvals/denials, omit
`retryable`. Other responses with no affirmative overload retry hint omit it
too. The Python models retain their `False` default for existing callers, but
serialization omits only that field when false; other defaults remain intact.
too. The Python models retain their `False` default for existing callers, and
serialization omits the field when false.
Clients should use `response.get("retryable", False)` and check `status`, not
assume the field is present or treat its absence as authorization. The field
remains optional in the output schema.
Expand All @@ -24,9 +24,27 @@ For `status: denied`, the response's `guidance` starts with a deterministic
note that safer revisions within the user's authorized goal need fresh
authorization, followed by the original Council or OPA
guidance. This reaches clients that read tool results without consulting the
output schema. Member votes and reasoning remain unchanged. Approved and error
responses retain their existing guidance, except for the clearer overload
instruction described above.
output schema. Member votes and reasoning remain unchanged.

When a packaged-file review fails, a deterministic native policy denial
takes precedence. `council_authorize` returns `status: denied`, omits
`error_code`, and issues no Writ. Follow the normal denial guidance. If the
request fails admission, for example due to missing required justification or
a full pending queue, the response reports the admission error without
`review_failed`.

An unavailable reviewer or invalid model decision contributes no vote. When the
valid votes reach the configured quorum, the Council returns the resulting
approval or denial without an `error_code`.

For an admitted request whose required review cannot complete,
`council_authorize` returns `status: error` and
`error_code: review_failed`, without a Writ. `council_propose_intent` returns
`success: false` and `state: failed` with the same error code. Any member
votes in the response are the valid results that arrived before the review
ended. Handle the failure before retrying. The error code does not grant
permission to execute or carry the admission-control retry hint. Monitoring
counts this outcome as a review error.

An agent may use the guidance to propose a safer operation within the user's
authorized goal. Every revised request requires a new authorization decision;
Expand Down
30 changes: 25 additions & 5 deletions nomos/level_2/quorum/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class QuorumResult:
status: QuorumStatus
record: VoteRecord
message: str
recorded: bool = False


class QuorumManager:
Expand Down Expand Up @@ -203,12 +204,13 @@ def cast_vote(
)

if auto_close and record.is_decided():
return self._close_vote(record)
return self._close_vote(record, recorded=True)

return QuorumResult(
status=QuorumStatus.PENDING,
record=record,
message=f"Vote recorded. Approve: {record.approve_weight}/{record.required_weight}",
recorded=True,
)

def revise_vote(
Expand Down Expand Up @@ -284,16 +286,23 @@ def revise_vote(
)

if auto_close and record.is_decided():
return self._close_vote(record)
return self._close_vote(record, recorded=True)

return QuorumResult(
status=QuorumStatus.PENDING,
record=record,
message=f"Vote revised (round {debate_round}). "
f"Approve: {record.approve_weight}/{record.required_weight}",
recorded=True,
)

def finalize_vote(self, intent_id: str, *, allow_pending: bool = False) -> QuorumResult:
def finalize_vote(
self,
intent_id: str,
*,
allow_pending: bool = False,
partial_voters: set[str] | None = None,
) -> QuorumResult:
"""Finalize a vote after a batch of ballots has been recorded."""
record = self._records.get(intent_id)
if record is None:
Expand All @@ -316,12 +325,20 @@ def finalize_vote(self, intent_id: str, *, allow_pending: bool = False) -> Quoru
message=f"Approve: {record.approve_weight}/{record.required_weight}",
)

if partial_voters is not None:
# A missing debate ballot must not leave an earlier ballot in the tally.
record.votes = {
voter_id: vote
for voter_id, vote in record.votes.items()
if voter_id in partial_voters
}

if record.is_decided():
return self._close_vote(record)

active_member_ids = {member.member_id for member in self.get_active_members()}
all_active_members_voted = active_member_ids.issubset(record.votes.keys())
if all_active_members_voted and not allow_pending:
if partial_voters is None and all_active_members_voted:
return self._close_vote(record, outcome=VoteType.DENY)

return QuorumResult(
Expand All @@ -330,7 +347,9 @@ def finalize_vote(self, intent_id: str, *, allow_pending: bool = False) -> Quoru
message=f"Approve: {record.approve_weight}/{record.required_weight}",
)

def _close_vote(self, record: VoteRecord, outcome: VoteType | None = None) -> QuorumResult:
def _close_vote(
self, record: VoteRecord, outcome: VoteType | None = None, *, recorded: bool = False
) -> QuorumResult:
"""Close a vote and record the outcome."""
record.closed_at = self._clock.now()
record.outcome = outcome or record.get_outcome()
Expand All @@ -356,6 +375,7 @@ def _close_vote(self, record: VoteRecord, outcome: VoteType | None = None) -> Qu
status=status,
record=record,
message=f"Vote closed: {status.value}",
recorded=recorded,
)

def forget_closed_vote(self, intent_id: str) -> bool:
Expand Down
26 changes: 22 additions & 4 deletions nomos/level_4/council/council.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ def cast_member_vote(
auto_close=finalize,
)

if not finalize and not result.recorded:
return SubmitResult(success=False, workflow=workflow, error=result.message)

workflow.vote_record = result.record
self._apply_quorum_result(workflow, result.status, reason)
return SubmitResult(success=True, workflow=workflow)
Expand Down Expand Up @@ -857,12 +860,19 @@ def revise_vote(
auto_close=finalize,
)

if not finalize and not result.recorded:
return SubmitResult(success=False, workflow=workflow, error=result.message)

workflow.vote_record = result.record
self._apply_quorum_result(workflow, result.status, reason)
return SubmitResult(success=True, workflow=workflow)

def finalize_intent_review(
self, intent_id: str, *, allow_pending: bool = False
self,
intent_id: str,
*,
allow_pending: bool = False,
partial_voters: set[str] | None = None,
) -> SubmitResult:
"""Finalize a batched council review round and sync workflow state."""
self._prune_terminal_workflows()
Expand All @@ -873,7 +883,12 @@ def finalize_intent_review(
if workflow.state != WorkflowState.AWAITING_APPROVAL:
return SubmitResult(success=True, workflow=workflow)

result = self._quorum_manager.finalize_vote(intent_id, allow_pending=allow_pending)
if partial_voters is None:
result = self._quorum_manager.finalize_vote(intent_id, allow_pending=allow_pending)
else:
result = self._quorum_manager.finalize_vote(
intent_id, allow_pending=allow_pending, partial_voters=partial_voters
)
workflow.vote_record = result.record
self._apply_quorum_result(workflow, result.status, workflow.denial_reason)
return SubmitResult(success=True, workflow=workflow)
Expand All @@ -889,10 +904,13 @@ def abort_intent_review(self, intent_id: str, reason: str) -> bool:
releases that capacity and stops a half-written review from being mistaken
for work still in flight.

Idempotent: unknown or already-terminal intents return False.
Idempotent: closed ballots are left alone. An expired or evicted workflow
may still have an open ballot; discard it without changing the workflow.
"""
workflow = self._workflows.get(intent_id)
if workflow is None or workflow.is_terminal:
if workflow is None or workflow.state == WorkflowState.EXPIRED:
return self._quorum_manager.abort_vote(intent_id)
if workflow.is_terminal:
return False

try:
Expand Down
Loading
Loading