Detect and clean stale POLECAT_DONE messages (#913)
* fix(witness): detect and ignore stale POLECAT_DONE messages Add timestamp validation to prevent witness from nuking newly spawned polecat sessions when processing stale POLECAT_DONE messages from previous sessions. - Add isStalePolecatDone() to compare message timestamp vs session created time - If message timestamp < session created time, message is stale and ignored - Add unit tests for timestamp parsing and stale detection logic Fixes #909 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(mail): add --stale flag to gt mail archive Add ability to archive stale messages (sent before current session started). This prevents old messages from cycling forever in patrol inbox. Changes: - Add --stale and --dry-run flags to gt mail archive - Move stale detection helpers to internal/session/stale.go for reuse - Add ParseAddress to parse mail addresses into AgentIdentity - Add SessionCreatedAt to get tmux session start time Usage: gt mail archive --stale # Archive all stale messages gt mail archive --stale --dry-run # Preview what would be archived Co-Authored-By: GPT-5.2 Codex <noreply@openai.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: GPT-5.2 Codex <noreply@openai.com>
This commit is contained in:
@@ -250,3 +250,71 @@ func TestParseSessionName_RoundTrip(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
address string
|
||||
want AgentIdentity
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "mayor",
|
||||
address: "mayor/",
|
||||
want: AgentIdentity{Role: RoleMayor},
|
||||
},
|
||||
{
|
||||
name: "deacon",
|
||||
address: "deacon",
|
||||
want: AgentIdentity{Role: RoleDeacon},
|
||||
},
|
||||
{
|
||||
name: "witness",
|
||||
address: "gastown/witness",
|
||||
want: AgentIdentity{Role: RoleWitness, Rig: "gastown"},
|
||||
},
|
||||
{
|
||||
name: "refinery",
|
||||
address: "rig-a/refinery",
|
||||
want: AgentIdentity{Role: RoleRefinery, Rig: "rig-a"},
|
||||
},
|
||||
{
|
||||
name: "crew",
|
||||
address: "gastown/crew/max",
|
||||
want: AgentIdentity{Role: RoleCrew, Rig: "gastown", Name: "max"},
|
||||
},
|
||||
{
|
||||
name: "polecat explicit",
|
||||
address: "gastown/polecats/nux",
|
||||
want: AgentIdentity{Role: RolePolecat, Rig: "gastown", Name: "nux"},
|
||||
},
|
||||
{
|
||||
name: "polecat canonical",
|
||||
address: "gastown/nux",
|
||||
want: AgentIdentity{Role: RolePolecat, Rig: "gastown", Name: "nux"},
|
||||
},
|
||||
{
|
||||
name: "invalid",
|
||||
address: "gastown/crew",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := ParseAddress(tt.address)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("ParseAddress(%q) error = %v", tt.address, err)
|
||||
}
|
||||
if *got != tt.want {
|
||||
t.Fatalf("ParseAddress(%q) = %#v, want %#v", tt.address, *got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user