Skip to content

feat(inbox): approval-item expiry (TTL) for all approval kinds (#622) - #637

Open
cagdasyurekli wants to merge 1 commit into
andrewyng:mainfrom
cagdasyurekli:feat/issue-622-inbox-approval-ttl
Open

feat(inbox): approval-item expiry (TTL) for all approval kinds (#622)#637
cagdasyurekli wants to merge 1 commit into
andrewyng:mainfrom
cagdasyurekli:feat/issue-622-inbox-approval-ttl

Conversation

@cagdasyurekli

Copy link
Copy Markdown

Summary

Closes #622.

Pending approvals in the inbox previously had no expiry (coworker/inbox.py) — an approval could sit indefinitely, wedging the suspending agent turn permanently on an approval request that might never be answered, or allowing a user to click allow hours later on stale consent context.

This PR implements TTL and expiry handling across all approval kinds (approval, question, directory, plan, tool):

  1. Per-Item Expiry TTL: Added optional expires_at and ttl_seconds parameters to InboxItem, InboxStore.add, and all kind-specific add helpers (add_approval, add_question, add_directory, add_plan, add_tool_request, add_notification).
  2. Honored at Resolve and Wait Time:
    • In InboxStore.resolve: late resolutions for expired items are rejected (resolve returns False) and the item auto-resolves as "expired" to prevent acting on stale human consent.
    • In InboxStore.wait: pending items with an expiry wait with an asyncio timeout; when the TTL elapses, the item is auto-resolved as "expired" and unblocks the suspending agent turn.
    • In InboxStore.list / InboxStore.pending / InboxStore.get: pending items whose TTL has elapsed are lazily transitioned to "expired".
  3. Turn Resumption Notice:
    • Added ApprovalOutcome.EXPIRED to coworker/engine.py.
    • When an approval item expires, inbox_approver returns ApprovalOutcome.EXPIRED.
    • TurnEngine records the event in the audit trail with status="expired" and returns an informative tool-error response ("approval request expired (TTL elapsed)") so the agent turn resumes gracefully rather than hanging forever.
  4. Configurable Default TTL:
    • Added inbox_approval_ttl_seconds: Optional[float] = None to Config (coworker/config.py), passed into InboxStore and TurnEngine defaults.
  5. Periodic Scheduler Sweeper:
    • SessionManager._scheduler_tick checks for due expired inbox items and durably resumes parked sessions if needed.

Verification

  • Added comprehensive tests in tests/test_inbox.py covering expiry calculation, default TTL, late resolution rejection, list/get filtering, wait timeout auto-resolution, and approver outcome.
  • Added test_turn_engine_approval_expired_resumes_with_notice in tests/test_engine.py to verify that expired approvals resume turn execution without wedging and emit the proper audit trail and tool error message.
  • Passed full test suites (pytest tests/test_inbox.py tests/test_engine.py tests/test_unattended.py).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Inbox approval-item expiry (TTL) for all approval kinds

1 participant