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
12 changes: 6 additions & 6 deletions .tours/01-primary-user-flow.tour
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
},
{
"file": "convex/nodeslideAgent.ts",
"line": 1704,
"line": 1712,
"description": "**The trust boundary.**\n\nAbove this line, values came from a browser and are suspect. Below it, everything is typed and checked.\n\nConvex validates every argument against this `args` object *before* the handler body runs, and rejects any undeclared field. Read the comment on `durableJob` below — declaring that one field was the difference between working durable jobs and every job dying at 35% progress."
},
{
"file": "convex/nodeslideAgent.ts",
"line": 1760,
"line": 1768,
"description": "**Why the cheap checks run first.**\n\nBoth checks below are pure string comparisons over arguments already in hand: no database read, no quota, no provider call. A caller that cannot name the job whose deck it claims to produce is refused *for free*.\n\nMoving either check later would turn a free refusal into one that arrives after a paid completion. This ordering is the rule the whole file obeys."
},
{
Expand All @@ -40,22 +40,22 @@
},
{
"file": "convex/nodeslideAgent.ts",
"line": 1882,
"line": 1890,
"description": "**The model is asked for intent, not geometry.**\n\nSlide count, allowed element kinds, and required provenance fields are enforced by this JSON schema — not hoped for in prose. `minItems`/`maxItems` come from the count the user actually asked for.\n\nA model that returns coordinates cannot be checked. A model that returns a typed plan can, and deterministic code turns the plan into positioned elements."
},
{
"file": "convex/nodeslideAgent.ts",
"line": 2013,
"line": 2021,
"description": "**A ceiling enforced by code, not by prompt.**\n\nThe dispatch reserves budget against a ledger row keyed by the run id, calls the provider with a hard timeout, and reconciles the spend afterwards.\n\nNote the comment on `timeoutMs`: the create path carries its own wire ceiling because full-deck generation legitimately takes minutes, and the 30-second edit-path default would guarantee a timeout and a silently degraded deck."
},
{
"file": "convex/nodeslideAgent.ts",
"line": 2058,
"line": 2066,
"description": "**Fail closed on an ambiguous charge.**\n\nIf the paid call ended without a reconcilable billing receipt, creation stops here. No fallback deck is produced under an unresolved charge.\n\nA provider *failure* is different and does fall back to the deterministic generator. Failure and ambiguity are not the same thing, and this repository refuses to treat them alike."
},
{
"file": "convex/nodeslideAgent.ts",
"line": 2150,
"line": 2158,
"description": "**The only write.**\n\nEverything above was computation. This one mutation persists the deck, its slides, its elements and their version clocks in a single transaction.\n\nFrom here on, every change to this deck goes through the version check in tour 2."
},
{
Expand Down
4 changes: 2 additions & 2 deletions .tours/02-agent-execution.tour
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"file": "convex/nodeslide.ts",
"line": 1180,
"line": 1184,
"description": "**Where every change enters, whoever made it.**\n\n`applyPatch` (direct), `proposePatch` (review first) and `proposePropagation` (apply an accepted change to matching slides) all normalise into the same shape and all end up at the same check."
},
{
Expand All @@ -45,7 +45,7 @@
},
{
"file": "convex/nodeslide.ts",
"line": 1224,
"line": 1228,
"description": "**Acceptance is one transaction.**\n\nThe commit, the version bump and the decision record either all land or all roll back. There is no window in which a deck has advanced but its receipt has not."
},
{
Expand Down
2 changes: 1 addition & 1 deletion .tours/03-debug-and-recovery.tour
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"file": "convex/nodeslide.ts",
"line": 3348,
"line": 3354,
"description": "**Failure 2: the worker died mid-run.**\n\nAn agent run holds a lease. This mutation finds runs whose `leaseExpiresAt` has passed and fails them honestly, so a crashed action stops spinning in the UI instead of hanging forever.\n\n'Honestly' is the operative word: it marks them failed with a reason rather than quietly deleting them."
},
{
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

### Agent surfaces

- Bound edit proposal publication to the active run and attempt, so cancellation
that persists first prevents a new proposal. Publication links its patch and
trace atomically; later cancellation preserves the existing proposal and replay.
Both hosted and local-candidate edits retain the later stream/review checkpoint.
- Upgraded `nodeslide.create_deck` from draft creation to the same finished-deck
transaction used by the CLI.
- Added safe output-root containment, artifact size limits, public URL delivery,
Expand Down
4 changes: 2 additions & 2 deletions convex/lib/nodeslideEditVerifyAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function harness(current: NodeSlideWorkspace) {
const budgetReply = nodeSlideBudgetLedgerStubResponse(args);
if (budgetReply !== undefined) return budgetReply;
if ('buckets' in args) return { ok: true };
if ('idempotencyKey' in args) return { created: true, run: { id: 'run-b4-test' } };
if ('runId' in args) {
if ('idempotencyKey' in args) return { created: true, run: { id: 'run-b4-test', attempt: 1 } };
if ('runId' in args && 'status' in args) {
steps.push({
status: args.status as string | undefined,
message: args.message as string | undefined,
Expand Down
32 changes: 31 additions & 1 deletion convex/nodeslide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,11 @@ export const cancelAgentRun = mutation({
.withIndex('by_stable_id', (query) => query.eq('id', args.runId))
.unique();
if (!row || row.deckId !== args.deckId) return null;
if (['completed', 'failed', 'cancelled', 'awaiting_review'].includes(row.status)) {
if (
row.patchId ||
row.traceId ||
['completed', 'failed', 'cancelled', 'awaiting_review'].includes(row.status)
) {
const { _id, _creationTime, ownerDigest: _ownerDigest, ...run } = row;
return run;
}
Expand Down Expand Up @@ -3087,6 +3091,7 @@ export const advanceAgentRunInternal = internalMutation({
deckId: v.string(),
ownerAccessKey: v.string(),
runId: v.string(),
expectedAttempt: v.optional(v.number()),
status: v.union(
v.literal('researching'),
v.literal('planning'),
Expand Down Expand Up @@ -3120,6 +3125,7 @@ export const advanceAgentRunInternal = internalMutation({
.withIndex('by_stable_id', (query) => query.eq('id', args.runId))
.unique();
if (!row || row.deckId !== args.deckId) throw new Error('Agent run not found.');
if (args.expectedAttempt !== undefined && row.attempt !== args.expectedAttempt) return null;
if (row.status === 'cancelled' && args.status !== 'cancelled') return null;
const now = Date.now();
const terminal = ['completed', 'failed', 'cancelled'].includes(args.status);
Expand Down Expand Up @@ -3786,6 +3792,8 @@ export const createFromBriefInternal = internalMutation({
export const proposeAgentPatchInternal = internalMutation({
args: {
...internalAgentPatchArgs,
runId: v.string(),
runAttempt: v.number(),
instruction: v.string(),
planningInputDigest: v.optional(v.string()),
planningSnapshotDigest: v.optional(v.string()),
Expand All @@ -3809,6 +3817,22 @@ export const proposeAgentPatchInternal = internalMutation({
},
handler: async (ctx, args) => {
await requireOwnerAccess(ctx, args.deckId, args.ownerAccessKey);
const run = await ctx.db
.query('nodeslide_agent_runs')
.withIndex('by_stable_id', (query) => query.eq('id', args.runId))
.unique();
// Cancellation and publication decide against the same run in this transaction.
if (
!run ||
run.deckId !== args.deckId ||
run.ownerDigest !== `actor_${nodeslideContentDigest(args.ownerAccessKey)}` ||
run.attempt !== args.runAttempt ||
!['queued', 'researching', 'planning', 'validating'].includes(run.status) ||
run.patchId ||
run.traceId
) {
throw new Error('Agent run is unavailable, cancelled, superseded, or already published.');
}
if (args.toolCalls.length > 16) throw new Error('Too many agent tool calls recorded.');
// A fallback reason without a fallback is a claim the record cannot support, and the
// absence of a reason on a fallback is the disclosure going missing at the source.
Expand Down Expand Up @@ -3898,6 +3922,12 @@ export const proposeAgentPatchInternal = internalMutation({
...(proposal.patch.status === 'stale' ? { completedAt: now } : {}),
};
await ctx.db.insert('nodeslide_traces', trace);
// Leave stream completion and the full awaiting-review checkpoint to the action.
await ctx.db.patch(run._id, {
patchId: proposal.patch.id,
traceId: args.traceId,
updatedAt: now,
});
if (args.shadowComparison) {
try {
assertNodeSlideShadowComparisonBounds(args.shadowComparison);
Expand Down
8 changes: 8 additions & 0 deletions convex/nodeslideAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ export const proposeEdit = action({
webResearch: args.webResearch === true,
});
const runId = runStart.run.id as string;
const runAttempt = runStart.run.attempt as number;
if (!runStart.created) {
if (runStart.run.patchId) {
const current = (await ctx.runQuery(nodeslideInternal.getAgentContextInternal, {
Expand Down Expand Up @@ -1180,6 +1181,8 @@ export const proposeEdit = action({
const proposal = await ctx.runMutation(nodeslideInternal.proposeAgentPatchInternal, {
id: patchId,
traceId,
runId,
runAttempt,
deckId: args.deckId,
ownerAccessKey: args.ownerAccessKey,
baseDeckVersion: args.baseDeckVersion,
Expand Down Expand Up @@ -1293,6 +1296,7 @@ export const proposeEdit = action({
deckId: args.deckId,
ownerAccessKey: args.ownerAccessKey,
runId,
expectedAttempt: runAttempt,
status: 'failed',
error: message.slice(0, 600),
message: `No deck changes were applied. ${message}`.slice(0, 4000),
Expand Down Expand Up @@ -1392,6 +1396,7 @@ export const proposeExternalAgentEdit = action({
webResearch: false,
});
const runId = runStart.run.id as string;
const runAttempt = runStart.run.attempt as number;
if (!runStart.created) {
if (runStart.run.patchId) {
const current = (await ctx.runQuery(nodeslideInternal.getAgentContextInternal, {
Expand Down Expand Up @@ -1422,6 +1427,8 @@ export const proposeExternalAgentEdit = action({
const proposal = await ctx.runMutation(nodeslideInternal.proposeAgentPatchInternal, {
id: patchId,
traceId,
runId,
runAttempt,
deckId: args.deckId,
ownerAccessKey: args.ownerAccessKey,
baseDeckVersion: args.baseDeckVersion,
Expand Down Expand Up @@ -1470,6 +1477,7 @@ export const proposeExternalAgentEdit = action({
deckId: args.deckId,
ownerAccessKey: args.ownerAccessKey,
runId,
expectedAttempt: runAttempt,
status: 'failed',
error: agentRunErrorMessage(error).slice(0, 600),
message: `No deck changes were applied. ${agentRunErrorMessage(error)}`.slice(0, 4000),
Expand Down
Loading
Loading