Skip to content

test(portal): prove the deployed patch lifecycle - #272

Merged
allisonmahmood merged 2 commits into
mainfrom
portal/259-e2e-docs
Sep 16, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
portal/259-e2e-docs

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

The portal build needed end-to-end proof of its deployed lifecycle, real-Postgres race coverage, and docs that describe what is now built.

The packed CLI flow now publishes a shared-table source and a real consumer, exercises discovery, retirement refusal and force, restore, rollback and description sync, and checks the portal and address notice with the seeded browser session. The new races exposed a stale owner join after reassignment; locking the patch before reading its owner fixes the incorrect not-found refusal. The docs pass includes ADR-0002's missing connections group and the skill hash.

Stacked on portal/258-address-notice; that branch is this PR's base, not main.

Closes #259. Portal map #230 is ready to close when this PR merges; it remains open.

Verification

  • Full offline suite: 935 tests across 80 files passed with --maxWorkers=2. The default-worker run hit one unrelated five-second Postgres-runtime timeout; that test passed alone and in the full two-worker run. No timeout changes.
  • All 7 real-Postgres concurrency tests and the complete packed CLI e2e passed.
  • Typecheck, lint and formatting passed. Independent Standards and Spec reviews each reported zero findings.

Surface check

  • Wire contract: unchanged; existing schemas and API docs remain current.
  • CLI: packed lifecycle/discovery coverage and skill guidance updated.
  • Dev loop: seed states and verification recipes documented.
  • Vocabulary and product shape: product, context map and glossaries reconciled.
  • Migrations: unchanged; all eight ledger records already wired.
  • Company resources: contracts unchanged; races verify retention and reclamation.
  • Served pages: seeded-session portal/card/notice coverage, corrected welcome copy, and portal checklist coverage under ui-consistency.
  • Reverse states: retire/restore and both sweep/restore outcomes covered.
  • Repo layout: README package descriptions updated.

Implemented with OpenAI GPT-6 Astra in Oh My Pi.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:l 501-1,000 changed lines labels Sep 15, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed origin/portal/258-address-notice...421086daae986bc031a5ee3f3d63ab1ff1a07baa against #259. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The row-lock change addresses the reassignment race without introducing another abstraction, and its callers retain their transaction boundaries.

Spec

No merge-blocking intent findings. The packed flow exercises an actual shared-table consumer, discovery, retirement refusal and force, the seeded-session notice, restore, rollback, description pull-down, and the portal index/card. The real-Postgres cases cover the requested races, including both sweep/restore outcomes. The documentation and skill changes match the built lifecycle.

Verification

Passed locally on the reviewed commit:

  • pnpm test:postgres-concurrency: 7 tests.
  • pnpm exec vitest run packages/patches/src/Patches.test.ts: 30 tests.
  • pnpm test:packed-cli-e2e: complete packed CLI real-server contract, including the new browser lifecycle flow.

Summary: Standards 0 findings; Spec 0 findings. No merge blocker on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Opus review

First reviewer, standing in for grok build. Two-axis review per .agents/skills + AGENTS.md, fixed point origin/portal/258-address-notice (three-dot), plus the intent/method/YAGNI pass the stack's last PR earns. Every doc claim below I re-derived from the tree, not from the PR body.

Verdict: merge. No hard violations on either axis. Everything below is a nit or a judgement call.

Standards

Clean. No documented standard is broken. effect-service-conventions binds (the diff edits Patches.ts); the service file keeps its order, namespace imports, environment-supplied dependencies and Schema.TaggedError failures. The test block stays inside one it.layer, uses it.effect, TestClock, Scope and an alternate layer (the gated CompanyDatabases) rather than a mock — no manual runtime, four cases, one race each. Judgement calls:

  • packages/patches/src/Patches.ts:1084–1097 — the invariant that makes this safe is undocumented. Dropping disabled_at IS NULL and the company scope from the second SELECT is correct only because both callers (manageable :1119, inventory :1580) run inside sql.withTransaction, so the FOR UPDATE from statement one is still held. The comment explains lock-before-join but not that. One clause ("the lock already fixed disabled and company scope") stops the next reader from "restoring" the predicates or lifting the call out of a transaction.
  • packages/patches/src/Patches.ts:1084 — unnamed Effect.fn. Every other production Effect.fn in this file carries a span name (Effect.fn("Patches.manageable")); bare Effect.fn(function* otherwise appears only in tests. Name the span or use Effect.gen.
  • scripts/packed-cli-e2e.mjs:3794–3795 — two contradictory PASS: lines. The new summary was added and the old one left standing. Delete one.
  • scripts/packed-cli-e2e.mjs:3649 — openReader asserts through notes (page.frameLocator("#patch"), :3404), which now resolves to the reader patch's frame. It works, but the name lies.
  • scripts/packed-cli-e2e.mjs:3664, :3669 — unguarded .find(...).state / .find(...).declarable. A missing entry throws a bare TypeError instead of a readable assertion.
  • scripts/packed-cli-e2e.mjs:3689–3792 — the new browser section bypasses checkedCall, while the rest of the file routes Playwright awaits through the SIGINT latch (:114). Consistency, not correctness.
  • CONTEXT-MAP.md / README.md — — → : punctuation churn on the bullets whose text changed, leaving both lists mixed. Half a cutover reads worse than either whole.

Spec

Clean against #259, with one partial. Verified item by item:

  • The packed e2e has all ten steps of Portal: finding and managing patches in the deployed stage #247 § Testing, in order, and asserts what the caller sees rather than exit codes: reader repo published through the real CLI with add shared-table (scripts/packed-cli-e2e.mjs:3626–3661), list :3663, list <first> :3665, list <first> orders :3670, portal / and card :3688–3697, dependant refusal :3699–3712, --force :3714, retired notice with actor stamp + Restore + card link :3718–3732 (including the dependant's access_denied shared read while the source is off), restore :3733, rollback 1 with v1 and /~v/2 both checked :3736–3757, describe pull-down and the card's value :3758–3790.
  • The three named races are at packages/patches/src/SdkConcurrency.postgres.test.ts:742 (publish vs retire), :795 (reassign vs publish), :858 (sweep vs restore), plus a fourth at :918 (restore vs sweep). Each is two real backends with blockedBy(pid) proving the lock wait, not a sleep. CI picks both up already: .github/workflows/ci.yml:39–53 and :126.
  • The docs pass. I grepped the tree myself: no not built / decided leftover survives about anything this stack built (the three remaining hits — CONTEXT-MAP.md:61, docs/agents/domain.md:8,34, docs/product.md:306 — are the policy statements and genuinely-unbuilt billing/groups). ADR-0002 now reads auth, patches, connections, sdk, runtime, which matches packages/api/src/api.ts exactly. sha256sum skills/patchy/SKILL.md = 183cc93b… = skills-lock.json — correct. welcome-patch.html:270–286 no longer claims inactivity retirement. docs/DEVELOPMENT.md gains the seed-states paragraph (:298) and the Portal and patch lifecycle recipe (:468).
  • The CLAUDE.md ledger is not a miss. CLAUDE.md is a symlink to AGENTS.md; the ledger there already reads "There are eight records … 0008 patches-lifecycle" (landed earlier in the stack), and the remaining ci+docs(domain): the packed e2e through the lifecycle; the map after the portal #259 item — the portal's pages under ui-consistency — is AGENTS.md:80 in this diff.

One finding:

  • PARTIAL (minor) — scripts/packed-cli-e2e.mjs:3663. Spec: "list, list <first>, list <first> orders". Top-level list asserts only that the source is live; it never asserts the dependant appears in the company listing at all. One assert closes it.

Intent vs. what landed

#259 asked for three things and got all three. The part I'd single out is that the e2e's dependant is now a real second patch — init → add shared-table → publish through the packed CLI, reading the source through its generated browser client (:3626–3661) — where the previous flow invented one with a raw POST /api/publish. That is the difference between proving the contract and proving the route. Same for the retirement: the test now watches the dependant's shared.list come back access_denied from the shell, which is what a colleague actually experiences.

Method, and the lifecycle fix

The races are written the right way round: gate on a real backend PID and assert pg_blocking_pids, so the test fails loudly if the lock stops being taken rather than passing on a lucky interleaving. And they earned their keep — the reassign race exposed a genuine production bug.

Worth being precise about what the bug was, because it is a wire-contract violation, not a cosmetic one. packages/api/src/api.ts:221 promises: "Ownership and lifecycle are checked … again at commit: another company's patch is 404; a same-company non-owner gets not_owner first, with the current owner." Before the fix, a publish that waited on a concurrent reassignment got a 404 instead: lockOpenable's FOR UPDATE OF patches sat inside a join to users owner, and PostgreSQL's EvalPlanQual recheck re-runs the join with the updated patch row against the original other-table rows, so the changed owner_user_id no longer matched and the row vanished. The agent was told its patch does not exist, when the truth was "a colleague owns it now" — the single most confusing refusal we could have produced, on the path #247 § 5 exists to make legible.

The fix is the right size: lock the row alone, then read it, at manageable — the one seam all lifecycle acts and inventory pass through (:1119, :1580), so nothing else needed patching. Cost is one extra round trip per managed act; correct beats clever. Test :795 pins the contract by asserting the refusal and refusal.owner naming the new owner.

Two residual notes, both judgement calls:

  • The title test(portal): prove the deployed patch lifecycle understates a production behaviour change. The body names it plainly, and the fix is inseparable from the ticket that found it, so I would not split the PR — but fix(patches) or a mention in the title would stop git log from hiding it.
  • packages/patches/src/Patches.ts:865 (backfillNames) still holds FOR UPDATE OF patches under a correlated NOT EXISTS, the same hazard class. It is a startup one-off over rows nobody is racing, so I'd leave it — but now that the failure mode has a name, one line of comment there would be cheap.

YAGNI

Nothing built for a future #259 didn't ask for. openReader, saveResources, assertResources and the new identity parameter on publish each have two or more real call sites; the observedRecord → observedPatches rename adds exactly the one method (purgeDeleted) the sweep race needs. The fourth race (:918, sweep wins) is not creep: Reverse states asks for the way out and the way back, and covering only the outcome where restore wins would leave the reclamation path — namespace reuse, object deletion, the refused late restore — unproven. The patchy-postgres skill step-5 rewrite is likewise in scope, not drive-by: "This release generates the files; it does not yet run patchy dev" was literally one of the "not built" lines #259 sent us to remove, and packages/patchy/src/devResources.ts backs the replacement.

Smaller: SdkConcurrency.postgres.test.ts rollback case now discards Fiber.join(rollback)'s { patch, currentVersion } where it used to assert the returned version id. The following rolledBack.patch.currentVersionId assertion covers the outcome, so this is taste — but the return value is now untested anywhere in this file.

Summary

  • Standards: 0 hard violations, 7 judgement calls. Worst: the undocumented lock invariant at Patches.ts:1084–1097 — safe today, quietly breakable tomorrow.
  • Spec: 0 hard violations, 1 partial. Worst: packed-cli-e2e.mjs:3663, top-level list never asserts the dependant is listed.

Nothing here blocks the merge, and nothing blocks closing #230.

🤖 Generated with Claude Code

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed the Astra and Opus comments, the Reviews tab and inline comments. Both reviewers recommend merging; there were no separate review bodies or inline findings. Follow-up fixes are committed and pushed in 2d9fd0670b2a466c1b5dbca34e8c137b7d82da0e.

Fixed

  • Documented that lockOpenable requires its callers' transaction to hold the patch lock across both statements, preserving the company and disabled-state checks. Named its Effect span Patches.lockOpenable to match the production convention.
  • Added explicit top-level discovery assertions for both the source and dependant, closing the missing coverage identified by Opus.
  • Added named assertions for missing patch summaries, unavailable inventory and a missing orders table instead of incidental TypeError failures.
  • Removed the misleading notes reference when checking the reader frame; the assertion now targets the current patch frame directly.
  • Routed the new navigation, click and paired runtime-response waits through checkedCall, matching the existing signal-latch handling. Passive Playwright assertions retain the surrounding flow's pattern.
  • Consolidated the two overlapping success summaries. They described separate successful parts rather than contradictory outcomes, but one complete summary is clearer.

Kept as is

  • The two-statement lock/owner lookup remains. Its held row lock is what makes the second query safe; repeating predicates there would not replace that transaction invariant.
  • README/context-map punctuation remains unchanged. This is stylistic, not a semantic defect, and a broader punctuation conversion would add unrelated churn.
  • The PR keeps its test(portal) title because lifecycle verification and documentation are the primary ticket. The production ownership fix remains explicit in the description and commit body; splitting it away from the race that exposed it would weaken the change.
  • backfillNames remains unchanged. It already rechecks the current name after acquiring the row lock and documents concurrent seeds at lines 870–873; no owner-join race is demonstrated on that path.
  • The rollback race continues to assert the committed version pointer, served HTML, retained schema and usable data rather than duplicating those checks against the returned object. The packed CLI flow separately checks the rollback receipt.

Verification on the latest commit

Local checks passed: all 7 real-Postgres concurrency tests, all 30 Patches tests, the complete packed CLI e2e, targeted typechecking, lint and formatting.

CI run 35014334904 completed successfully for 2d9fd0670b2a466c1b5dbca34e8c137b7d82da0e: test (22), test (24), postgres-concurrency, clerk-live, cli-smoke, lint and dependency-review all passed. The latest PR-label check passed too.

The stacked base portal/258-address-notice has no configured required checks or branch rules. All applicable workflow checks nevertheless pass. GitHub reports MERGEABLE and CLEAN; no new review feedback or unresolved blocker remains. Ready to merge into that stacked base, not directly into main. No merge performed. #230 remains open and is ready to close when this PR merges.

@allisonmahmood
allisonmahmood force-pushed the portal/258-address-notice branch from f1fe3d1 to 719d695 Compare September 16, 2026 16:00
@allisonmahmood
allisonmahmood force-pushed the portal/258-address-notice branch from 719d695 to c0163e1 Compare September 16, 2026 18:09
Base automatically changed from portal/258-address-notice to main September 16, 2026 18:16
Complete #259 with packed source/consumer lifecycle and seeded-session portal coverage, real-Postgres races, and the built-feature documentation pass.

Fix the reassignment race exposed by the new test: lock the patch before joining its owner so a waiting publish reports NotOwner instead of PatchUnavailable.

Verified 935 offline tests with two workers, seven real-Postgres concurrency tests, the complete packed CLI e2e, typecheck, lint and formatting. The default-worker run hit one unrelated five-second Postgres runtime timeout; that test passed alone and in the full bounded-worker run.

Leave portal map #230 open until this change merges.
Assert both source and dependant appear in discovery, clarify missing inventory failures and reader-frame targeting, preserve signal checks around browser navigation, and consolidate the flow summary. Document the transaction invariant and name the owner-lock span.
@allisonmahmood
allisonmahmood merged commit 5329ffb into main Sep 16, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the portal/259-e2e-docs branch September 16, 2026 18:25
allisonmahmood added a commit that referenced this pull request Sep 16, 2026
…281)

Patch lists loaded inventory they never display, and user lifecycle
commits locked every patch in the company. Lifecycle API refusals
repeated the same response construction.

Fetch inventory only for detail routes. Keep the dependency advisory
lock and transaction owned by Patches, and change selected patches in ID
order before changing the user. Share the refusal mapping without
changing wire bodies or unavailable-inventory semantics. The rollback
regression still proves patch and user changes commit together.

Stacked on #272, with base branch `portal/259-e2e-docs`. This PR
contains only the cleanup commit above that stack.

## Verification
- `pnpm lint`
- `pnpm typecheck`
- `pnpm test:postgres-concurrency` — 7 passed
- `pnpm exec vitest run packages/portal/src/PortalPages.test.ts` — 47
passed

Implemented with `openai-codex/gpt-6-astra` using Oh My Pi.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci+docs(domain): the packed e2e through the lifecycle; the map after the portal

1 participant