flan/test/programs/agent-nostart.flan
Joseph Ferano 77d6e43b09 The agent binds before main, so a dev program need not start it at all
A constructor in the agent package binds FLAN_AGENT_SOCKET when it is set,
which is the daemon and nothing else — both shapes set it, before the fork in
--two-process and before the exec in the merged build. So a program under
[flan dev] that calls (agent/poll) and has no (agent/start) in it takes
redefinitions anyway, and one that does call start meets an agent that is
already listening and gets a no-op.

The window this closes was the complaint in DISCUSS.org: a program that opens
a window before starting its agent leaves the daemon waiting on a socket that
does not exist yet. Bound here, the socket exists before main whatever the
program does afterwards — so test_dev.ml's late-agent row asserts the negation
of what it used to. The delivery sent during the sleep no longer carries "the
program has not called (agent/start ...) yet", because that is no longer true
of it; what is still late, and still asserted, is the poll that installs it.

It reaches exactly as far as the linker does. Reach prunes a package nothing
calls into, so a program that mentions the agent nowhere does not link this
file and has no constructor to run: auto-start is for a program that polls and
has dropped its start call, not for one that says nothing about the agent at
all. That limit and the release-build residual are in FIX.org, along with the
daemon branch that can no longer be reached.

agent-nostart.flan is the pin, and its two numbers are the honest ones: 1
before anything could arrive, 1000 after the wait, because a listener bound
before main is still not an install.
2026-09-20 19:52:34 +07:00

28 lines
1020 B
Plaintext

;;;; A program with no (agent/start) in it at all, which still takes a
;;;; redefinition.
;;;;
;;;; The listener comes from the package's constructor, which binds
;;;; FLAN_AGENT_SOCKET when the daemon has set it — so under [flan dev] there
;;;; is nothing to call and nothing to forget. Installing is still the
;;;; program's own decision and still happens where it says: [wait] is the
;;;; headless spelling of the poll at the top of a frame, and the second number
;;;; below cannot appear before it.
;;;;
;;;; It does import the agent and it does call into it. That is not an accident
;;;; of how the fixture was written: [Reach] prunes a package nothing calls, so
;;;; an executable that mentions the agent nowhere does not link the
;;;; constructor either. See flan_agent.c's [auto_start].
(import agent "vendor:agent")
(defvar ticks i64)
(defn tick [] i64
(set ticks (+ ticks 1))
ticks)
(defn main [] i32
(print (tick)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (tick)) (println "")
0)