deepstrike-core 0.2.63

Cross-language agent runtime kernel — pure computation, zero I/O
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
use super::*;

impl CanonicalOperationDriver {
    /// Apply one already-attributed request. Every arm reads its caller from `causation` and
    /// nothing else — there is no parameter through which a host could name a different one.
    pub(super) fn apply_syscall(
        &mut self,
        context: &PlanContext<'_>,
        causation: &SyscallCausation,
        request: &SyscallRequest,
        effect_index: &mut u32,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        let caller = causation_task(causation);
        let quarantined = self
            .engine
            .as_ref()
            .is_some_and(|engine| engine.task_quarantined(caller.as_str()));
        if quarantined && let Some(family) = privileged_family(request) {
            // §7.6 · a quarantined task read untrusted content. Letting it grow the DAG, mutate its
            // capability surface or reach memory would make the untrusted content the author of the
            // escalation. Fails closed on the whole family rather than trusting per-request
            // coercion to be exhaustive.
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                family,
                format!(
                    "quarantine: task {caller} is quarantined and may not widen its authority \
                     through a {family} syscall"
                ),
            )));
        }

        match request {
            SyscallRequest::SubmitWorkflow(submit) => {
                if submit.spec.nodes.is_empty() {
                    return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                        "start_workflow",
                        "an authored workflow with no nodes has nothing to spawn",
                    )));
                }
                if self
                    .engine
                    .as_ref()
                    .is_some_and(LoopStateMachine::workflow_active)
                {
                    // §10.2 flatten: the caller is already inside a DAG, so its spec grows that DAG
                    // rather than stacking a second one. One root lifecycle, one quota.
                    self.append_nodes(
                        context.config,
                        &submit.spec.nodes,
                        &caller,
                        CoreSyscall::LoadWorkflow { node_count: 0 },
                        "start_workflow",
                    )
                } else {
                    self.enter_nested_workflow(context, &submit.spec, effect_index)
                }
            }
            SyscallRequest::AppendWorkflowNodes(append) => {
                if append.nodes.is_empty() {
                    return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                        "submit_workflow_nodes",
                        "an empty submission appends nothing",
                    )));
                }
                if !self
                    .engine
                    .as_ref()
                    .is_some_and(LoopStateMachine::workflow_active)
                {
                    return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                        "submit_workflow_nodes",
                        "no workflow is in flight, so there is no graph to append to",
                    )));
                }
                self.append_nodes(
                    context.config,
                    &append.nodes,
                    &caller,
                    CoreSyscall::SubmitNodes { count: 0 },
                    "submit_workflow_nodes",
                )
            }
            SyscallRequest::ActivateSkill(activate) => {
                let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
                if !engine.ctx.skill_available(&activate.name) {
                    return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                        "skill",
                        format!(
                            "this operation declares no skill named {:?}; activation is a \
                             capability mutation and is refused rather than invented",
                            activate.name
                        ),
                    )));
                }
                ensure_skill_grants_are_attenuated(
                    engine.ctx.skill_capability_grants(&activate.name),
                    engine.task_capabilities(caller.as_str()),
                )
                .map_err(|violations| {
                    SyscallRefusal::Rejected(SyscallRejection::new(
                        "skill",
                        skill_grant_attenuation_message(&activate.name, &violations),
                    ))
                })?;
                let expires_at_turn = activate
                    .lease_turns
                    .map(|turns| engine.turn.saturating_add(turns));
                engine
                    .ctx
                    .activate_skill_leased(activate.name.as_str(), expires_at_turn);
                Ok(SyscallOutcome::default())
            }
            SyscallRequest::UpdateTask(update) => {
                let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
                engine.ctx.update_task(core_task_update(&update.update));
                Ok(SyscallOutcome::default())
            }
            SyscallRequest::RequestMemoryWrite(write) => {
                self.plan_memory_write(context, causation, &write.proposal, effect_index)
            }
            SyscallRequest::RequestMemoryQuery(query) => {
                self.plan_memory_query(context, causation, &query.query, effect_index)
            }
            SyscallRequest::PageIn(page_in) => {
                self.plan_page_in(context, &caller, &page_in.handle_id, effect_index)
            }
            SyscallRequest::SendMessage(send) => self.plan_send_message(&caller, send),
            SyscallRequest::PublishChannel(publish) => self.plan_publish_channel(&caller, publish),
            SyscallRequest::ReceiveMailbox(receive) => {
                self.plan_receive_mailbox(&caller, receive.limit)
            }
            SyscallRequest::ReceiveChannel(receive) => {
                self.plan_receive_channel(&caller, &receive.channel_id)
            }
            SyscallRequest::ReadObject(read) => self.plan_read_object(&caller, read.object_id),
        }
    }

    pub(super) fn plan_send_message(
        &mut self,
        caller: &TaskId,
        request: &super::super::syscall::SendMessageRequest,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        validate_ipc_labels(&request.message_id, &request.message_kind)?;
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let handle = resolve_ipc_handle(engine, &request.payload_handle)?;
        let descriptor =
            crate::mm::handle::ObjectDescriptor::from_handle(caller.as_str().into(), &handle, 1);
        if engine
            .task_table()
            .object(descriptor.id)
            .is_some_and(|existing| existing != &descriptor)
        {
            return Err(local_ipc_refusal(
                crate::scheduler::tcb::LocalIpcError::ObjectConflict,
            ));
        }
        let now = crate::scheduler::mailbox::LogicalTime(engine.turn);
        let message = crate::scheduler::mailbox::MailboxMessage {
            id: request.message_id.as_str().into(),
            from: caller.as_str().into(),
            to: request.to.as_str().into(),
            kind: request.message_kind.as_str().into(),
            payload_handle: handle.id,
            priority: crate::types::signal::Urgency::Normal,
            timestamp: now,
            expires_at: request
                .ttl_turns
                .map(|ttl| crate::scheduler::mailbox::LogicalTime(engine.turn.saturating_add(ttl))),
        };
        let accepted = engine
            .task_table_mut()
            .send_message_from(caller.as_str(), message, now)
            .map_err(local_ipc_refusal)?;
        engine
            .task_table_mut()
            .register_object(caller.as_str(), descriptor)
            .map_err(local_ipc_refusal)?;
        engine.observe_local_runnable_tasks();
        Ok(local_ipc_outcome(accepted))
    }

    pub(super) fn plan_publish_channel(
        &mut self,
        caller: &TaskId,
        request: &super::super::syscall::PublishChannelRequest,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        validate_ipc_labels(&request.message_id, &request.message_kind)?;
        if request.channel_id.is_empty() || request.subscribers.is_empty() {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "publish_channel",
                "channel_id and subscribers must be non-empty",
            )));
        }
        let mut subscribers: Vec<_> = request
            .subscribers
            .iter()
            .map(|id| id.as_str().into())
            .collect();
        subscribers.sort_unstable();
        subscribers.dedup();
        if subscribers.len() != request.subscribers.len() {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "publish_channel",
                "channel subscribers must be unique",
            )));
        }
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let handle = resolve_ipc_handle(engine, &request.payload_handle)?;
        let descriptor =
            crate::mm::handle::ObjectDescriptor::from_handle(caller.as_str().into(), &handle, 1);
        if engine
            .task_table()
            .object(descriptor.id)
            .is_some_and(|existing| existing != &descriptor)
        {
            return Err(local_ipc_refusal(
                crate::scheduler::tcb::LocalIpcError::ObjectConflict,
            ));
        }
        let now = crate::scheduler::mailbox::LogicalTime(engine.turn);
        let message = crate::scheduler::mailbox::MailboxMessage {
            id: request.message_id.as_str().into(),
            from: caller.as_str().into(),
            to: request.channel_id.as_str().into(),
            kind: request.message_kind.as_str().into(),
            payload_handle: handle.id,
            priority: crate::types::signal::Urgency::Normal,
            timestamp: now,
            expires_at: request
                .ttl_turns
                .map(|ttl| crate::scheduler::mailbox::LogicalTime(engine.turn.saturating_add(ttl))),
        };
        let accepted = engine
            .task_table_mut()
            .publish_channel(
                caller.as_str(),
                ChannelId(request.channel_id.as_str().into()),
                subscribers,
                message,
                now,
            )
            .map_err(local_ipc_refusal)?;
        engine
            .task_table_mut()
            .register_object(caller.as_str(), descriptor)
            .map_err(local_ipc_refusal)?;
        engine.observe_local_runnable_tasks();
        Ok(local_ipc_outcome(accepted))
    }

    pub(super) fn plan_receive_mailbox(
        &mut self,
        caller: &TaskId,
        limit: u32,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        if limit == 0 || limit > 64 {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "receive_mailbox",
                "limit must be between 1 and 64",
            )));
        }
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let now = crate::scheduler::mailbox::LogicalTime(engine.turn);
        let messages = engine
            .task_table_mut()
            .receive_mailbox(caller.as_str(), now, limit as usize)
            .map_err(local_ipc_refusal)?;
        Ok(ipc_messages_outcome(&messages))
    }

    pub(super) fn plan_receive_channel(
        &mut self,
        caller: &TaskId,
        channel_id: &str,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let now = crate::scheduler::mailbox::LogicalTime(engine.turn);
        let messages = engine
            .task_table_mut()
            .receive_channel(caller.as_str(), &ChannelId(channel_id.into()), now)
            .map_err(local_ipc_refusal)?;
        Ok(ipc_messages_outcome(&messages))
    }

    pub(super) fn plan_read_object(
        &mut self,
        caller: &TaskId,
        object_id: crate::mm::handle::ObjectId,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let descriptor = engine
            .task_table()
            .object(object_id)
            .cloned()
            .ok_or_else(|| {
                SyscallRefusal::Rejected(SyscallRejection::new(
                    "read_object",
                    format!("object {object_id} is not registered"),
                ))
            })?;
        if descriptor.owner.as_str() != caller.as_str()
            && !crate::mm::handle::object_access_allowed_at(
                engine.task_capabilities(caller.as_str()),
                "read",
                &descriptor,
                engine.turn,
            )
        {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "read_object",
                format!("caller {caller} has no read capability for object {object_id}"),
            )));
        }
        Ok(SyscallOutcome {
            ack: Some(
                serde_json::to_string(&descriptor)
                    .expect("canonical object descriptors are serializable"),
            ),
            ..SyscallOutcome::default()
        })
    }

    /// §10.3 · gate + trust-aware append, with the spawn round deferred to the caller.
    pub(super) fn append_nodes(
        &mut self,
        config: &ResolvedOperationConfig,
        nodes: &[WireNode],
        caller: &TaskId,
        syscall: CoreSyscall,
        label: &'static str,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        // §7.3 · an authored node may not name a contract the operation never declared. Same rule
        // as a root spec, and checked on the same side of the gate as identity/acyclicity: a batch
        // with a dangling reference is malformed and must not spend quota.
        for node in nodes {
            self.require_known_contract(config, node.run_spec.as_ref())
                .map_err(|fault| {
                    SyscallRefusal::Rejected(SyscallRejection::new(label, fault.message))
                })?;
        }
        // Batch-relative identity and acyclicity are checked before the gate sees a count, so a
        // malformed batch never spends quota.
        let core_nodes = build_core_spec(&WireSpec {
            name: String::new(),
            nodes: nodes.to_vec(),
        })
        .map_err(|fault| SyscallRefusal::Rejected(SyscallRejection::new(label, fault.message)))?
        .nodes;

        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let admitted = engine.append_workflow_nodes(
            core_nodes,
            // §7.6 · the submitter is the derived caller, never an optional host field. The
            // historical `submitter_agent_id: Option<String>` erred open — omitting it skipped the
            // quarantine coercion entirely — and there is no shape here that can omit it.
            Some(caller.as_str()),
            // `append_workflow_nodes` refills the count from the batch, so the two entry points
            // cannot disagree about what they meter.
            syscall,
            label,
        );
        if !admitted {
            // `append_workflow_nodes` already pushed the rejection observation and the model-facing
            // note; re-recording it here would double the audit fact.
            return Ok(SyscallOutcome::default());
        }
        // §10.3 · deterministic node identity is a kernel fact. An appended batch lands at the end
        // of the index-addressed DAG, so mirroring its wire ids here is what lets a later spawn
        // effect and the workflow terminal still name the node the caller declared — rather than
        // falling back to the internal `wf-nodeN` id.
        self.node_ids
            .extend(nodes.iter().map(|node| node.node_id.clone()));
        self.workflow_nodes.extend_from_slice(nodes);
        Ok(SyscallOutcome {
            effects: Vec::new(),
            focus: None,
            needs_workflow_round: true,
            ack: None,
        })
    }

    pub(super) fn plan_memory_write(
        &mut self,
        context: &PlanContext<'_>,
        causation: &SyscallCausation,
        proposal: &super::super::syscall::MemoryWriteProposal,
        effect_index: &mut u32,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        let Some(binding) = context.config.memory_access.clone() else {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "write_memory",
                "this operation holds no memory binding, so it can author no memory record",
            )));
        };
        if !binding.capabilities.write {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "write_memory",
                "this operation's memory binding is read-only",
            )));
        }
        self.require_effect_support(context.config, EffectKindTag::PersistMemory)
            .map_err(SyscallRefusal::Fault)?;
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        let disposition = engine.gate_memory_write_proposal();
        if !disposition.is_allowed() {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "write_memory",
                denial_reason(&disposition, "memory write denied"),
            )));
        }
        // §22.13 · the proposal contributed name/kind/content/evidence and nothing else. Tenant,
        // author, trust, timestamp and provenance are authored here, from the operation's binding,
        // the envelope's accepted time and the derived causation.
        let authored = AuthoredMemoryWrite {
            binding_id: binding.binding_id.clone(),
            name: proposal.name.clone(),
            kind: proposal.kind,
            size_bytes: proposal.content.len() as u32,
        };
        let effect = EffectKind::PersistMemory(PersistMemoryEffect {
            binding,
            memory: CanonicalMemoryWrite {
                name: proposal.name.clone(),
                kind: proposal.kind,
                content: proposal.content.clone(),
                description: proposal.description.clone(),
                evidence_refs: proposal.evidence_refs.clone(),
                accepted_at_ms: context.input.observed_at_ms,
                causation: causation.clone(),
            },
        });
        let published = self.mint_effect(context, effect, effect_index);
        self.pending_memory_writes
            .insert(published.effect_id.clone(), authored);
        Ok(SyscallOutcome {
            effects: vec![published],
            focus: None,
            needs_workflow_round: false,
            ack: None,
        })
    }

    pub(super) fn plan_memory_query(
        &mut self,
        context: &PlanContext<'_>,
        causation: &SyscallCausation,
        proposal: &super::super::syscall::MemoryQueryProposal,
        effect_index: &mut u32,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        let Some(binding) = context.config.memory_access.clone() else {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "query_memory",
                "this operation holds no memory binding, so it can read no memory record",
            )));
        };
        if !binding.capabilities.read {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                "query_memory",
                "this operation's memory binding is write-only",
            )));
        }
        self.require_effect_support(context.config, EffectKindTag::QueryMemory)
            .map_err(SyscallRefusal::Fault)?;
        // The retrieval width is the operation's policy, clamped — the host does not re-decide it
        // and a model cannot widen it by asking for more.
        let ceiling = context.config.memory_policy.retrieval_top_k;
        let requested_k = proposal.limit.unwrap_or(ceiling).clamp(1, ceiling);
        let authored = AuthoredMemoryQuery {
            binding_id: binding.binding_id.clone(),
            text: proposal.text.clone(),
            requested_k,
        };
        let effect = EffectKind::QueryMemory(QueryMemoryEffect {
            binding,
            query: CanonicalMemoryQuery {
                text: proposal.text.clone(),
                kinds: proposal.kinds.clone(),
                accepted_at_ms: context.input.observed_at_ms,
                causation: causation.clone(),
            },
            requested_k,
        });
        let published = self.mint_effect(context, effect, effect_index);
        self.pending_memory_queries
            .insert(published.effect_id.clone(), authored);
        Ok(SyscallOutcome {
            effects: vec![published],
            focus: None,
            needs_workflow_round: false,
            ack: None,
        })
    }

    /// §7.6 / §7.10 rule 4 · `read_result` reduces to exactly one thing: a `LoadPayload` effect for
    /// a body the caller already holds an address for.
    ///
    /// Two refusals, both *rejections* rather than faults — the caller was established, so what is
    /// refused is the address it named, and the transition that carried it still commits with an
    /// audit fact the model reads on its next turn:
    ///
    /// - an address that is not in this operation's handle table. A page-in reaches only what the
    ///   caller already holds, which is what stops `read_result` from becoming a general read
    ///   primitive — the historical SDK answered it by scanning a spool directory and then the
    ///   session log, so any path-shaped string was a readable address.
    /// - an address whose body core still holds. `Resident` and `Collapsed` are not paged out at
    ///   all. Neither yields a locator the kernel could hand back,
    ///   and fabricating one is exactly the confusion the closed union removes.
    pub(super) fn plan_page_in(
        &mut self,
        context: &PlanContext<'_>,
        caller: &TaskId,
        handle_id: &super::super::scalar::HandleId,
        effect_index: &mut u32,
    ) -> Result<SyscallOutcome, SyscallRefusal> {
        let engine = self.engine_mut().map_err(SyscallRefusal::Fault)?;
        if let Some(handle) = engine.ctx.handles.all().iter().find(|handle| {
            handle.source.as_deref() == Some(handle_id.as_str())
                || handle.id.to_string() == handle_id.as_str()
        }) && let Some(descriptor) = engine.task_table().object(handle.id)
            && descriptor.owner.as_str() != caller.as_str()
            && !crate::mm::handle::object_access_allowed_at(
                engine.task_capabilities(caller.as_str()),
                "read",
                descriptor,
                engine.turn,
            )
        {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                READ_RESULT_TOOL_NAME,
                format!(
                    "caller {caller} has no read capability for shared object {}",
                    descriptor.id
                ),
            )));
        }
        let Some(residency) = engine.ctx.payload_residency(handle_id.as_str()).cloned() else {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                READ_RESULT_TOOL_NAME,
                format!(
                    "handle {handle_id} is not reachable in this operation's handle table; a \
                     page-in addresses only what the caller already holds"
                ),
            )));
        };
        let (Some(payload_ref), Some(digest)) = (residency.payload_ref(), residency.digest())
        else {
            return Err(SyscallRefusal::Rejected(SyscallRejection::new(
                READ_RESULT_TOOL_NAME,
                format!(
                    "handle {handle_id} is {} — its body is held by this kernel, not by the \
                     payload store, so there is nothing to page in",
                    residency.label()
                ),
            )));
        };
        let payload_ref = PayloadRef::new(payload_ref).map_err(|error| {
            SyscallRefusal::Fault(KernelFault::new(
                KernelFaultCode::MalformedEnvelope,
                format!(
                    "handle {handle_id} records an unusable payload locator: {}",
                    error.message
                ),
            ))
        })?;
        self.require_effect_support(context.config, EffectKindTag::LoadPayload)
            .map_err(SyscallRefusal::Fault)?;
        let effect = EffectKind::LoadPayload(LoadPayloadEffect {
            handle_id: handle_id.clone(),
            payload_ref,
        });
        let published = self.mint_effect(context, effect, effect_index);
        self.pending_payload_loads.insert(
            published.effect_id.clone(),
            PendingPayloadLoad {
                handle_id: handle_id.as_str().to_string(),
                digest: digest.to_string(),
                original_size: match &residency {
                    Residency::External { original_size, .. } => Some(*original_size),
                    _ => None,
                },
            },
        );
        Ok(SyscallOutcome {
            effects: vec![published],
            focus: None,
            needs_workflow_round: false,
            ack: None,
        })
    }

    /// Record a refused request as an audit fact the model reads on its next turn (§7.6, §7.7).
    pub(super) fn note_rejection(&mut self, rejection: SyscallRejection) {
        let Some(engine) = self.engine.as_mut() else {
            return;
        };
        let note = crate::scheduler::rollback::build_control_rejection_note(
            rejection.operation,
            &rejection.reason,
            engine.ctx.config.verbose_control_notes,
        );
        engine.ctx.push_signal(note);
        let turn = engine.turn;
        engine
            .observations
            .push(KernelObservation::ControlRequestRejected {
                turn,
                operation: rejection.operation.to_string(),
                subject: rejection.subject,
                reason: rejection.reason,
            });
    }
}