Repository navigation
Conversation
Back up Pick & polish notes from the canvas with the Rails revision and conversation rules, add them to the comment feeds on request, and recall accepted learnings for the canvas learnings hook. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject NUL and malformed text before it reaches PostgreSQL, present each note author's current login, fail fast instead of waiting behind authority locks during recall, answer recall within its deadline, and limit recall per connection. Add independent note and validator coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Authorization races can expose private data or permit writes after access changes, while unbounded note feeds can exhaust server memory.
12 open issues
Revalidate current identity authority before returning protected data · New Recheck the original write-authority revision before saving · New Revalidate connection and repository access before returning recall · New Paginate and bound note feeds and responses · New Return learnings_off when SQLite has no learning store · New Start the recall deadline before learning-store discovery · New Log bounded error codes for non-transient recall failures · New Reject unpaired surrogates in review anchor fields · New Reject remote body changes and preserve the original test body · New Reject invalid avatar text before parsing the URL · New Allow deletion without resending oversized conversation history · New Recheck and lock prototype reviewability inside the save transaction · New
What changed in this PR
Adds Node Hub support for backing up canvas Pick & polish notes and recalling accepted learnings, building on the review-comment and share-link APIs.
Changes:
- Stores note revisions, validates conversations, preserves deletion tombstones, and includes notes in feeds.
- Adds rate-limited learning recall with execution deadlines and delivery tracking.
- Shares canvas helpers and expands contracts, tests, and documentation.
| File | Description |
|---|---|
hub/server/routes/index.ts |
Passes learning dependencies to canvas routes. |
hub/server/routes/api/repositories/prototypes/builds/get/index.test.ts |
Updates product dependency mocks. |
hub/server/routes/api/product/types.ts |
Defines transactional canvas authorization. |
hub/server/routes/api/product/create-product-route-dependencies/index.ts |
Shares mutation authorization. |
hub/server/routes/api/canvas/share-links/index.ts |
Uses shared request authorization. |
hub/server/routes/api/canvas/share-links/constants.ts |
Removes extracted parameter schemas. |
hub/server/routes/api/canvas/review-comments/index.ts |
Adds notes to comment feeds. |
hub/server/routes/api/canvas/review-comments/index.db.test.ts |
Updates invalid-filter coverage. |
hub/server/routes/api/canvas/review-comments/constants.ts |
Accepts note feed filters. |
hub/server/routes/api/canvas/recall.db.test.ts |
Covers recall guards and rate limits. |
hub/server/routes/api/canvas/present-canvas-improvement-note/index.ts |
Serializes notes and edit permissions. |
hub/server/routes/api/canvas/index.ts |
Mounts note and recall endpoints. |
hub/server/routes/api/canvas/improvement-notes/index.ts |
Serves note reads and synchronization. |
hub/server/routes/api/canvas/improvement-notes/index.db.test.ts |
Covers note lifecycle and access rules. |
hub/server/routes/api/canvas/improvement-notes/constants.ts |
Defines note request schemas. |
hub/server/routes/api/canvas/find-canvas-avatars/index.ts |
Shares immutable-ID avatar lookup. |
hub/server/routes/api/canvas/contracts.ts |
Adds note and recall response types. |
hub/server/routes/api/canvas/confirm-canvas-read/index.ts |
Extracts final read-access checks. |
hub/server/routes/api/canvas/authorize-canvas-request/index.ts |
Extracts canvas request authorization. |
hub/server/repositories/improvement-notes/save-improvement-note/index.ts |
Persists note revisions. |
hub/server/repositories/improvement-notes/list-improvement-notes/index.ts |
Queries notes and presentation data. |
hub/server/repositories/improvement-notes/find-note-build/index.ts |
Finds eligible successful Builds. |
hub/server/repositories/improvement-notes/find-improvement-note/index.ts |
Finds an author's saved note. |
hub/server/integrations/postgres/with-learning-execution-lock/index.ts |
Adds fail-fast lock acquisition. |
hub/server/integrations/postgres/with-learning-execution-lock/index.db.test.ts |
Covers fail-fast authority locking. |
hub/server/domains/improvement-notes/validate-improvement-thread/index.ts |
Validates conversations and history. |
hub/server/domains/improvement-notes/validate-improvement-thread/index.test.ts |
Tests conversation validation rules. |
hub/server/domains/improvement-notes/synchronize-improvement-note/index.ts |
Enforces revision and tombstone rules. |
hub/server/domains/improvement-notes/is-valid-note-text/index.ts |
Checks database-safe note text. |
hub/server/domains/improvement-notes/errors.ts |
Defines note synchronization errors. |
hub/server/domains/improvement-notes/constants.ts |
Defines statuses and validation limits. |
hub/server/domains/canvas/recall-canvas-learnings/index.ts |
Executes and formats learning recall. |
hub/server/domains/canvas/recall-canvas-learnings/index.test.ts |
Covers recall results and failures. |
hub/server/domains/canvas/authorize-canvas-review/index.ts |
Supports token-scoped repository requests. |
hub/schema/user.prisma |
Adds the note-author relation. |
hub/schema/prototype.prisma |
Adds prototype notes. |
hub/schema/migrations/migration_lock.toml |
Adds generated header comments only. |
hub/schema/migrations/20261230090000_canvas_improvement_notes/migration.sql |
Creates note storage and constraints. |
hub/schema/improvement-note.prisma |
Defines the improvement-note model. |
hub/schema/build.prisma |
Adds Build-linked notes. |
hub/docs/prototype-canvas.md |
Documents note synchronization and recall. |
hub/docs/database.md |
Documents note persistence rules. |
Review effort: Max (adaptive)
Comment on lines
+3
to
+25
| import type { PrismaClient } from "../../../../generated/prisma/client.ts" | ||
| import { verifyCanvasAccess } from "../../../../repositories/canvas/grants/index.ts" | ||
| import type { ProductRouteDependencies } from "../../product/types.ts" | ||
| import type { CanvasScope } from "../authorize-canvas-request/index.ts" | ||
|
|
||
| /** | ||
| * Rechecks the connection and the stored repository access after a protected read, as Hub's | ||
| * review pages do, so access withdrawn during the read returns nothing. Answers 401 itself. | ||
| */ | ||
| export async function confirmCanvasRead( | ||
| response: Response, | ||
| database: PrismaClient, | ||
| isRepositoryVisible: ProductRouteDependencies["isRepositoryVisible"], | ||
| scope: CanvasScope, | ||
| ) { | ||
| if ( | ||
| (await verifyCanvasAccess(database, scope.grantId, scope.tokenDigest, new Date())) && | ||
| (await isRepositoryVisible(scope.viewer, scope.repository.id)) | ||
| ) | ||
| return true | ||
| response.status(401).json({ error: "Canvas connection is no longer active." }) | ||
| return false | ||
| } |
Comment on lines
+110
to
+116
| authorize: (transaction: Prisma.TransactionClient) => | ||
| input.product.authorizeCanvasMutation( | ||
| transaction, | ||
| scope.tokenDigest, | ||
| userId, | ||
| scope.repository.id, | ||
| ), |
| status(response, 503, "Hub could not recall learnings. Try again.") | ||
| return | ||
| } | ||
| response.json({ text: result.text, memories: [...result.memories] } satisfies CanvasRecall) |
Comment on lines
+251
to
+253
| : await listImprovementNotes(transaction, { | ||
| prototype: eligibleReviewPrototype(scope.repository), | ||
| }), |
| root: learning.root, | ||
| staticDirectories: learning.staticDirectories, | ||
| }) | ||
| if (!directory) return { status: "ok", text: "", memories: [] } as const |
| ) | ||
| let anchor: Prisma.InputJsonValue | ||
| try { | ||
| anchor = parseReviewAnchor(note.anchor) as unknown as Prisma.InputJsonValue |
| if (!same) conflict("This note revision has different content.") | ||
| return saved | ||
| } | ||
| if (saved.deletedAt) conflict("A deleted note cannot be restored.") |
| invalid("Author snapshots must identify this note's owner.") | ||
| const avatar = author.avatarUrl | ||
| if (avatar === null) return | ||
| const url = typeof avatar === "string" && avatar.length <= 2048 && URL.parse(avatar) |
| router.post( | ||
| path, | ||
| input.limit("canvas-improvement-note", 120), | ||
| express.json({ limit: "1600kb", strict: true }), |
Comment on lines
+91
to
+92
| if (prototype.registeredAt === null) | ||
| return fail(response, 404, "Hub has not registered a reviewable prototype on this branch.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
d5f05e314f4108dd60f1f0de94c282ce990b4307↑ Seven pure validator cases came from an independent test writer and were confirmed red against broken rules.
↑ Four code-review findings are fixed: live author login, text the database can store, a fail-fast recall deadline, and a per-connection recall limit.
↑ Lint,
db:validate, types, unit (4015) and database (888) suites and the build pass locally on this head.↓ Recall isn't exercised against a real learning store; its command and lock are mocked.
↓ There's no dedicated migration-compatibility test for the added table.
↓ CI hasn't run yet.
Why
The canvas extension backs up Pick & polish notes through
/api/canvas/repositories/…/prototypes/…/improvement_notes. Its learnings hook callsPOST /api/canvas/learnings/recallbefore each prompt. The Rails Hub onmainserved both, but the Node Hub doesn't, so note backup and Hub learnings are unavailable in the canvas againstbuild/hub/new. This is the third of three server PRs in the Canvas Hub API contract shared with @arniebradfo. It's stacked on #485, which is stacked on #481.What changes
Improvement notes.
Storage. A new
improvement_notestable backs up each author's notes: one row per author, prototype and the extension's local note ID. Each row holds the anchor and conversation as JSON, the successful Build it was written against, and a tombstone after deletion.GETreturns only the viewer's own notes and needs repository read access.POSTsaves one complete revision and needs repository write access, as on Rails. It ports Rails'ssynchronize!:409;Thread rules. These port Rails's thread and message contracts:
A thread that breaks them returns
422. Text with NUL or malformed characters also returns422, because PostgreSQL can't store it.Feeds. The review-comment feeds now accept
improvement_notes=include|onlyand add everyone's notes.Author login. Notes show the author's current login, because the extension matches notes to its signed-in login.
Learning recall.
POST /api/canvas/learnings/recallreturns the learnings the repository's administrators accepted as{ text, memories: [{ id, digest }] }.replica-learning recallunder the learning execution lock and records the recall as a delivery toagent:hub-canvas-connection-<id>.failFastlock option, a held authority lock counts as busy instead of a wait, so recall answers within 1.5 seconds or returns503.404withcode: "learnings_off".Refactor. The canvas routers now share
authorize-canvas-request,confirm-canvas-readandfind-canvas-avatars, instead of duplicating them.Divergences from
mainand risks422.422. Rails stored them.agent:hub-canvas-connection-<id>), as Hub's agent connections do, rather than under the person. Each recall is still recorded as a use, as the user decided.403 learnings_consent_requiredis never returned. Repository learning settings govern learnings.learnings_offand the extension's local learning mode applies.withLearningExecutionLockgains an opt-infailFastoption. Existing callers are unchanged.improvement_notes=include|onlyis now accepted, so feat(hub): serve canvas review comments #481's400for those values no longer applies.20261230090000_canvas_improvement_notessorts after fix(hub): harden canvas and agent authorization #470's20261229090000migration.authorizeCanvasMutationthat feat(hub): serve canvas review comments #481 tests.