--- id: "bug-1627" status: "fixed" status_updated: "2026-09-24" status_note: "" component: "controller" severity: "unknown" timestamp: "2026-08-23T05:35:00Z" last_seen: "2026-09-19T09:00:00Z" occurrences: 3 files: ["src/controller/job.c"] tags: ["controller", "reference-counting", "memory-leak", "refcount", "dispatch_a_job_", "pre-existing"] related: ["bug-1626"] legacy: true --- # bug-1627: None yet observed at runtime -- found via code trace during round 3/4 of /kiro-validate-design… ## Description None yet observed at runtime -- found via code trace during round 3/4 of /kiro-validate-design review of scheduler-dispatch-commit. ## Environment _Not recorded (migrated from buglog.json)._ ## Reproduction _Not recorded (migrated from buglog.json)._ ## Root cause dispatch_a_job_() (job.c:831-963) calls reference(j) at line 854 after successfully looking up the job. On FOUR of its failure/return paths it never calls a matching dereference(j): workermgr key_find() failing (rc<0, line 888-890), the worker not being found (w==NULL, line 892-894), the worker not being in a ready state (E_XCE_BAD_WORKER, line 897-909), and xce_startjob_req() itself failing (rc<0, line 956-960 -- found in a later review pass than the first three). (Contrast: the nc<=0 path at line 869-873 and the get_queue_exec() failure path at line 917-925 both correctly dereference(j) before returning.) Each occurrence permanently leaks one reference on the job object. Separately and NOT included in this bug (flagged as a distinct open question, not a confirmed defect): the function also never calls dereference(j) on its normal SUCCESS return path -- this may be an intentional reference hand-off to the job entering its dispatched/running lifetime rather than a bug, and needs its own investigation rather than being folded in here. ## Fix FIXED -- scheduler-dispatch-commit task 3.3. dispatch_a_job_() (job.c) now closes all four leak sites as part of the retryable-failure classify/resolve restructuring the bug's own notes anticipated: XCE_DISPATCH_FAIL_SITE_WORKER_LOOKUP, _WORKER_NULL, _WORKER_NOT_READY, and _RPC_FAILURE each now lock(j, RTTI_LOCK_WRITE), classify via xce_classify_dispatch_fail(), increment job.dispatch_fail_count under that lock, resolve retryable (within XCE_DISPATCH_FAIL_RETRY_BOUND==3) or terminal (mark_job_fail(), mirroring task 3.2's two sibling terminal sites) as appropriate, unlock(j), then dereference(j) -- closing the leak uniformly across all four. Regression-tested via test_dispatch_fail_retry.c's canary-reference technique (task 3.2's own established pattern) at three of the four sites (WORKER_LOOKUP/WORKER_NULL share one test since a black-box test cannot force which of the two an unregistered worker key actually triggers -- both share the identical resolution code shape). RED confirmed first (all 4 new tests failed against the unmodified four sites, git-stash verified), then GREEN after the fix, full controller_unit_test suite run (1056 tests, filtered only for the pre-existing bug-1429 hang) showed zero new failures beyond the pre-existing bug-1561 pair. ## Verification _Not recorded (migrated from buglog.json)._ ## References - Related: bug-1626