Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion cloudflare-gastown/src/dos/Town.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import * as scheduling from './town/scheduling';
import * as events from './town/events';
import * as reconciler from './town/reconciler';
import { applyAction } from './town/actions';
import type { ApplyActionContext } from './town/actions';
import type { Action, ApplyActionContext } from './town/actions';
import { buildRefinerySystemPrompt } from '../prompts/refinery-system.prompt';
import { GitHubPRStatusSchema, GitLabMRStatusSchema } from '../util/platform-pr.util';

Expand Down Expand Up @@ -3684,6 +3684,31 @@ export class TownDO extends DurableObject<Env> {
};
}

// DEBUG: dry-run the reconciler against current state, returning actions
// it would emit without applying them. Side-effect-free — reconcile()
// only reads SQLite state; applyAction() is never called.
async debugDryRun(): Promise<{
actions: Action[];
metrics: Pick<
reconciler.ReconcilerMetrics,
'actionsEmitted' | 'actionsByType' | 'pendingEventCount'
>;
}> {
const actions = reconciler.reconcile(this.sql);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Dry-run skips pending events and can report stale actions

reconcile() is only Phase 1 of the alarm loop. Facts still sitting in town_events (for example agent_done, agent_completed, bead_created, or container_status) are normally applied in Phase 0 via drainEvents() + applyEvent() before reconciliation runs, so this endpoint can disagree with the very next real alarm tick whenever pendingEventCount > 0.

const actionsByType: Record<string, number> = {};
for (const a of actions) {
actionsByType[a.type] = (actionsByType[a.type] ?? 0) + 1;
}
return {
actions,
metrics: {
actionsEmitted: actions.length,
actionsByType,
pendingEventCount: events.pendingEventCount(this.sql),
},
};
}

// DEBUG: concise non-terminal bead summary — remove after debugging
async debugBeadSummary(): Promise<unknown[]> {
return [
Expand Down
8 changes: 8 additions & 0 deletions cloudflare-gastown/src/gastown.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ app.get('/debug/towns/:townId/status', async c => {
return c.json({ alarmStatus, agentMeta, beadSummary });
});

app.post('/debug/towns/:townId/reconcile-dry-run', async c => {
const townId = c.req.param('townId');
const town = getTownDOStub(c.env, townId);
// eslint-disable-next-line @typescript-eslint/await-thenable -- DO RPC returns promise at runtime
const result = await town.debugDryRun();
return c.json(result);
});

// ── Town ID + Auth ──────────────────────────────────────────────────────
// All rig routes live under /api/towns/:townId/rigs/:rigId so the townId
// is always available from the URL path.
Expand Down
Loading