Remove agent usage records left behind when their collector goes away - #10911
Open
Daniluvatar wants to merge 1 commit into
Open
Remove agent usage records left behind when their collector goes away#10911Daniluvatar wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).