Skip to content

fix(schedule): the Schedule tool on every schedule-capable session (ADR 0076) - #314

Merged
JAORMX merged 6 commits into
mainfrom
acc/schedule-shared-catalog
Jul 28, 2026
Merged

JAORMX merged 6 commits into
mainfrom
acc/schedule-shared-catalog

Conversation

@JAORMX

@JAORMX JAORMX commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

Fixes the reported bug: in-chat scheduling was unreachable from the default mecatui session. "Schedule a check for new issues in 5 minutes" had no Schedule tool to call and no prompt note mentioning one — despite the scheduler ticking and the store backing a ScheduleStore.

Root cause

ADR 0073 decision 1 registers the Schedule tool "for every session that has a backing ScheduleStore, exactly like the six memory tools." The implementation broke that for the shared-engine fast path (a default-profile, zero-selector session — what a plain mecatui launch creates):

  • The shared engine's catalog is assembled inside buildEngine → buildCatalog → assembleCatalog, before server.NewService exists.
  • The port.ScheduleManager the tool drives was only late-bound onto the catalog assets after NewService (the "chicken-and-egg").
  • A covering comment claimed "any schedule-capable session routes through a per-session engine" — but sessionNeedsPerFactory has no schedule arm, and needsRehydration restores a restarted default session onto the shared engine.

Root cause was a shape error: schedule capability was treated as Service-shaped (resolvable only after NewService) when it is store-shaped — every construction input is available before buildEngine.

The fix (ADR 0076)

  1. Store-shaped pre-Service scheduleManager (internal/adapter/server/schedule_manager.go): the nine port.ScheduleManager methods + the validated create-seam moved verbatim off *Service. Constructed from the store + now-func before buildEngine; the scheduler + model-inventory are late-set atomic fields. *Service delegates — the RPC surface is byte-identical.
  2. Eager factory bind: assets.scheduleManagerFactory is bound before buildEngine, so registerScheduleTool fires on the build-time pass and the shared catalog gains Schedule + ScheduleQuery — the same conditional-registration shape as the memory tools. The late-bind + stale comment are deleted.
  3. Shared-engine prompt note (ADR 0070): applySchedulePosture applied to the shared engine under the same gate, so the model is told the tool exists.

Every schedule-capable session — shared engine or per-session, on create and on restart-rehydration — now carries the tool. mecated / mecatui / mecak8s (all compose app.Build) inherit the fix with no flag.

Plan + acceptance

docs/acceptance/schedule-shared-catalog.md (landed) — 3 scenarios, 11 ACs, all verify: proofs green under task ac-trace-strict. New ADR-0076 records the "store-shaped, not Service-shaped" decision + the rejected converge-on-per-session-factory alternative.

Panel review

Three-axis panel (Spec / Standards / Domain): 0 ship-blockers. Spec: every AC implemented, no missing/wrong. Standards: no hard violations (layering, diagnostics, ONE-registration-path, typed-nil discipline all hold). Domain: one Medium (architect) — the manager's now-func and the Service's cfg.Now are independent copies that could diverge if composition ever threads a clock; latent today (no clock is threaded — both default to time.Now), recorded as a judgement call for a future app.Config.Now seam rather than a ship-blocker. Security/reuse/duplication: clean.

Gates

task lint ✅ · task test (both modules, -race, engine-standalone) ✅ · task docs (matlatl strict) ✅ · task api:check ✅ · task ac-trace-strict ✅ · go run ./cmd/mecademo ✅

JAORMX and others added 6 commits July 28, 2026 12:47
…shaped manager (ADR 0076)

The validated create/read/update/fire seam lived on *server.Service as methods
reaching into s.cfg. It is in fact STORE-SHAPED — every input it needs (the
ScheduleStore type-asserted off the session store, a now-func, the cadence
floor, the event-log, diagnostics) is available before buildEngine. Move it
verbatim onto a standalone scheduleManager (new schedule_manager.go),
constructed from the store + now-func alone, with the scheduler + model
inventory as late-bound atomic fields. *Service keeps thin delegating
wrappers so the RPC surface (grpc_schedule.go, REST /v1/schedules, the mecatui
/schedule overlay) is byte-identical.

Composition (app.Build) constructs the manager from the store BEFORE buildEngine
and hands it to server.Config.ScheduleManager; the Service adopts it and
late-binds its models pointer so SetModels keeps working with no second copy.
assets.scheduleManagerFactory is still bound LATE (after NewService) — the
eager binding is task 02. This is a pure refactor: zero behaviour change.

Pins AC1.1/AC1.3/AC1.4 of the schedule-shared-catalog plan:
- TestScheduleSharedCatalog_Scenario1_ManagerIsStoreShaped (AC1.1)
- TestScheduleSharedCatalog_Scenario1_ServiceDelegates (AC1.3)
- TestScheduleSharedCatalog_Scenario1_FireNowStatesPreserved (AC1.4)

All existing schedule tests stay green (schedule_test.go, schedule_e2e_test.go,
schedule_validation_test.go, schedule_wire_survives_test.go, internal/app
scheduletool tests, TestPerSessionCatalogMatchesSharedCatalog).

Co-Authored-By: mecatl <[email protected]>
…ule/ScheduleQuery (ADR 0076, task 02)

buildEngine now constructs the store-shaped schedule manager from the
session store BEFORE any catalog assembly and buildCatalog binds
assets.scheduleManagerFactory onto the assets before the build-time
assembleCatalog pass — so registerScheduleTool fires on the SHARED pass
and the build-time shared catalog gains Schedule (mutating) +
ScheduleQuery (read-only), exactly like the six memory tools (ADR 0073
decision 1). The late bind (assets.scheduleManagerFactory =
svc.ScheduleManager after server.NewService) and the stale
"chicken-and-egg / legitimately has no Schedule tool" comments are
deleted: sessionNeedsPerFactory has no schedule arm, so the
default-profile shared-engine fast path (the plain mecatui launch) was
schedule-less.

Build hands the SAME manager buildEngine returns to server.NewService
via server.Config.ScheduleManager (one manager, one truth). The manager
crosses composition as the concrete *scheduleManager (the new
server.ScheduleManagerImpl alias) with an explicit nil check in the
factory — a typed-nil interface would defeat registerScheduleTool's
mgr == nil honest-absence gate and nil-panic NewService's
setModelsPointer adoption (caught by the full suite). A store with no
ScheduleStore keeps the tool honestly absent from BOTH catalogs (never
a stub).

TestPerSessionCatalogMatchesSharedCatalog now covers the schedule pair
with NO carve-out: the pair joins requiredFamilyTools, fullyLoadedCfg
backs a ScheduleStore (StoreDir), and the drift guard passes the same
eager factory buildEngine performs. registerScheduleTool and
scheduleManagerPresent are unchanged (they already no-op on a nil
factory/manager).

Also adds Config.MockProvider (test-only): a scripted provider seam
through a full app.Build — UseMock scripts one fixed text turn and can
never emit a tool call, which the AC2.1 pin needs.

verify:
- AC2.1: TestScheduleSharedCatalog_Scenario2_SharedCatalogHasScheduleTools
  (store-backed Build; scripted Schedule + ScheduleQuery calls through a
  default-profile shared-engine session; oracle = the run's own
  EvToolResult — an unregistered tool comes back "unknown tool"; watched
  red before the fix and red again with the eager bind planted out)
- AC2.2: TestScheduleTool_RegisteredOnlyWhenStoreBacked (green)
- AC2.3: TestPerSessionCatalogMatchesSharedCatalog (green, schedule pair
  in requiredFamilyTools, no carve-out)

Co-Authored-By: mecatl <[email protected]>
… 0070/0075, task 03)

The shared engine's Deps never got applySchedulePosture — today applied
only in the per-session factory (sessionEngineFactory) — so a
default-profile, zero-selector session (the shared-engine fast path a
plain mecatui launch takes) carried the Schedule tool in its catalog
(task 02) but was never TOLD the tool exists (the ADR-0070 affordance
gate). buildEngine now applies applySchedulePosture to the shared
engine's PromptConfig under the SAME scheduleManagerPresent(assets) gate
the factory uses, mirroring the note's registration exactly (a store
with no ScheduleStore withholds it).

Four Scenario-3 pins prove the end-to-end over a store-backed Build
(launch-root workspace → the shared-engine fast path):

- AC3.1: TestScheduleSharedCatalog_Scenario3_DefaultSessionHasTool — the
  shared engine's catalog resolves Schedule + ScheduleQuery (scripted
  dispatch executes both, no unknown-tool error).
- AC3.2: TestScheduleSharedCatalog_Scenario3_SystemPromptCarriesScheduleNote
  — the shared engine's system prompt carries schedulePostureNote on the
  Role/StablePrefix layer (asserted against req.System.StablePrefix, not
  the combined Render); watched RED before the fix (launch-root session
  → shared engine), GREEN after; a store-less shared engine withholds it.
- AC3.3: TestScheduleSharedCatalog_Scenario3_OriginAndDeliveryWired — a
  schedule created from a shared-engine session stamps OriginSessionID
  (OriginBinder live), and the production fire path (scheduler.FireNow →
  makeFireFunc → fireClaimed → deliverFireResult) enqueues the fire's
  fenced result into the FileDeliveryQueue the shared engine's Step 2a
  drain records into the origin chat (ADR 0075).
- AC3.4: TestScheduleSharedCatalog_Scenario3_RehydratedSessionKeepsTool —
  a default-profile session persisted then reloaded (a second Build over
  the SAME store, the restart path) still resolves the Schedule tool on
  the restored shared engine.

The tests create sessions on the LAUNCH-ROOT workspace so
sessionNeedsPerFactory is false (the shared-engine fast path); an early
draft passed a t.TempDir() workspace and silently exercised the
per-session factory, masking the missing shared-engine wiring — caught
by watching AC3.2 fail against the launch-root session.

Co-Authored-By: mecatl <[email protected]>
@JAORMX
JAORMX merged commit 9d603f4 into main Jul 28, 2026
14 checks passed
@JAORMX
JAORMX deleted the acc/schedule-shared-catalog branch July 28, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant