Address review: a Go for a target the helper does not hold is refused

The bounded record of answered targets evicted its oldest entry, and a
generate event naming an unrecognized target was admitted, so a Go
delayed past enough later resolutions could still open a session for
a request the CLI had reported as failed.

The admission rule is now positive: a generate event naming an agent
target is welcome only while that target is pending without a rival
lease, or when it comes from the session that answered it. Unknown
targets, evicted or never issued, are refused like any other superseded
Go, so eviction can never reopen a request. The record keeps 256
entries for the answering session's sake.

Tests: a Rust integration case and a Node protocol case (an envelope
naming an unheld target is refused and journals nothing; the same event
without an envelope is an ordinary Go); contract doc updated.

Written with AI assistance (Claude).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Abdul Wahab
2026-09-15 05:45:49 +05:00
committed by Abdul Wahab
co-authored by Claude Fable 5
parent 76db418212
commit d579ecb2f2
4 changed files with 49 additions and 12 deletions
+17
View File
@@ -582,3 +582,20 @@ fn agent_target_fences_a_generate_event_that_lands_after_the_timeout() {
assert!(body.get("sessionId").is_none(), "{body}");
assert!(!s.dir.join(".impeccable/live/sessions/eeeeeeee.jsonl").exists());
}
#[test]
fn agent_target_refuses_a_generate_event_for_a_target_it_never_held() {
// Unknown means refused: a target this helper never issued, or one
// evicted from its bounded record, can never be reopened by a late Go.
let s = Server::start("unknown-target");
let (status, body) = post_json(s.port, "/events", generate_event_for(&s, "0badf00d", "ffffffff", "tab-a"));
assert_eq!(status, 409, "{body}");
assert_eq!(body["error"], serde_json::json!("agent_target_already_served"));
assert!(body.get("sessionId").is_none(), "{body}");
assert!(!s.dir.join(".impeccable/live/sessions/ffffffff.jsonl").exists());
// Without an envelope the same event is an ordinary Go.
let mut plain = generate_event_for(&s, "0badf00d", "ffffffff", "tab-a");
plain.as_object_mut().unwrap().remove("agentTarget");
let (status, _) = post_json(s.port, "/events", plain);
assert_eq!(status, 200);
}