fix(gateway): make chat restart policy fail closed - #10
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a62fcb16df
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "Use the supervised host deployment/restart procedure." | ||
| ) | ||
| _RESTART_COMMAND = re.compile( | ||
| r"^\s*/restart(?:@[A-Za-z0-9_]+)?(?:\s+.*)?\s*$", |
There was a problem hiding this comment.
Match every command form the gateway treats as restart
On free-form gateway platforms, /restart@- or /restart@ does not match this regex, but MessageEvent.get_command() in gateway/platforms/base.py strips everything after @ and returns restart, after which gateway/run.py invokes the built-in restart handler. An authorized chat user can therefore bypass the disabled policy using input the gateway already treats as the same command; base the gate on the gateway's canonical command parsing rather than this narrower regex.
AGENTS.md reference: AGENTS.md:L54-L57
Useful? React with 👍 / 👎.
| return None | ||
| if _restart_command_enabled(): | ||
| return None | ||
| return {"action": "rewrite", "text": _BLOCKED_COMMAND} |
There was a problem hiding this comment.
Handle blocked restarts before running-agent busy logic
When the session already has a running agent, this rewrite is not side-effect-free: the running-agent fast path in gateway/run.py recognizes only built-in commands via resolve_command(), so the plugin-only /restart-policy-blocked falls into the queue, steer, or interrupt branches instead of reaching the plugin handler later in dispatch. Consequently, a denied /restart can interrupt the current turn or be queued rather than returning the policy explanation; route the denial through a path handled safely before busy-input processing and cover the real gateway flow.
AGENTS.md reference: AGENTS.md:L84-L87
Useful? React with 👍 / 👎.
Contexto
Reconstrução final e mínima do DTC-03 sobre o
mainatual. Substitui #9, #7 e o trecho equivalente do PR contaminado #4.Mudança
Adiciona o plugin opt-in
restart-command-policy:/restartempre_gateway_dispatch, antes do handler interno;/restart-nowou texto comum.Semântica fail-closed
falseexplícito: bloqueia;gatewaymalformado ou config ilegível: bloqueia;Redaction
Falhas de parser/loader não registram texto da exceção. A regressão injeta uma string sensível na exceção e comprova que ela não chega ao log.
Ativação
É necessário um único restart supervisionado após o deploy para carregar o plugin.
Propriedades de segurança
Uma solicitação bloqueada nunca chega ao handler interno. Portanto, não cria
.restart_notify.jsonou.restart_last_processed.json, não inicia drain, não sinaliza o processo e não solicita reinicialização.Verificação local
python -m py_compile: aprovado;tests/test_restart_command_policy_plugin.py: aprovada;Gates restantes
/restartbloqueado, PID invariável, nenhum marker novo,/statussaudável e rollback comprovado.