fix question answer sender and self-cancel feedback loop
This commit is contained in:
parent
e50173f3e1
commit
d8e64742f4
3 changed files with 31 additions and 12 deletions
|
|
@ -532,6 +532,14 @@ impl Coordinator {
|
||||||
/// events back to the agent that called `ask`, `QuestionAsked`
|
/// events back to the agent that called `ask`, `QuestionAsked`
|
||||||
/// events to the target of a peer question, etc.
|
/// events to the target of a peer question, etc.
|
||||||
pub fn notify_agent(&self, agent: &str, event: &hive_sh4re::HelperEvent) {
|
pub fn notify_agent(&self, agent: &str, event: &hive_sh4re::HelperEvent) {
|
||||||
|
self.notify_agent_from(hive_sh4re::SYSTEM_SENDER, agent, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same as `notify_agent` but with an explicit sender. Use this
|
||||||
|
/// when the event originates from a known agent or the operator
|
||||||
|
/// (e.g. `QuestionAnswered` — the answerer should be the `from`,
|
||||||
|
/// not `system`) so the recipient's terminal shows the right name.
|
||||||
|
pub fn notify_agent_from(&self, from: &str, agent: &str, event: &hive_sh4re::HelperEvent) {
|
||||||
let body = match serde_json::to_string(event) {
|
let body = match serde_json::to_string(event) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -540,7 +548,7 @@ impl Coordinator {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = self.broker.send(&hive_sh4re::Message {
|
if let Err(e) = self.broker.send(&hive_sh4re::Message {
|
||||||
from: hive_sh4re::SYSTEM_SENDER.to_owned(),
|
from: from.to_owned(),
|
||||||
to: agent.to_owned(),
|
to: agent.to_owned(),
|
||||||
body,
|
body,
|
||||||
in_reply_to: None,
|
in_reply_to: None,
|
||||||
|
|
|
||||||
|
|
@ -865,7 +865,8 @@ async fn post_cancel_question(
|
||||||
true,
|
true,
|
||||||
target.as_deref(),
|
target.as_deref(),
|
||||||
);
|
);
|
||||||
state.coord.notify_agent(
|
state.coord.notify_agent_from(
|
||||||
|
hive_sh4re::OPERATOR_RECIPIENT,
|
||||||
&asker,
|
&asker,
|
||||||
&hive_sh4re::HelperEvent::QuestionAnswered {
|
&hive_sh4re::HelperEvent::QuestionAnswered {
|
||||||
id,
|
id,
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,10 @@ pub fn handle_answer(
|
||||||
.answer(id, answer, answerer)
|
.answer(id, answer, answerer)
|
||||||
.map_err(|e| format!("{e:#}"))?;
|
.map_err(|e| format!("{e:#}"))?;
|
||||||
tracing::info!(%id, %answerer, %asker, "question answered");
|
tracing::info!(%id, %answerer, %asker, "question answered");
|
||||||
coord.notify_agent(
|
// Use answerer as the broker `from` so the asker's terminal shows
|
||||||
|
// the real name (agent or "operator") instead of "system".
|
||||||
|
coord.notify_agent_from(
|
||||||
|
answerer,
|
||||||
&asker,
|
&asker,
|
||||||
&hive_sh4re::HelperEvent::QuestionAnswered {
|
&hive_sh4re::HelperEvent::QuestionAnswered {
|
||||||
id,
|
id,
|
||||||
|
|
@ -149,7 +152,13 @@ pub fn handle_cancel_loose_end(
|
||||||
.map_err(|e| format!("{e:#}"))?;
|
.map_err(|e| format!("{e:#}"))?;
|
||||||
let sentinel = format!("[cancelled by {canceller}]");
|
let sentinel = format!("[cancelled by {canceller}]");
|
||||||
tracing::info!(%id, %canceller, %asker, "question cancelled");
|
tracing::info!(%id, %canceller, %asker, "question cancelled");
|
||||||
coord.notify_agent(
|
// Only notify the asker if they didn't cancel it themselves.
|
||||||
|
// Self-cancels are already known to the canceller — sending
|
||||||
|
// a QuestionAnswered back would cause the harness to process
|
||||||
|
// its own cancel as an incoming answer.
|
||||||
|
if asker != canceller {
|
||||||
|
coord.notify_agent_from(
|
||||||
|
canceller,
|
||||||
&asker,
|
&asker,
|
||||||
&hive_sh4re::HelperEvent::QuestionAnswered {
|
&hive_sh4re::HelperEvent::QuestionAnswered {
|
||||||
id,
|
id,
|
||||||
|
|
@ -158,6 +167,7 @@ pub fn handle_cancel_loose_end(
|
||||||
answerer: canceller.to_owned(),
|
answerer: canceller.to_owned(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
coord.emit_question_resolved(id, &sentinel, canceller, true, target.as_deref());
|
coord.emit_question_resolved(id, &sentinel, canceller, true, target.as_deref());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue