hermes-agent/gateway/session_operator.py
Teknium aca73b2f64 fix(kanban): a card attempt lost across an owner restart settles interrupted
A Kanban card attempt fenced `unknown` across owner epochs paused its card
session forever: run_task admitted with the worker's principal and a
`{text, finite}` payload, so GW-10's unattended settle rule never matched it.

The dispatcher now hands SessionAuthority.submit a trusted producer marker
(`_kanban_card`, a keyword argument, never a payload field). submit commits
it as `kanban_card_v1`; is_unattended recognises it, so boot recovery and the
drain settle the lost card turn interrupted with the automation notice and
never replay it. Clients cannot mint it: the authority's payload allowlist
and session.submit's parameter allowlist both refuse the key. An attempt
main committed without the marker resubmits unmarked on retry (same digest,
original receipt) and keeps today's pause.

The real-process restart probe (kanban_recovery_probe.py) pinned the old
pause; it now expects terminal/interrupted.

Refs #134889 (KB-8)
Refs #134889 only
2026-10-19 03:00:38 -07:00

38 lines
1.9 KiB
Python

"""Private provenance for already-authorized operator input.
Operator access is profile-local, not account linking or a change of authorship.
It never claims unowned legacy history: that still requires the native migration
path. Only SessionAuthority.submit writes this envelope after authorization;
public submission parameters cannot supply it.
"""
from hermes_state_runtime import RuntimeStoreError
# Fields ``SessionAuthority.submit`` commits for a local session's input; producers commit their own envelope.
LOCAL_INPUT_FIELDS = frozenset({'text', 'attachments_v1', 'finite', 'unattended', 'surface_v1', 'display_v1',
'cli_turn_v1', 'kanban_card_v1'})
def is_viewer_input(row):
"""A row a session viewer submitted through ``session.submit`` (a client's own prompt), not a producer
admission: ``local_automation_v1`` (plugin injection, delegation completions, process and watch notices,
/loop, heartbeat), a hosted-room task (``hosted:`` request id) or any other envelope."""
return (not str(row['request_id']).startswith('hosted:')
and {'text'} <= set(row['payload']) <= LOCAL_INPUT_FIELDS | {'local_operator_v1'})
def check_local_input(authority, ref, row, *, source=None):
payload = row['payload']
allowed = set(LOCAL_INPUT_FIELDS)
if 'local_operator_v1' in payload:
allowed.add('local_operator_v1')
if payload['local_operator_v1'] != {
'profile_id': authority.profile_id, 'session_id': ref.session_id,
'principal_id': row['principal_id']}:
raise RuntimeStoreError('permission_denied')
else:
source = source or authority.sessions[ref.session_id].source
if row['principal_id'] != source.user_id:
raise RuntimeStoreError('permission_denied')
if not {'text'} <= set(payload) <= allowed:
raise RuntimeStoreError('permission_denied')