Failed delivery replacement leaves freed strings owned by the scheduler
perfloop-oss/nullclaw · Premature Release
https://perfloop.ai/t/oss/case_j4xaaw9hyn
Verdict
VALIDATED BY A DIFFERENT CHANGE · settled 2026-11-02 · pull request opened as nullclaw/nullclaw#1090
What happened: The check fails before this change and passes with it.
Hypothesis
An allocation failure while replacing an existing job's delivery settings can turn scheduler cleanup into a second free of the same memory. This affects persistence after a changed scheduler tick. Its occurrence under real memory pressure is unmeasured; no native allocation-failure counterexample has been run here.
In upsertSchedulerRuntimeJob, the existing-job branch frees an owned delivery.channel before evaluating the fallible duplicate assigned to that same field. If that duplicate fails, assignment does not finish and both the old pointer and its ownership flag remain. The same sequence exists for account_id, to, peer_id and thread_id. mergeSchedulerTickChangesAndSave has already deferred latest.deinit, whose CronScheduler.freeJobOwned frees those flagged pointers. A job read from cron.json with a non-null delivery channel supplies the required owned destination; this does not require concurrent memory access or an unsupported caller.
I first considered removing delivery replacement altogether, since CronScheduler.tick does not modify those settings. The upsert nevertheless explicitly propagates runtime routing, and its missing-job regression requires agent-field preservation. Removing that behavior needs a separate merge-contract proof. This narrower contribution addresses the entire five-field replacement class without changing the store format, routing contract or retry policy. The added complexity is local staging and cleanup, not a new subsystem.
The durable ownership property is prop_94xkrhz5qk. The allocator parameter is an existing injection point, but both the upsert and merge are private Zig functions. The new-file-only property guide therefore prevents adding a direct fault check without a product seam edit. The attempted run of the two committed merge fixtures printed an integer-overflow panic in the external-job fixture and timed out; that unresolved run is neither a confirmation nor a refutation of this ownership defect.
The smallest useful Case check is an in-module std.testing.FailingAllocator test: load one delivery-bearing job, fail each replacement copy in turn, and allow normal merge teardown. Confirm that the baseline reports a duplicate free or invalid owned pointer, then require clean teardown after repair. Verify cron.json is byte-identical for failures before saveJobs, and verify all delivery and scheduling values after a successful retry. An error exit that leaves every owned pointer valid would reject the claimed lifetime mechanism.
The current open-PR pages were checked through their final page. Actual daemon hunks in https://github.com/nullclaw/nullclaw/pull/1058, https://github.com/nullclaw/nullclaw/pull/1061, https://github.com/nullclaw/nullclaw/pull/1068, https://github.com/nullclaw/nullclaw/pull/1069, https://github.com/nullclaw/nullclaw/pull/1071 and https://github.com/nullclaw/nullclaw/pull/1075 change streaming, reactions, stop handling or startup logging, not scheduler upserts. Their linked tracking issue https://github.com/nullclaw/nullclaw/issues/1066 does not own this repair. Targeted prior-repair searches for this owner and scheduler merge allocation cleanup returned no overlap.
Change to test: Stage all replacement delivery strings under a single rollback-cleaned owner, then commit the replacement only after every required copy succeeds. Establish safe teardown and unchanged persisted state for each pre-save allocation failure while preserving successful merge behavior.
Where it lives
perfloop-oss/nullclaw · src/daemon.zig
Evidence
The check fails before this change and passes with it: `When an existing scheduler job has five owned nonempty delivery strings and each replacement is nonempty, failing any one replacement allocation returns OutOfMemory and leaves teardown with valid ownership.`
The check passes with this change: `For a stored existing agent job with five owned nonempty delivery strings and nonempty replacements, failing each delivery-copy allocation during merge returns OutOfMemory, keeps teardown ownership balanced and store bytes unchanged, and a successful retry persists the runtime routing and scheduling values.`
Checks: 2 of 2 passed. Verification: no defect found.
Timeline
2026-11-02· Case opened2026-11-02· PR opened