8.6 KiB
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | must_haves | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 01.1-matrix-restart-reconciliation-and-dev-reset-workflow | 02 | execute | 2 |
|
|
true |
|
Purpose: D-05 through D-07 require restart recovery to be the default developer path. The bot must bootstrap itself from existing Matrix rooms on startup and make one on-demand repair attempt before routing an unknown room through the dispatcher.
Output: adapter/matrix/bot.py performs initial sync + reconciliation before sync_forever(), and runtime tests prove the bot recovers or logs clearly instead of blindly dispatching broken state.
<execution_context> @/Users/a/.codex/get-shit-done/workflows/execute-plan.md @/Users/a/.codex/get-shit-done/templates/summary.md </execution_context>
@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/01.1-matrix-restart-reconciliation-and-dev-reset-workflow/01.1-CONTEXT.md @.planning/phases/01.1-matrix-restart-reconciliation-and-dev-reset-workflow/01.1-RESEARCH.md @.planning/phases/01.1-matrix-restart-reconciliation-and-dev-reset-workflow/01.1-01-PLAN.md @adapter/matrix/bot.py @adapter/matrix/room_router.py @adapter/matrix/reconcile.py @tests/adapter/matrix/test_dispatcher.py From `adapter/matrix/bot.py`:class MatrixBot:
async def on_room_message(self, room: MatrixRoom, event: RoomMessageText) -> None
async def main() -> None
From adapter/matrix/reconcile.py:
async def reconcile_matrix_state(client: Any, store: StateStore, chat_mgr: ChatManager) -> dict
async def reconcile_single_room(
client: Any, store: StateStore, chat_mgr: ChatManager, room_id: str, matrix_user_id: str
) -> dict
From adapter/matrix/room_router.py:
async def resolve_chat_id(store: StateStore, room_id: str, matrix_user_id: str) -> str
Task 1: Run initial sync and reconciliation before the long-poll loop
adapter/matrix/bot.py, tests/adapter/matrix/test_dispatcher.py
adapter/matrix/bot.py, adapter/matrix/reconcile.py, tests/adapter/matrix/test_dispatcher.py, .planning/phases/01.1-matrix-restart-reconciliation-and-dev-reset-workflow/01.1-RESEARCH.md
- Test 1: `main()` performs `client.sync(timeout=0, full_state=True)` before `sync_forever()`.
- Test 2: `main()` calls `reconcile_matrix_state(...)` after the initial sync and logs the returned report.
- Test 3: startup still reaches `sync_forever()` when reconciliation reports recoverable skips/conflicts instead of fatal failure.
Modify `adapter/matrix/bot.py` so normal startup follows the two-phase bootstrap recommended in research:
1. build client and runtime
2. authenticate
3. register callbacks
4. run `await client.sync(timeout=0, full_state=True)`
5. run `await reconcile_matrix_state(client, runtime.store, runtime.chat_mgr)`
6. log a structured `matrix_reconcile_complete` event with the report fields
7. enter `await client.sync_forever(timeout=30000)`
Do not move provisioning logic into startup. The startup step only rehydrates local state from server-side rooms per D-02 through D-04.
Update or add focused tests in tests/adapter/matrix/test_dispatcher.py using monkeypatch/fake-client patterns already used in the repo so the verify command proves the call order and logging-safe behavior. The test should fail if sync_forever() starts before reconciliation.
cd /Users/a/MAI/sem2/lambda/surfaces-bot && pytest tests/adapter/matrix/test_dispatcher.py -q
<acceptance_criteria>
adapter/matrix/bot.pyruns an initial full-state sync before steady-state polling.adapter/matrix/bot.pyinvokesreconcile_matrix_state(...)exactly once during startup.- Startup logs a structured reconciliation summary instead of silently skipping the recovery step.
tests/adapter/matrix/test_dispatcher.pyasserts the bootstrap order explicitly. </acceptance_criteria> Normal Matrix bot startup now includes a recovery pass before the event loop begins handling user traffic.
Do not invent a new fallback chat id and do not auto-create rooms here; that would violate D-04. Keep this change inside adapter/matrix/bot.py so file ownership stays isolated for this plan.
cd /Users/a/MAI/sem2/lambda/surfaces-bot && pytest tests/adapter/matrix/test_dispatcher.py -q
<acceptance_criteria>
- Unknown Matrix rooms trigger one targeted reconciliation attempt before dispatch.
- Successful targeted recovery leads to normal dispatch with a real logical
chat_id. - Failed targeted recovery logs a clear diagnostic and avoids a handler crash on missing chat state per D-06.
- No code path in this task provisions new Matrix rooms or Spaces. </acceptance_criteria> The runtime treats unknown rooms as recoverable state drift first, not as a silent routing failure or crash path.
<success_criteria>
- A standard Matrix restart now attempts recovery before the bot starts processing live events.
- Unknown-room events are diagnosable and recoverable instead of falling straight into broken command handling.
- The runtime never provisions new server-side rooms during restart reconciliation. </success_criteria>