MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / write_watch_notice

Method write_watch_notice

atomic-agent/src/turn/session.rs:1182–1218  ·  view source on GitHub ↗

Write one pending shim-watch notice for a session (CB-13D). The optional metadata-only shim watch daemon (RFC §11.2 rule 6) calls this when it detects an external Git transition or an unsafe state while a managed session is active. The notice is a separate pending file — it never mutates the session state file the orchestrator owns, so the daemon cannot clobber orchestrator state. The orchestrato

(
        &self,
        session_id: &str,
        kind: &str,
        detail: &str,
        remediation: &str,
    )

Source from the content-addressed store, hash-verified

1180 /// The orchestrator drains the file at the session's next turn start or
1181 /// tool call; until then the notice is purely additive evidence.
1182 pub fn write_watch_notice(
1183 &self,
1184 session_id: &str,
1185 kind: &str,
1186 detail: &str,
1187 remediation: &str,
1188 ) -> AgentResult<()> {
1189 validate_session_id(session_id)?;
1190 let notices = self.sessions_dir.join(WATCH_NOTICES_DIRECTORY);
1191 std::fs::create_dir_all(&notices)?;
1192 let notice = WatchNotice {
1193 version: WATCH_NOTICE_VERSION,
1194 record_type: WATCH_NOTICE_RECORD_TYPE.to_string(),
1195 session_id: session_id.to_string(),
1196 kind: kind.to_string(),
1197 detail: detail.to_string(),
1198 remediation: remediation.to_string(),
1199 recorded_at: Utc::now().to_rfc3339(),
1200 };
1201 let path = self.watch_notice_path(session_id);
1202 // A per-writer unique temporary name (review R6): two concurrent
1203 // daemon instances (or a daemon and a command) must never share the
1204 // same `.tmp` name — a shared name lets one writer's rename publish
1205 // another writer's partially-written bytes.
1206 let tmp = path.with_extension(format!(
1207 "json.{}.{}.tmp",
1208 std::process::id(),
1209 WATCH_NOTICE_SEQUENCE.fetch_add(1, Ordering::Relaxed)
1210 ));
1211 let bytes = serde_json::to_vec(&notice)?;
1212 std::fs::write(&tmp, bytes)?;
1213 // rename(2) publishes the complete notice atomically; a newer
1214 // notice replaces an older pending one without any reader seeing a
1215 // partial file.
1216 std::fs::rename(&tmp, &path)?;
1217 Ok(())
1218 }
1219
1220 /// Take the pending shim-watch notice for a session, if any (CB-13D).
1221 ///

Calls 3

validate_session_idFunction · 0.85
watch_notice_pathMethod · 0.80
writeFunction · 0.50