fix(work): fence repeated approval intents and audit state changes atomically

This commit is contained in:
ex_tianzy
2026-11-17 15:21:54 +08:00
parent 03d34f1d55
commit 75c609ded6
15 changed files with 638 additions and 10 deletions
+6 -4
View File
@@ -215,7 +215,7 @@ def validate_overlay(base, merged, candidate, router_key_required=True, approval
env = new[name]["environment"]
for key, value in old[name].get("environment", {}).items():
if key not in {"HN_CREDENTIAL_MODE","HN_ROUTER_ADMISSION_SECRET","HN_CREDENTIAL_KEYRING_FILE",
"HN_CREDENTIAL_PERMISSION_PROFILES","HN_CONNECTOR_INTERNAL_URL","HN_FEISHU_APP_ID","HN_OAUTH_ENABLED","HN_WORK_FILES_ENABLED","HN_WORK_TASK_CARDS_ENABLED","HN_WORK_REMOTE_APPROVALS_ENABLED","HN_FEISHU_TENANT_KEY","HN_FEISHU_VERIFICATION_TOKEN"}:
"HN_CREDENTIAL_PERMISSION_PROFILES","HN_CONNECTOR_INTERNAL_URL","HN_FEISHU_APP_ID","HN_OAUTH_ENABLED","HN_WORK_FILES_ENABLED","HN_WORK_TASK_CARDS_ENABLED","HN_WORK_REMOTE_APPROVALS_ENABLED","HN_FEISHU_TENANT_KEY","HN_FEISHU_VERIFICATION_TOKEN","HN_APPROVAL_RETENTION_ENABLED"}:
if env.get(key) != value:
raise DeployError("existing environment changed: "+key)
old_volumes = {v["target"]:v for v in old[name].get("volumes", [])}
@@ -238,7 +238,7 @@ def validate_overlay(base, merged, candidate, router_key_required=True, approval
# namespace rather than silently converting it to production. All modes still
# require PostgreSQL and HTTPS/WSS for this existing-server migration.
require_platform(env)
approval_keys={'HN_WORK_REMOTE_APPROVALS_ENABLED','HN_FEISHU_TENANT_KEY','HN_FEISHU_VERIFICATION_TOKEN'}
approval_keys={'HN_WORK_REMOTE_APPROVALS_ENABLED','HN_FEISHU_TENANT_KEY','HN_FEISHU_VERIFICATION_TOKEN','HN_APPROVAL_RETENTION_ENABLED'}
for name in ('connector','router'):
before=old[name].get('environment',{});after=new[name]['environment']
if name=='connector'and approval_plan and approval_plan.get('remote_approvals_managed'):
@@ -454,9 +454,11 @@ def prepare_update(args):
shared={'HN_WORK_REMOTE_APPROVALS_ENABLED':'true',
'HN_FEISHU_TENANT_KEY':approval_identity['tenant_key'],
'HN_FEISHU_VERIFICATION_TOKEN':approval_identity['verification_token']}
plan['connector_approval_environment']=shared
# Retention remains disabled for this candidate even if a deployment
# environment contains an unrelated setting. Enabling needs review.
plan['connector_approval_environment']={**shared,'HN_APPROVAL_RETENTION_ENABLED':'false'}
plan['longconn_approval_environment']={**shared,'HN_CREDENTIAL_MODE':'broker'}
overlay['services']['connector']['environment'].update(shared)
overlay['services']['connector']['environment'].update(plan['connector_approval_environment'])
overlay['services']['connector']['environment']['HN_WORK_TASK_CARDS_ENABLED']='true'
plan['work_task_cards_enabled']=True
original_long=live['services']['longconn']