interrupt-routing

Interrupt routing: what Ctrl-C means without signals

Status: DECIDED 2026-07-28 (calef), then BUILT: the two-tier design (option C), interrupt capability held by the shell, Tcb::SUSPEND still deferred. See DECISIONS §24 and its implementation amendment for what shipped. The cooperative tier is a shared-memory flag, not the endpoint notification this proposal imagined, because a running compute job cannot poll an endpoint. The forcible tier is Untyped::DESTROY on a region the shell holds. This document stays as the original design record. Milestone 28 (a solid terminal) built the terminal that detects ^C and wrote down the contract's hook for it (FLAG_INTERRUPTED), and deliberately stopped there. How the interrupt actually reaches the foreground process is a capability-routing question with real forks, and this project's answer will not be Unix signals. This note frames the problem, lays out candidate mechanisms, reads the prior art, and recommends a direction. It builds no kernel mechanism.

The problem

A user runs a command and it takes too long, or hangs, or is a mistake. They press ^C and expect the foreground computation to stop and the prompt to come back. In Unix the tty line discipline turns ^C into SIGINT and sends it to the foreground process group, named by PID. That is ambient authority in two layers: the tty may signal any process in its group, and a process is reachable by a global identifier it did not hand anyone. nife rejects both (DECISIONS §10 (process model: capability-based, microkernel), nifeos/nife:notes/ipc-naming.md): there are no PIDs to signal and no global namespace to reach a process through. So the question is sharp: when the user presses ^C, whose right is it to interrupt which process, and what capability carries that right?

Two cases, and the split is the whole difficulty:

  1. The foreground process is blocked reading. This one is already handled. The terminal fails the parked OPERATION_READLINE with FLAG_INTERRUPTED; the shell sees it, discards the line, and reprompts. No process was doing work, so there is nothing to stop. line_editor does this today.
  2. The foreground process is running. A runaway loop, a long compute, a wedged driver call. There is no outstanding read to fail. Interrupting it means reaching a process that is not asking to be reached, which is exactly the authority Unix grants ambiently and we do not.

Everything below is about case 2.

What must be true of any answer

Candidate mechanisms

A. A cooperative interrupt notification (async, endpoint-delivered)

When the shell puts a process in the foreground, it gives the terminal an interrupt endpoint that the foreground process is watching (or that the kernel delivers an async notification to, the same way an interrupt becomes a message: interrupts.md). On ^C the terminal notifies it. The process handles the notification at a safe point and unwinds: it prints, frees what it holds, and returns to the shell.

B. A forcible abort capability (the holder can tear the job down)

The foreground job is represented by a capability the terminal holds that can destroy or suspend it. Either the job's Tcb capability with a suspend/kill method, or a revocable "job" capability whose revocation reclaims the job's objects (DECISIONS §13 (capability revocation) and §16 (object revocation), which already reclaim a process's frames and objects). On ^C, the terminal invokes it; the job stops regardless of what it was doing.

C. Two-tier: cooperative first, forcible on escalation

Combine them. ^C delivers the cooperative notification (A). If the job does not yield within a window (a second ^C, or a timeout), the terminal escalates to the forcible capability (B). This is close to how a real shell feels: the first ^C asks nicely, a second one insists.

Who holds the capability: terminal or shell?

Orthogonal to A/B/C. The interrupt right can live with the terminal (it detects ^C, so it acts directly, lowest latency) or with the shell (the terminal reports the interrupt as an event, and the shell, which owns job control, decides). The shell is the more principled home, because "what is the foreground job" is the shell's knowledge, not the terminal's, and milestone 31 makes the shell the authority on grants. The cost is one more hop (^C becomes an event the shell must be waiting for) and a shell that must multiplex reading its next line against watching for an interrupt. A pragmatic split: the terminal reports FLAG_INTERRUPTED (case 1) itself, and routes case 2 to the shell, which holds the job's interrupt capability.

Prior art

Recommendation

Adopt C (two-tier), with the interrupt capability held by the shell, and reuse existing primitives rather than inventing a signal:

  1. The cooperative tier is an async notification on an endpoint the foreground job watches, built from the same "interrupt becomes a message" machinery as interrupt delivery. A job that wants graceful interruption receives it; a job that does not care simply never registers, and the escalation covers it.
  2. The forcible tier is object revocation / a Tcb suspend-or-destroy method on the job, scoped to exactly the foreground job. This is where the model may need one genuinely new method (a TCB SUSPEND, if we want suspend-and-report rather than destroy), which would be its own DECISIONS entry because it widens the §4 boundary. Destroy-and-reprompt needs nothing new.
  3. The shell holds both capabilities for the current job and surrenders them when the job ends. The terminal handles case 1 (FLAG_INTERRUPTED on a parked read) itself and routes case 2 to the shell.

The open decisions for an architect, which is why this is not built:

None of these should be settled by building through them. They are the substance the milestone-28 roadmap entry called "kernel-adjacent," and they want a decision before code.