Repository navigation
Remove agent usage records left behind when their collector goes away - #10911
Daniluvatar wants to merge 1 commit into
Conversation
The agents panel lists every file in the usage directory, so a record written by a collector that is no longer installed keeps showing up forever even after the plugin is removed. The orchestrator now prunes such records on every run, and a migration clears the ones already left behind. A record only disappears when no installed collector produces it and it has not been written to for seven days, so plugins that write fresh data without a collector of their own are not disturbed.
|
Reviewed at 897b36e by Claude Opus 5.5, with a second opinion from Codex Medium. The bug is real and the change fixes it. On an Omarchy ISO worker, a 30-day-old What needs a decision before this can go further:
Codex agreed on the contract and proportionality points. Its independence is not guaranteed, since it can read this session. Its regex finding was new. It also raised a race in which a writer replaces an old record between the Nothing was pushed to the branch. Next step: the maintainer decides whether records outside a collector may be removed. After that, the author needs to resolve the conflict and update the change to match. |
|
Re-checked at 897b36e against current Nothing on On the 7-day guard: it protects a writer that writes often, not one that is installed. A hook that only writes One interaction is new. #12353 discovers collectors in This still waits on the maintainer to decide whether records not written by a collector in |
Problema
O painel de agentes lista todos os arquivos
.jsondo diretório de uso, sem checar se ainda existe coletor para aquele agente. Quando um coletor vai embora (plugin desinstalado, agente renomeado, etc.), o registro antigo continua aparecendo no painel — como um fantasma — para sempre.É o que aconteceu, por exemplo, com antigos plugins que escreviam
copilot.json: mesmo depois da remediação do plugin, a linha "copilot" continuava visível no bar.Correção (em duas camadas)
Migração (
migrations/1788919234.sh) — limpa os órfãos já existentes em instalações atuais. Como migrações rodam naomarchy update/login, todos os usuários passam por ela uma vez.GC no orquestrador (
bin/omarchy-agent-usage-update) — na primeira coleta de cada dia, apaga registros órfãos, previne o acúmulo futuro e também cobre quem está atrasado nas migrações.Regra de segurança
Um registro só é apagado quando ambas condições valem:
bin/ padrão,plugins/*/scripts/eplugins/*/bin/, e um wrapper do próprio orquestrador não conta como coletor), eAgentes que ainda estão ativos — inclusive plugins que escrevem o JSON sem coletor próprio — não são tocados nunca: sua gravação recente os protege.
Testes
test/shell.d/agent-usage-update-test.sh(mantém agente vivo, preserva registro recente de coletor ausente, apaga órfão antigo, não conta wrapper como coletor, preserva coletor de plugin);test/shell.d/agent-usage-orphan-migration-test.shcom 6 testes (remota órfão, não remota agente vivo, não conta wrapper, preserva registro recente, reporta o que remove, idempotência);./test/allroda limpo para todos os testes relacionados (as 5 falhas restantes emshell.d— config, locate, runtime-smoke, snapper, unowned-system-paths — falham idênticas na árvore limpa, por falta de checkout deomarchy-pkgs/ambiente, não por esta mudança).