Add Helmer ledger apply rehearsal
Some checks are pending
CI / lint-and-test (push) Waiting to run

This commit is contained in:
twentyOne2x 2026-07-09 23:17:28 +02:00
parent 9dde83c602
commit d9c794bebc
11 changed files with 1147 additions and 58 deletions

View file

@ -32,8 +32,12 @@ Use this file before making status claims. Prefer fresh VPS/GCP readbacks when c
- Mapped production apply packet, not executed in production: `docs/reports/leo-working-state-20260709/production-apply-packet-current.md`
- Helmer 7 Powers proposal plan: `docs/reports/leo-working-state-20260709/helmer-7powers-creation-plan.json`
- Helmer 7 Powers apply packet, not executed in production: `docs/reports/leo-working-state-20260709/helmer-7powers-production-apply-packet-current.md`
- Helmer 7 Powers apply packet JSON: `docs/reports/leo-working-state-20260709/helmer-7powers-production-apply-packet.json`
- Helmer 7 Powers authorized commit SQL, not executed in production: `docs/reports/leo-working-state-20260709/helmer-7powers-production-apply-authorized-commit.sql`
- Helmer 7 Powers delete rollback SQL: `docs/reports/leo-working-state-20260709/helmer-7powers-production-delete-rollback.sql`
- Helmer live rollback log: `docs/reports/leo-working-state-20260709/helmer-7powers-live-preflight-rollback-current.log`
- Helmer clone commit/delete rollback log: `docs/reports/leo-working-state-20260709/helmer-7powers-clone-commit-delete-rollback-current.log`
- Helmer ledger clone commit/delete rollback log: `docs/reports/leo-working-state-20260709/helmer-7powers-ledger-clone-commit-delete-rollback-current.log`
## GCP
@ -44,12 +48,14 @@ Use this file before making status claims. Prefer fresh VPS/GCP readbacks when c
- Skill-pack map: `docs/reports/leo-working-state-20260709/leo-db-state-13-skill-pack.svg`
- Helmer packet proof: `docs/reports/leo-working-state-20260709/leo-db-state-14-helmer-packet.svg`
- Open-ended Cory-style canary map: `docs/reports/leo-working-state-20260709/leo-db-state-15-open-ended-canary.svg`
- Helmer ledger packet proof: `docs/reports/leo-working-state-20260709/leo-db-state-16-helmer-ledger.svg`
## Current Claim Ceiling
- VPS Leo Telegram memory, KB audit, and staged-write canaries are live-proven.
- VPS Leo open-ended Cory-style triage is live-proven for a read-only vague incident prompt.
- A strict canonical `add_edge` apply canary is live-proven.
- Rich approved proposal packets are clone/rehearsal-proven, not production-applied.
- Helmer 7 Powers is full-coverage packet and ledger clone-proven, not production-applied.
- Mapped rich approved proposal packet is clone/rehearsal-proven for the supported subset, not production-applied.
- The live VPS runtime behavior should not be changed while the DB apply path is stabilized.
- GCP parity remains blocked by account auth/access facts until a fresh readback proves otherwise.

View file

@ -0,0 +1,319 @@
== production preflight before rollback rehearsal ==
id | status | proposal_type | reviewed_by_handle | reviewed_at
--------------------------------------+----------+-----------------+--------------------+-------------------------------
a64df080-8502-42e2-98f4-9bbdecb8da73 | approved | attach_evidence | m3taversal | 2026-06-29 16:32:39.431004+00
(1 row)
check_name | id | reason
------------+----+--------
(0 rows)
expected_reasoning_tools | expected_claims | expected_sources | expected_claim_edges | expected_claim_evidence
--------------------------+-----------------+------------------+----------------------+-------------------------
1 | 5 | 13 | 7 | 17
(1 row)
generated_reasoning_tool_rows | generated_claim_rows | generated_source_rows | generated_edge_rows | generated_evidence_rows
-------------------------------+----------------------+-----------------------+---------------------+-------------------------
0 | 0 | 0 | 0 | 0
(1 row)
== production rollback-only rehearsal ==
BEGIN
SET
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
ROLLBACK
BEGIN
DO
ROLLBACK
== production preflight after rollback rehearsal ==
id | status | proposal_type | reviewed_by_handle | reviewed_at
--------------------------------------+----------+-----------------+--------------------+-------------------------------
a64df080-8502-42e2-98f4-9bbdecb8da73 | approved | attach_evidence | m3taversal | 2026-06-29 16:32:39.431004+00
(1 row)
check_name | id | reason
------------+----+--------
(0 rows)
expected_reasoning_tools | expected_claims | expected_sources | expected_claim_edges | expected_claim_evidence
--------------------------+-----------------+------------------+----------------------+-------------------------
1 | 5 | 13 | 7 | 17
(1 row)
generated_reasoning_tool_rows | generated_claim_rows | generated_source_rows | generated_edge_rows | generated_evidence_rows
-------------------------------+----------------------+-----------------------+---------------------+-------------------------
0 | 0 | 0 | 0 | 0
(1 row)
== create disposable clone ==
set_config
------------
(1 row)
== clone preflight before commit ==
id | status | proposal_type | reviewed_by_handle | reviewed_at
--------------------------------------+----------+-----------------+--------------------+-------------------------------
a64df080-8502-42e2-98f4-9bbdecb8da73 | approved | attach_evidence | m3taversal | 2026-06-29 16:32:39.431004+00
(1 row)
check_name | id | reason
------------+----+--------
(0 rows)
expected_reasoning_tools | expected_claims | expected_sources | expected_claim_edges | expected_claim_evidence
--------------------------+-----------------+------------------+----------------------+-------------------------
1 | 5 | 13 | 7 | 17
(1 row)
generated_reasoning_tool_rows | generated_claim_rows | generated_source_rows | generated_edge_rows | generated_evidence_rows
-------------------------------+----------------------+-----------------------+---------------------+-------------------------
0 | 0 | 0 | 0 | 0
(1 row)
== clone authorized commit rehearsal ==
BEGIN
SET
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
COMMIT
BEGIN
DO
COMMIT
== clone postflight after commit ==
generated_reasoning_tool_rows | generated_claim_rows | generated_source_rows | generated_edge_rows | generated_evidence_rows
-------------------------------+----------------------+-----------------------+---------------------+-------------------------
1 | 5 | 13 | 7 | 17
(1 row)
id | agent_id | name | category | description
--------------------------------------+--------------------------------------+-----------------+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
473ba7b0-ce44-5e77-bc46-ef82a49b6a3e | 11111111-1111-1111-1111-111111111111 | Helmer 7 Powers | strategy_framework | {"approval_change_log": [{"change": "Removed proposed claim #6 / teleo_power_candidate_is_credibility_and_process_not_control from this framework proposal.", "rationale": "It applies 7 Powers downstream to Teleo self-positioning; approving the framework should not accidentally approve Teleo-as-network-economies / Teleo-as-process-power claims."}, {"change": "Added competitive advantage / moats conceptual-neighborhood links for resolution.", "rationale": "7 Powers should sit in the competitive ad
(1 row)
id | type | confidence | text
--------------------------------------+------------+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12d2c4aa-1c23-5173-b666-dea903dd7432 | normative | 0.65 | Leo should use 7 Powers after inflection mapping and attractor-state analysis to distinguish builders who merely benefit from a wave from builders who can durably capture and compound value from that wave.
23927224-0d72-5b37-a600-33c63277f6a9 | structural | 0.8 | Helmer's 7 Powers framework diagnoses durable value capture only when a company has both a material benefit and a barrier that prevents motivated capable competitors from arbitraging that benefit away.
4701f303-ca9c-5da1-aa48-8cf28189c23c | structural | 0.7 | Power must be analyzed by lifecycle stage because different powers become available in Origination, Take-Off, and Stability, and the window to establish a power can close as market flux resolves.
6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3 | structural | 0.7 | Network effects create product value but do not become network economies power unless they also prevent competitors from reaching equivalence and let the focal actor capture surplus.
d2b2142b-c2d8-5e33-9a38-14598d94d715 | structural | 0.75 | Counter-positioning is most useful near inflection points because entrants can adopt a superior model while incumbents rationally delay imitation to avoid damaging their existing economics, channels, or identity.
(5 rows)
id | source_type | excerpt
--------------------------------------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
02b8c5ff-04fb-54e7-b132-e731086f1436 | other | {"excerpt": "Canonical source for the seven powers framework; source of definitions, benefit/barrier logic, Power Progression, and company examples. Full text not ingested in this run; use book/page references if availab
0c87a244-afa2-5d08-8e79-9cb792aff553 | other | {"body": null, "candidate_review_note": null, "claim_key": "agentic_capital_needs_power_analysis", "edges": [{"edge_type": "supports", "rationale": "7 Powers operationalizes scarcity/value-capture analysis for builder ev
11fa942d-e81a-5142-965d-3c60714a7dca | other | {"body": null, "candidate_review_note": null, "claim_key": "counter_positioning_is_early_inflection_power", "edges": [{"edge_type": "relates", "rationale": "Counter-positioning exploits path dependence and incumbent comm
263f423e-c16f-544c-ae5f-3e370e736e12 | other | {"body": null, "candidate_review_note": null, "claim_key": "network_effects_do_not_equal_network_power", "edges": [{"edge_type": "relates", "rationale": "Commercial network effects can be self-enforcing only when they al
2df4bb44-4853-5455-8049-6dbb8685523b | transcript | {"excerpt": "Chenyi Shi frames platform power through three questions: how economic value is created, how each customer group perceives value as the platform scales, and how competitors are prevented from reaching equiva
4bd41552-8017-551a-84b5-19b0107c20b5 | article | {"excerpt": "Helmer develops from first principles a practical theory of Strategy rooted in the notion of Power, those conditions which create the potential for persistent differential returns. The synopsis says inventio
50e0d1ef-322b-5097-afe6-c9aa5ecea5fc | article | {"excerpt": "Episode summary asks what keeps competition away and states Helmer's framework reveals conditions for persistent and durable differential returns.", "metadata": {"source_key": "nfx_podcast_summary", "title":
5f9dd7ca-83f8-5ea6-8e00-d9d13003f8fc | other | {"body": null, "candidate_review_note": null, "claim_key": "seven_powers_requires_benefit_and_barrier", "edges": [{"edge_type": "supports", "rationale": "Benefit/barrier is a precise isolating-mechanism test.", "to_exist
621bb834-6366-5940-b6c3-c5f82ba35d48 | article | {"excerpt": "Show notes emphasize 'all strategy begins with invention,' transition from startup to pricer with scale economies, competition, brand definition, and sustainable leverage/power.", "metadata": {"source_key":
6fe15936-d5b9-514e-802f-32a2a06f4a23 | article | {"excerpt": "NFX/Helmer provides concise definitions and examples for the powers: cornered resource (Pixar), scale economies (Netflix), switching costs (SAP), counter-positioning (Twilio/Tesla/Netflix), brand (Apple/Herm
97c3fc2f-16ae-5507-ad51-b1f4a1bcfb11 | other | {"body": null, "candidate_review_note": null, "claim_key": "power_progression_stage_gates_strategy", "edges": [{"edge_type": "relates", "rationale": "Stage-specific power creation supports strategy-as-design rather than
bc081b04-709f-565a-af0b-95d4ca0589fa | article | {"excerpt": "Hastings describes Helmer's Power Dynamics assessment of Netflix, identifies Counter-Positioning and Power Progression as novel conceptual advances, and says Counter-Positioning explained why incumbents rati
dc1c238c-f835-5641-980a-f0fe53f8dfe5 | transcript | {"excerpt": "Helmer states power has two necessary and sufficient conditions: benefit and barrier. Benefit is a materially better business model; barrier prevents motivated and capable competitors from taking it away. He
(13 rows)
from_claim | to_claim | edge_type
--------------------------------------+--------------------------------------+-----------
12d2c4aa-1c23-5173-b666-dea903dd7432 | 2ef388ab-4102-4416-a6e1-ae6ba8ee02fa | supports
12d2c4aa-1c23-5173-b666-dea903dd7432 | 8f3e773e-4255-47a7-ba8f-61c57a43bebe | supports
23927224-0d72-5b37-a600-33c63277f6a9 | 2ef388ab-4102-4416-a6e1-ae6ba8ee02fa | relates
23927224-0d72-5b37-a600-33c63277f6a9 | 8f3e773e-4255-47a7-ba8f-61c57a43bebe | supports
4701f303-ca9c-5da1-aa48-8cf28189c23c | 25a350e0-ebce-4072-8f2a-48427a727553 | relates
6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3 | 93d583d9-5394-4e6a-97ca-bcd48796d94a | relates
d2b2142b-c2d8-5e33-9a38-14598d94d715 | be59b559-de8b-4dec-a7be-773188c0e632 | relates
(7 rows)
claim_id | source_id | role
--------------------------------------+--------------------------------------+-------------
12d2c4aa-1c23-5173-b666-dea903dd7432 | 0c87a244-afa2-5d08-8e79-9cb792aff553 | illustrates
12d2c4aa-1c23-5173-b666-dea903dd7432 | 4bd41552-8017-551a-84b5-19b0107c20b5 | grounds
12d2c4aa-1c23-5173-b666-dea903dd7432 | dc1c238c-f835-5641-980a-f0fe53f8dfe5 | grounds
23927224-0d72-5b37-a600-33c63277f6a9 | 5f9dd7ca-83f8-5ea6-8e00-d9d13003f8fc | illustrates
23927224-0d72-5b37-a600-33c63277f6a9 | 6fe15936-d5b9-514e-802f-32a2a06f4a23 | grounds
23927224-0d72-5b37-a600-33c63277f6a9 | dc1c238c-f835-5641-980a-f0fe53f8dfe5 | grounds
4701f303-ca9c-5da1-aa48-8cf28189c23c | 4bd41552-8017-551a-84b5-19b0107c20b5 | grounds
4701f303-ca9c-5da1-aa48-8cf28189c23c | 97c3fc2f-16ae-5507-ad51-b1f4a1bcfb11 | illustrates
4701f303-ca9c-5da1-aa48-8cf28189c23c | bc081b04-709f-565a-af0b-95d4ca0589fa | grounds
4701f303-ca9c-5da1-aa48-8cf28189c23c | dc1c238c-f835-5641-980a-f0fe53f8dfe5 | grounds
6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3 | 263f423e-c16f-544c-ae5f-3e370e736e12 | illustrates
6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3 | 2df4bb44-4853-5455-8049-6dbb8685523b | grounds
6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3 | 6fe15936-d5b9-514e-802f-32a2a06f4a23 | grounds
d2b2142b-c2d8-5e33-9a38-14598d94d715 | 11fa942d-e81a-5142-965d-3c60714a7dca | illustrates
d2b2142b-c2d8-5e33-9a38-14598d94d715 | 6fe15936-d5b9-514e-802f-32a2a06f4a23 | grounds
d2b2142b-c2d8-5e33-9a38-14598d94d715 | bc081b04-709f-565a-af0b-95d4ca0589fa | grounds
d2b2142b-c2d8-5e33-9a38-14598d94d715 | dc1c238c-f835-5641-980a-f0fe53f8dfe5 | grounds
(17 rows)
id | superseded_by
----+---------------
(0 rows)
id | status | applied_by_handle | applied_at
--------------------------------------+---------+-----------------------+-------------------------------
a64df080-8502-42e2-98f4-9bbdecb8da73 | applied | codex-packet-20260709 | 2026-07-09 21:14:11.331665+00
(1 row)
== clone delete rollback including proposal status restore ==
BEGIN
DELETE 17
DELETE 7
UPDATE 0
DELETE 13
DELETE 5
DELETE 1
DO
COMMIT
== clone postflight after delete rollback ==
generated_reasoning_tool_rows | generated_claim_rows | generated_source_rows | generated_edge_rows | generated_evidence_rows
-------------------------------+----------------------+-----------------------+---------------------+-------------------------
0 | 0 | 0 | 0 | 0
(1 row)
id | agent_id | name | category | description
----+----------+------+----------+-------------
(0 rows)
id | type | confidence | text
----+------+------------+------
(0 rows)
id | source_type | excerpt
----+-------------+---------
(0 rows)
from_claim | to_claim | edge_type
------------+----------+-----------
(0 rows)
claim_id | source_id | role
----------+-----------+------
(0 rows)
id | superseded_by
----+---------------
(0 rows)
id | status | applied_by_handle | applied_at
--------------------------------------+----------+-------------------+------------
a64df080-8502-42e2-98f4-9bbdecb8da73 | approved | |
(1 row)
== production preflight after clone rehearsal ==
id | status | proposal_type | reviewed_by_handle | reviewed_at
--------------------------------------+----------+-----------------+--------------------+-------------------------------
a64df080-8502-42e2-98f4-9bbdecb8da73 | approved | attach_evidence | m3taversal | 2026-06-29 16:32:39.431004+00
(1 row)
check_name | id | reason
------------+----+--------
(0 rows)
expected_reasoning_tools | expected_claims | expected_sources | expected_claim_edges | expected_claim_evidence
--------------------------+-----------------+------------------+----------------------+-------------------------
1 | 5 | 13 | 7 | 17
(1 row)
generated_reasoning_tool_rows | generated_claim_rows | generated_source_rows | generated_edge_rows | generated_evidence_rows
-------------------------------+----------------------+-----------------------+---------------------+-------------------------
0 | 0 | 0 | 0 | 0
(1 row)
== cleanup disposable clone ==
0
== service stability ==
3252143
0
Thu 2026-07-09 06:59:44 UTC
/home/teleo
teleo
active
running

File diff suppressed because one or more lines are too long

View file

@ -1,10 +1,12 @@
# Helmer 7 Powers Production Apply Packet - 2026-07-09
# Helmer 7 Powers Production Apply Packet - Ledger-Proven Refresh - 2026-07-09
Status: packet ready and clone-proven; not executed on production.
Generated UTC: `2026-07-09T21:15:06.276683+00:00`
Status: full-coverage packet ready and clone-proven; not executed on production.
Proposal:
- `a64df080-8502-42e2-98f4-9bbdecb8da73`
- Status on production preflight: `approved`
- Production status on preflight: `approved`
- Proposal type: `attach_evidence`
- Reviewer: `m3taversal`
- Reviewed at: `2026-06-29 16:32:39.431004+00`
@ -16,25 +18,35 @@ Generated row contract:
- `public.claim_edges`: 7 rows
- `public.claim_evidence`: 17 rows
Ledger behavior:
- `marks_original_proposals_applied`: `true`
- `applied_by_handle`: `codex-packet-20260709`
- Remaining blocked fragments: `0`
- Unresolved design decisions: `0`
Important boundary:
- The canonical reasoning-tool row is sanitized: Teleo-specific self-positioning/application examples are removed from the reasoning-tool description and counted as deferred.
- The packet does not mark the original `kb_stage.kb_proposals` row as `applied`.
- Because the packet has full coverage for the approved Helmer framework contract and no blocked fragments, the authorized commit SQL now marks the original `kb_stage.kb_proposals` row as `applied` after generated rows are written.
- The mapped internet-finance/Hayek packet still refuses this ledger behavior because it has unresolved non-claim/cross-table fragments.
- Production commit SQL exists only for separately authorized execution. It has not been run against production.
Live production rehearsal:
Live production rollback rehearsal:
- Preflight found the proposal approved and all required existing target claims present.
- Preflight generated-row counts were `0/0/0/0/0` for reasoning tool / claims / sources / edges / evidence.
- Rollback-only apply rehearsal inserted the planned rows inside a transaction and ended with `ROLLBACK`.
- Post-rehearsal production generated-row counts remained `0/0/0/0/0`.
- Rollback-only apply rehearsal inserted the planned rows and executed the proposal-ledger update inside transactions ending with `ROLLBACK`.
- Post-rehearsal production generated-row counts remained `0/0/0/0/0` and proposal status remained `approved`.
Disposable clone proof:
- Disposable DB: `teleo_helmer_rehearsal_20260709`
- Disposable DB: `teleo_helmer_ledger_rehearsal_20260709`
- Clone commit produced `1` reasoning tool, `5` claims, `13` sources, `7` claim edges, and `17` claim evidence rows.
- Clone postflight read back reasoning tool `473ba7b0-ce44-5e77-bc46-ef82a49b6a3e` named `Helmer 7 Powers`.
- Clone postflight read back proposal `a64df080-8502-42e2-98f4-9bbdecb8da73` as `applied` with `applied_by_handle = codex-packet-20260709`.
- Delete rollback removed `17` evidence rows, `7` edge rows, `13` source rows, `5` claim rows, and `1` reasoning-tool row.
- Delete rollback restored the proposal ledger to `approved` with blank `applied_by_handle`/`applied_at`.
- Clone after delete returned generated-row counts to `0/0/0/0/0`.
- Production after clone remained `0/0/0/0/0`.
- Production after clone remained `0/0/0/0/0` and proposal status remained `approved`.
- Disposable clone was dropped; final clone DB count was `0`.
- VPS service stayed active/running with PID `3252143`, restarts `0`.
Packet files:
- `production-preflight.sql`
@ -43,9 +55,7 @@ Packet files:
- `production-postflight.sql`
- `production-delete-rollback.sql`
- `production-apply-packet.json`
- `production-apply-packet-summary.json`
- `live-preflight-rollback-current.log`
- `clone-commit-delete-rollback-current.log`
- `ledger-clone-commit-delete-rollback-current.log`
Claim ceiling:
This proves the approved Helmer 7 Powers framework can be represented and rolled back safely using current canonical tables. It does not prove production has been updated, because production commit was intentionally not executed.
This proves the approved Helmer 7 Powers framework can be represented, applied, ledger-marked, and rolled back safely in a disposable clone using current canonical tables. It does not prove production has been updated, because production commit was intentionally not executed.

View file

@ -0,0 +1,41 @@
{
"applied_by_handle": "codex-packet-20260709",
"claim_ceiling": "Production apply packet for full covered proposal contract; authorized commit SQL marks original proposal(s) applied after generated rows are written.",
"marks_original_proposals_applied": true,
"packet_version": 1,
"plan_path": "/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/outputs/rich-proposal-creation-plan-20260709/helmer-7powers-20260709/helmer-7powers-creation-plan.json",
"proposal_ids": [
"a64df080-8502-42e2-98f4-9bbdecb8da73"
],
"remaining_blocked_fragments": [],
"required_existing_claims": [
{
"id": "25a350e0-ebce-4072-8f2a-48427a727553",
"reason": "claim_edges.to_claim"
},
{
"id": "2ef388ab-4102-4416-a6e1-ae6ba8ee02fa",
"reason": "claim_edges.to_claim"
},
{
"id": "8f3e773e-4255-47a7-ba8f-61c57a43bebe",
"reason": "claim_edges.to_claim"
},
{
"id": "93d583d9-5394-4e6a-97ca-bcd48796d94a",
"reason": "claim_edges.to_claim"
},
{
"id": "be59b559-de8b-4dec-a7be-773188c0e632",
"reason": "claim_edges.to_claim"
}
],
"row_counts": {
"claim_edges": 7,
"claim_evidence": 17,
"claims": 5,
"reasoning_tools": 1,
"sources": 13
},
"unresolved_design_decisions": []
}

View file

@ -0,0 +1,103 @@
\set ON_ERROR_STOP on
-- Emergency rollback for the mapped generated rows only.
-- Run only before any later production data depends on these generated rows.
begin;
delete from public.claim_evidence ce
using (values
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid, '5f9dd7ca-83f8-5ea6-8e00-d9d13003f8fc'::uuid, 'illustrates'::evidence_role),
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid, 'dc1c238c-f835-5641-980a-f0fe53f8dfe5'::uuid, 'grounds'::evidence_role),
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid, '6fe15936-d5b9-514e-802f-32a2a06f4a23'::uuid, 'grounds'::evidence_role),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid, '97c3fc2f-16ae-5507-ad51-b1f4a1bcfb11'::uuid, 'illustrates'::evidence_role),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid, '4bd41552-8017-551a-84b5-19b0107c20b5'::uuid, 'grounds'::evidence_role),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid, 'bc081b04-709f-565a-af0b-95d4ca0589fa'::uuid, 'grounds'::evidence_role),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid, 'dc1c238c-f835-5641-980a-f0fe53f8dfe5'::uuid, 'grounds'::evidence_role),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid, '11fa942d-e81a-5142-965d-3c60714a7dca'::uuid, 'illustrates'::evidence_role),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid, 'dc1c238c-f835-5641-980a-f0fe53f8dfe5'::uuid, 'grounds'::evidence_role),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid, 'bc081b04-709f-565a-af0b-95d4ca0589fa'::uuid, 'grounds'::evidence_role),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid, '6fe15936-d5b9-514e-802f-32a2a06f4a23'::uuid, 'grounds'::evidence_role),
('6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3'::uuid, '263f423e-c16f-544c-ae5f-3e370e736e12'::uuid, 'illustrates'::evidence_role),
('6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3'::uuid, '2df4bb44-4853-5455-8049-6dbb8685523b'::uuid, 'grounds'::evidence_role),
('6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3'::uuid, '6fe15936-d5b9-514e-802f-32a2a06f4a23'::uuid, 'grounds'::evidence_role),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid, '0c87a244-afa2-5d08-8e79-9cb792aff553'::uuid, 'illustrates'::evidence_role),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid, '4bd41552-8017-551a-84b5-19b0107c20b5'::uuid, 'grounds'::evidence_role),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid, 'dc1c238c-f835-5641-980a-f0fe53f8dfe5'::uuid, 'grounds'::evidence_role)
) as v(claim_id, source_id, role)
where ce.claim_id = v.claim_id and ce.source_id = v.source_id and ce.role = v.role;
delete from public.claim_edges e
using (values
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid, '8f3e773e-4255-47a7-ba8f-61c57a43bebe'::uuid, 'supports'::edge_type),
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid, '2ef388ab-4102-4416-a6e1-ae6ba8ee02fa'::uuid, 'relates'::edge_type),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid, '25a350e0-ebce-4072-8f2a-48427a727553'::uuid, 'relates'::edge_type),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid, 'be59b559-de8b-4dec-a7be-773188c0e632'::uuid, 'relates'::edge_type),
('6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3'::uuid, '93d583d9-5394-4e6a-97ca-bcd48796d94a'::uuid, 'relates'::edge_type),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid, '2ef388ab-4102-4416-a6e1-ae6ba8ee02fa'::uuid, 'supports'::edge_type),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid, '8f3e773e-4255-47a7-ba8f-61c57a43bebe'::uuid, 'supports'::edge_type)
) as v(from_claim, to_claim, edge_type)
where e.from_claim = v.from_claim and e.to_claim = v.to_claim and e.edge_type = v.edge_type;
update public.claims
set superseded_by = null,
updated_at = now()
where superseded_by in (select id from (values
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid),
('6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3'::uuid),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid)
) as v(id));
delete from public.sources
where id in (select id from (values
('02b8c5ff-04fb-54e7-b132-e731086f1436'::uuid),
('4bd41552-8017-551a-84b5-19b0107c20b5'::uuid),
('bc081b04-709f-565a-af0b-95d4ca0589fa'::uuid),
('dc1c238c-f835-5641-980a-f0fe53f8dfe5'::uuid),
('2df4bb44-4853-5455-8049-6dbb8685523b'::uuid),
('6fe15936-d5b9-514e-802f-32a2a06f4a23'::uuid),
('50e0d1ef-322b-5097-afe6-c9aa5ecea5fc'::uuid),
('621bb834-6366-5940-b6c3-c5f82ba35d48'::uuid),
('5f9dd7ca-83f8-5ea6-8e00-d9d13003f8fc'::uuid),
('97c3fc2f-16ae-5507-ad51-b1f4a1bcfb11'::uuid),
('11fa942d-e81a-5142-965d-3c60714a7dca'::uuid),
('263f423e-c16f-544c-ae5f-3e370e736e12'::uuid),
('0c87a244-afa2-5d08-8e79-9cb792aff553'::uuid)
) as v(id));
delete from public.claims
where id in (select id from (values
('23927224-0d72-5b37-a600-33c63277f6a9'::uuid),
('4701f303-ca9c-5da1-aa48-8cf28189c23c'::uuid),
('d2b2142b-c2d8-5e33-9a38-14598d94d715'::uuid),
('6014c3ea-3ba5-5ed1-bf15-31f6938e3fc3'::uuid),
('12d2c4aa-1c23-5173-b666-dea903dd7432'::uuid)
) as v(id));
delete from public.reasoning_tools
where id in (select id from (values
('473ba7b0-ce44-5e77-bc46-ef82a49b6a3e'::uuid)
) as v(id));
do $$
declare
restored int;
begin
update kb_stage.kb_proposals
set status = 'approved',
applied_by_handle = null,
applied_by_agent_id = null,
applied_at = null,
updated_at = now()
where id in (select id from (values
('a64df080-8502-42e2-98f4-9bbdecb8da73'::uuid)
) as v(id))
and status = 'applied';
get diagnostics restored = row_count;
if restored <> 1 then
raise exception 'rich proposal packet ledger rollback restored % row(s), expected 1; original proposals were not all applied', restored;
end if;
end $$;
commit;

View file

@ -0,0 +1,48 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1120" height="650" viewBox="0 0 1120 650">
<rect width="1120" height="650" fill="#f8fafc"/>
<text x="48" y="58" font-family="Arial, sans-serif" font-size="30" font-weight="700" fill="#0f172a">Helmer 7 Powers: Full-Coverage Apply Packet</text>
<text x="48" y="92" font-family="Arial, sans-serif" font-size="16" fill="#475569">Rows + proposal ledger are clone-proven. Production remains unchanged until explicit apply authorization.</text>
<g font-family="Arial, sans-serif">
<rect x="48" y="132" width="250" height="128" rx="8" fill="#e0f2fe" stroke="#0284c7"/>
<text x="68" y="168" font-size="18" font-weight="700" fill="#075985">Production Preflight</text>
<text x="68" y="198" font-size="14" fill="#075985">proposal: approved</text>
<text x="68" y="220" font-size="14" fill="#075985">generated rows: 0/0/0/0/0</text>
<text x="68" y="242" font-size="14" fill="#075985">missing required claims: 0</text>
<path d="M308 196 H388" stroke="#64748b" stroke-width="3" marker-end="url(#arrow)"/>
<rect x="398" y="132" width="300" height="128" rx="8" fill="#dcfce7" stroke="#16a34a"/>
<text x="418" y="168" font-size="18" font-weight="700" fill="#166534">Disposable Clone Commit</text>
<text x="418" y="198" font-size="14" fill="#166534">reasoning tools / claims / sources</text>
<text x="418" y="220" font-size="14" fill="#166534">1 / 5 / 13</text>
<text x="418" y="242" font-size="14" fill="#166534">edges / evidence: 7 / 17</text>
<path d="M708 196 H788" stroke="#64748b" stroke-width="3" marker-end="url(#arrow)"/>
<rect x="798" y="132" width="274" height="128" rx="8" fill="#fef3c7" stroke="#d97706"/>
<text x="818" y="168" font-size="18" font-weight="700" fill="#92400e">Proposal Ledger</text>
<text x="818" y="198" font-size="14" fill="#92400e">a64df080 -> applied</text>
<text x="818" y="220" font-size="14" fill="#92400e">applied_by: codex-packet-20260709</text>
<text x="818" y="242" font-size="14" fill="#92400e">guard: approved row count = 1</text>
<rect x="48" y="318" width="318" height="150" rx="8" fill="#ecfdf5" stroke="#10b981"/>
<text x="68" y="354" font-size="18" font-weight="700" fill="#065f46">Delete Rollback</text>
<text x="68" y="386" font-size="14" fill="#065f46">deleted evidence/edges/sources/claims/tool</text>
<text x="68" y="410" font-size="14" fill="#065f46">restored proposal status to approved</text>
<text x="68" y="434" font-size="14" fill="#065f46">clone rows after rollback: 0/0/0/0/0</text>
<rect x="402" y="318" width="318" height="150" rx="8" fill="#eff6ff" stroke="#2563eb"/>
<text x="422" y="354" font-size="18" font-weight="700" fill="#1e40af">Production Stayed Clean</text>
<text x="422" y="386" font-size="14" fill="#1e40af">generated rows after rehearsal: 0/0/0/0/0</text>
<text x="422" y="410" font-size="14" fill="#1e40af">proposal status: approved</text>
<text x="422" y="434" font-size="14" fill="#1e40af">no production commit executed</text>
<rect x="756" y="318" width="316" height="150" rx="8" fill="#f1f5f9" stroke="#64748b"/>
<text x="776" y="354" font-size="18" font-weight="700" fill="#334155">Guardrail</text>
<text x="776" y="386" font-size="14" fill="#334155">full coverage only</text>
<text x="776" y="410" font-size="14" fill="#334155">partial mapped packet refused ledger mark</text>
<text x="776" y="434" font-size="14" fill="#334155">VPS service active, restarts 0</text>
</g>
<text x="48" y="558" font-family="Arial, sans-serif" font-size="16" fill="#475569">Claim ceiling: production apply still requires explicit authorization; this is clone proof and production rollback-only proof.</text>
<defs><marker id="arrow" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto" markerUnits="strokeWidth"><path d="M0,0 L0,6 L9,3 z" fill="#64748b"/></marker></defs>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -1,6 +1,6 @@
# Working Leo Current State - 2026-07-09
Generated UTC: `2026-07-09T20:32:38Z`
Generated UTC: `2026-07-09T21:15:00Z`
## Current Working Definition
@ -16,6 +16,11 @@ A working Leo, for Cory/m3taversal's current expectation, is a Telegram-facing a
- turn 2 reply preserved the correction `approved is not the same as applied`
- turn 2 reply reported proposal `00957f6c-9883-4015-95a4-6b09367efb0e` as `applied`
- turn 2 reply reported edge `c167933e-d513-4f43-9335-d5d8aeb259f2` exists in `public.claim_edges` and the canonical row exists
- Open-ended Cory-style Telegram canary passed:
- marker `WL-LIVE-TG-CORY-OPEN-20260709`
- Leo inferred the likely failure mode from "agents not working / KB same as last night" without exact proposal IDs
- Leo named `kb_stage.kb_proposals`, gateway/scheduler logs, and canonical `public.*` graph deltas as first checks
- Leo distinguished proposed, approved, and applied without staging or mutating the KB
- Telegram-shaped handler canary passed in the same user/cwd context as the live service:
- authorized source: `agent:main:telegram:group:-5146042086:9070919`
- turn 1 ack passed
@ -34,10 +39,9 @@ A working Leo, for Cory/m3taversal's current expectation, is a Telegram-facing a
## What Is Still Not Proven
- Old Cory-approved proposals are still not directly applyable:
- Old Cory-approved mapped rich proposals are still not fully directly applyable:
- `14fa5ecc-ac7a-41c1-807d-a2e85b936617`
- `ac036c9d-20a0-4ffe-881f-57d6b7bacf22`
- `a64df080-8502-42e2-98f4-9bbdecb8da73`
- `14fa5ecc` normalization is blocked by missing canonical claim/source IDs. The proposal contains approved textual successor candidates, but the exact successor rows A/B/C/D do not already exist as canonical rows.
- Current narrow apply worker supports `add_edge`, `attach_evidence`, and `revise_strategy`; it does not create new `public.claims` or `public.sources` rows. Applying `14fa5ecc` as Cory likely expects requires either creating/identifying canonical rows first or explicitly widening the guarded apply contract.
- Live approved rich proposal contract preview is now available:
@ -68,13 +72,14 @@ A working Leo, for Cory/m3taversal's current expectation, is a Telegram-facing a
- clone post-commit readback showed DB-side `superseded_by` pointers are set by generated `supersedes` edges for `7da4851c...` and `d0000000...`
- packet delete rollback now clears those exact `superseded_by` pointers, deletes generated rows, and returns clone generated-row counts to `0/0/0/0`
- production generated rows remain `0/0/0/0`; disposable packet clone and temp dump were removed
- Helmer 7 Powers approved proposal `a64df080-8502-42e2-98f4-9bbdecb8da73` is now packet-ready and clone-proven:
- Helmer 7 Powers approved proposal `a64df080-8502-42e2-98f4-9bbdecb8da73` is now full-coverage packet-ready and ledger clone-proven:
- generated row contract is `1` reasoning tool, `5` claims, `13` sources, `7` claim_edges, and `17` claim_evidence rows
- canonical reasoning-tool description is sanitized so Teleo-specific self-positioning/application examples are deferred rather than canonically approved through the framework proposal
- live production preflight confirms the proposal is approved, required existing target claims are present, and generated rows are `0/0/0/0/0`
- live production rollback rehearsal inserted the planned rows inside a transaction and rolled back cleanly
- disposable clone `teleo_helmer_rehearsal_20260709` committed the packet and read back `1/5/13/7/17`
- clone delete rollback returned generated rows to `0/0/0/0/0`
- live production rollback rehearsal inserted the planned rows and proposal-ledger update inside transactions and rolled back cleanly
- disposable clone `teleo_helmer_ledger_rehearsal_20260709` committed the packet and read back `1/5/13/7/17`
- clone postflight read back proposal `a64df080-8502-42e2-98f4-9bbdecb8da73` as `applied` with `applied_by_handle=codex-packet-20260709`
- clone delete rollback returned generated rows to `0/0/0/0/0` and restored the proposal ledger to `approved`
- production generated rows remain `0/0/0/0/0`; disposable clone was dropped with final clone count `0`
- GCP parity was rechecked and remains blocked on account authentication:
- `billy@livingip.xyz` is selected for project `teleo-501523` but token refresh fails non-interactively
@ -96,6 +101,7 @@ A working Leo, for Cory/m3taversal's current expectation, is a Telegram-facing a
- Mapped rich proposal creation plan: `outputs/rich-proposal-creation-plan-20260709/rich-proposal-creation-plan-mapped-current.md`
- Production apply packet for mapped subset: `outputs/rich-proposal-creation-plan-20260709/production-apply-packet-mapped-20260709/production-apply-packet-current.md`
- Helmer 7 Powers apply packet: `outputs/rich-proposal-creation-plan-20260709/helmer-7powers-20260709/production-apply-packet/production-apply-packet-current.md`
- Helmer 7 Powers ledger proof log: `outputs/rich-proposal-creation-plan-20260709/helmer-7powers-20260709/production-apply-packet/ledger-clone-commit-delete-rollback-current.log`
- Execution plan: `outputs/working-leo-execution-plan-20260709/working-leo-execution-plan-current.md`
- Cory expected outcomes: `outputs/cory-expected-working-leo-outcomes-20260709.md`
- Current live proof image: `outputs/leo-db-state-07-live-proof.svg`
@ -105,6 +111,8 @@ A working Leo, for Cory/m3taversal's current expectation, is a Telegram-facing a
- Mapped staging proof image: `outputs/leo-db-state-11-mapped-staging.svg`
- Production packet proof image: `outputs/leo-db-state-12-production-packet.svg`
- Helmer packet proof image: `outputs/leo-db-state-14-helmer-packet.svg`
- Open-ended Cory-style canary image: `outputs/leo-db-state-15-open-ended-canary.svg`
- Helmer ledger proof image: `outputs/leo-db-state-16-helmer-ledger.svg`
- GCP parity blocker: `outputs/gcp-db-parity-current-blocker-20260709.json`
## Next Actions

View file

@ -1,6 +1,6 @@
# Working Leo Execution Plan - 2026-07-09
Claim ceiling: VPS Telegram memory/KB audit, Telegram-to-`kb_stage` proposal staging, and strict existing-ID apply are working; rich approved packet row creation is clone-commit proven and now has a production apply packet for the mapped supported subset, but production has not been applied; non-claim target decisions and GCP parity remain pending.
Claim ceiling: VPS Telegram memory/KB audit, open-ended Cory-style triage, Telegram-to-`kb_stage` proposal staging, and strict existing-ID apply are working. Helmer 7 Powers is full-coverage packet and ledger clone-proven, but not production-applied. The mapped rich packet is clone-proven only for its supported subset; non-claim target decisions and GCP parity remain pending.
## WL-EXEC-01 - VPS Telegram-visible memory + KB audit
- Status: `done`
@ -50,11 +50,11 @@ Claim ceiling: VPS Telegram memory/KB audit, Telegram-to-`kb_stage` proposal sta
## WL-EXEC-05C - Helmer 7 Powers approved proposal packet
- Status: `done_packet_ready_not_executed`
- Result: Generated packet for proposal `a64df080-8502-42e2-98f4-9bbdecb8da73` with 1 reasoning tool, 5 claims, 13 sources, 7 edges, and 17 evidence rows. Live production preflight and rollback rehearsal passed; disposable clone commit/readback produced `1/5/13/7/17`; delete rollback returned clone generated rows to `0/0/0/0/0`; production stayed zero.
- Result: Generated full-coverage packet for proposal `a64df080-8502-42e2-98f4-9bbdecb8da73` with 1 reasoning tool, 5 claims, 13 sources, 7 edges, and 17 evidence rows. Live production preflight and rollback rehearsal passed; disposable clone commit/readback produced `1/5/13/7/17` and marked the proposal `applied`; delete rollback returned clone generated rows to `0/0/0/0/0` and restored the proposal to `approved`; production stayed zero.
- Not done condition: Production canonical rows remain unapplied until explicit production apply authorization.
- Evidence:
- `/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/outputs/rich-proposal-creation-plan-20260709/helmer-7powers-20260709/production-apply-packet/production-apply-packet-current.md`
- `/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/outputs/rich-proposal-creation-plan-20260709/helmer-7powers-20260709/production-apply-packet/clone-commit-delete-rollback-current.log`
- `/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/outputs/rich-proposal-creation-plan-20260709/helmer-7powers-20260709/production-apply-packet/ledger-clone-commit-delete-rollback-current.log`
## WL-EXEC-06 - Reviewed decisions for unsupported rich-packet fragments
- Status: `partially_resolved_pending_non_claim_target_decisions`

View file

@ -12,9 +12,10 @@ proposal creation plan into reproducible SQL files:
* postflight SQL: exact generated-row count/readback;
* rollback-delete SQL: exact reverse deletes for the generated rows.
The packet intentionally does not mark the original rich proposals as applied.
The mapped subset is partial while non-claim targets remain unresolved; marking
the original proposals applied would overstate DB state.
The packet marks original rich proposals as applied only when explicitly
requested and the plan has no remaining blocked fragments or unresolved design
decisions. Mapped subsets must leave the original proposals approved, because
marking a partial packet applied would overstate DB state.
"""
from __future__ import annotations
@ -92,6 +93,34 @@ def collect_required_existing_claims(rows: dict[str, list[dict[str, Any]]]) -> l
return [{"id": claim_id, "reason": reason} for claim_id, reason in sorted(required.items())]
def collect_blocked_fragments(plans: list[dict[str, Any]]) -> list[dict[str, Any]]:
return [
fragment
for plan in plans
for fragment in plan.get("blocked_fragments", [])
if isinstance(fragment, dict)
]
def collect_unresolved_design_decisions(plans: list[dict[str, Any]]) -> list[dict[str, Any]]:
return [
item
for plan in plans
for item in plan.get("unresolved_design_decisions", [])
if isinstance(item, dict)
]
def assert_can_mark_original_proposals_applied(plans: list[dict[str, Any]]) -> None:
blocked = collect_blocked_fragments(plans)
unresolved = collect_unresolved_design_decisions(plans)
if blocked or unresolved:
raise ValueError(
"cannot mark original proposals applied for a partial packet: "
f"{len(blocked)} blocked fragment(s), {len(unresolved)} unresolved design decision(s)"
)
def build_generated_counts_sql(rows: dict[str, list[dict[str, Any]]]) -> str:
reasoning_tool_ids = [row["id"] for row in rows["reasoning_tools"]]
claim_ids = [row["id"] for row in rows["claims"]]
@ -105,6 +134,35 @@ def build_generated_counts_sql(rows: dict[str, list[dict[str, Any]]]) -> str:
"""
def build_mark_original_proposals_sql(plans: list[dict[str, Any]], *, commit: bool, applied_by_handle: str) -> str:
proposal_ids = [str(plan.get("proposal_id")) for plan in plans if plan.get("proposal_id")]
if not proposal_ids:
raise ValueError("cannot mark original proposals applied without proposal ids")
terminator = "commit;" if commit else "rollback;"
return f"""begin;
do $$
declare
flipped int;
begin
update kb_stage.kb_proposals
set status = 'applied',
applied_by_handle = {creation_plan._sql_literal(applied_by_handle)},
applied_at = now(),
updated_at = now()
where id in (select id from {_uuid_values(proposal_ids)})
and status = 'approved';
get diagnostics flipped = row_count;
if flipped <> {len(proposal_ids)} then
raise exception 'rich proposal packet ledger flip affected % row(s), expected {len(proposal_ids)}; original proposals were not all approved', flipped;
end if;
end $$;
{terminator}
"""
def build_preflight_sql(plans: list[dict[str, Any]], rows: dict[str, list[dict[str, Any]]]) -> str:
proposal_ids = [str(plan.get("proposal_id")) for plan in plans if plan.get("proposal_id")]
required_claims = collect_required_existing_claims(rows)
@ -148,13 +206,31 @@ select {expected['reasoning_tools']}::int as expected_reasoning_tools,
{build_generated_counts_sql(rows)}"""
def build_write_sql(plans: list[dict[str, Any]], *, commit: bool) -> str:
def build_write_sql(
plans: list[dict[str, Any]],
*,
commit: bool,
mark_original_proposals_applied: bool,
applied_by_handle: str,
) -> str:
sql = "\n\n".join(plan.get("rollback_rehearsal_sql", "") for plan in plans)
terminator = "commit;" if commit else "rollback;"
return sql.replace("rollback;", terminator)
write_sql = sql.replace("rollback;", terminator)
if mark_original_proposals_applied:
write_sql = (
write_sql.rstrip()
+ "\n\n-- Full-coverage packet ledger update: mark original approved proposal(s) applied only after generated rows exist.\n"
+ build_mark_original_proposals_sql(plans, commit=commit, applied_by_handle=applied_by_handle)
)
return write_sql
def build_postflight_sql(rows: dict[str, list[dict[str, Any]]]) -> str:
def build_postflight_sql(
rows: dict[str, list[dict[str, Any]]],
*,
proposal_ids: list[str],
include_original_proposal_readback: bool,
) -> str:
reasoning_tool_ids = [row["id"] for row in rows["reasoning_tools"]]
claim_ids = [row["id"] for row in rows["claims"]]
source_ids = [row["id"] for row in rows["sources"]]
@ -192,10 +268,24 @@ select id::text, superseded_by::text
from public.claims
where superseded_by in (select id from {_uuid_values(claim_ids)})
order by id;
""" + (
f"""
select id::text, status, applied_by_handle, applied_at
from kb_stage.kb_proposals
where id in (select id from {_uuid_values(proposal_ids)})
order by id;
"""
if include_original_proposal_readback
else ""
)
def build_delete_rollback_sql(rows: dict[str, list[dict[str, Any]]]) -> str:
def build_delete_rollback_sql(
rows: dict[str, list[dict[str, Any]]],
*,
proposal_ids: list[str],
restore_original_proposals_approved: bool,
) -> str:
reasoning_tool_ids = [row["id"] for row in rows["reasoning_tools"]]
claim_ids = [row["id"] for row in rows["claims"]]
source_ids = [row["id"] for row in rows["sources"]]
@ -226,42 +316,97 @@ where id in (select id from {_uuid_values(claim_ids)});
delete from public.reasoning_tools
where id in (select id from {_uuid_values(reasoning_tool_ids)});
{build_restore_original_proposals_sql(proposal_ids) if restore_original_proposals_approved else ""}
commit;
"""
def build_packet(plan_path: Path, *, emit_commit_sql: bool) -> dict[str, Any]:
def build_restore_original_proposals_sql(proposal_ids: list[str]) -> str:
if not proposal_ids:
return ""
return f"""do $$
declare
restored int;
begin
update kb_stage.kb_proposals
set status = 'approved',
applied_by_handle = null,
applied_by_agent_id = null,
applied_at = null,
updated_at = now()
where id in (select id from {_uuid_values(proposal_ids)})
and status = 'applied';
get diagnostics restored = row_count;
if restored <> {len(proposal_ids)} then
raise exception 'rich proposal packet ledger rollback restored % row(s), expected {len(proposal_ids)}; original proposals were not all applied', restored;
end if;
end $$;"""
def build_packet(
plan_path: Path,
*,
emit_commit_sql: bool,
mark_original_proposals_applied: bool = False,
applied_by_handle: str = "codex-packet",
) -> dict[str, Any]:
plans = load_creation_plans(plan_path)
if mark_original_proposals_applied:
assert_can_mark_original_proposals_applied(plans)
rows = collect_rows(plans)
proposal_ids = [str(plan.get("proposal_id")) for plan in plans if plan.get("proposal_id")]
remaining_blocked_fragments = collect_blocked_fragments(plans)
unresolved_design_decisions = collect_unresolved_design_decisions(plans)
claim_ceiling = (
"Production apply packet for full covered proposal contract; authorized commit SQL marks original proposal(s) "
"applied after generated rows are written."
if mark_original_proposals_applied
else (
"Production apply packet for mapped supported subset only; original rich proposals are not marked applied "
"unless the packet fully covers the approved reasoning-tool/claim/source contract."
)
)
return {
"packet_version": 1,
"plan_path": str(plan_path),
"proposal_ids": [plan.get("proposal_id") for plan in plans],
"claim_ceiling": (
"Production apply packet for mapped supported subset only; original rich proposals are not marked applied "
"unless the packet fully covers the approved reasoning-tool/claim/source contract."
),
"proposal_ids": proposal_ids,
"claim_ceiling": claim_ceiling,
"row_counts": {key: len(value) for key, value in rows.items()},
"required_existing_claims": collect_required_existing_claims(rows),
"remaining_blocked_fragments": [
fragment
for plan in plans
for fragment in plan.get("blocked_fragments", [])
if isinstance(fragment, dict)
],
"unresolved_design_decisions": [
item
for plan in plans
for item in plan.get("unresolved_design_decisions", [])
if isinstance(item, dict)
],
"marks_original_proposals_applied": False,
"remaining_blocked_fragments": remaining_blocked_fragments,
"unresolved_design_decisions": unresolved_design_decisions,
"marks_original_proposals_applied": mark_original_proposals_applied,
"applied_by_handle": applied_by_handle if mark_original_proposals_applied else None,
"sql": {
"preflight": build_preflight_sql(plans, rows),
"apply_rollback_rehearsal": build_write_sql(plans, commit=False),
"apply_commit": build_write_sql(plans, commit=True) if emit_commit_sql else None,
"postflight": build_postflight_sql(rows),
"delete_rollback": build_delete_rollback_sql(rows),
"apply_rollback_rehearsal": build_write_sql(
plans,
commit=False,
mark_original_proposals_applied=mark_original_proposals_applied,
applied_by_handle=applied_by_handle,
),
"apply_commit": (
build_write_sql(
plans,
commit=True,
mark_original_proposals_applied=mark_original_proposals_applied,
applied_by_handle=applied_by_handle,
)
if emit_commit_sql
else None
),
"postflight": build_postflight_sql(
rows,
proposal_ids=proposal_ids,
include_original_proposal_readback=mark_original_proposals_applied,
),
"delete_rollback": build_delete_rollback_sql(
rows,
proposal_ids=proposal_ids,
restore_original_proposals_approved=mark_original_proposals_applied,
),
},
}
@ -287,12 +432,30 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
parser.add_argument("--plan-json", required=True, type=Path, help="mapped rich proposal creation plan JSON")
parser.add_argument("--output-dir", type=Path, help="directory to write packet files")
parser.add_argument("--emit-commit-sql", action="store_true", help="also write the authorized COMMIT SQL file")
parser.add_argument(
"--mark-original-proposals-applied",
action="store_true",
help="include guarded ledger SQL to mark original approved proposals applied; requires full coverage",
)
parser.add_argument(
"--applied-by-handle",
default="codex-packet",
help="applied_by_handle value for guarded full-coverage ledger SQL",
)
return parser.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = parse_args(sys.argv[1:] if argv is None else argv)
packet = build_packet(args.plan_json, emit_commit_sql=args.emit_commit_sql)
try:
packet = build_packet(
args.plan_json,
emit_commit_sql=args.emit_commit_sql,
mark_original_proposals_applied=args.mark_original_proposals_applied,
applied_by_handle=args.applied_by_handle,
)
except ValueError as exc:
raise SystemExit(str(exc)) from exc
if args.output_dir:
write_packet_files(packet, args.output_dir)
print(json.dumps({key: value for key, value in packet.items() if key != "sql"}, indent=2, sort_keys=True))

View file

@ -6,13 +6,15 @@ import json
import sys
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import kb_rich_proposal_apply_packet as packet # noqa: E402
def _plan_file(tmp_path: Path) -> Path:
def _plan_file(tmp_path: Path, *, blocked: bool = True) -> Path:
plan = {
"creation_plans": [
{
@ -52,8 +54,8 @@ def _plan_file(tmp_path: Path) -> Path:
}
],
},
"blocked_fragments": [{"kind": "edge", "reasons": ["still blocked"]}],
"unresolved_design_decisions": [{"decision": "non_claim_target"}],
"blocked_fragments": [{"kind": "edge", "reasons": ["still blocked"]}] if blocked else [],
"unresolved_design_decisions": [{"decision": "non_claim_target"}] if blocked else [],
}
]
}
@ -100,3 +102,31 @@ def test_write_packet_files(tmp_path: Path):
summary = json.loads((output_dir / "production-apply-packet.json").read_text())
assert "sql" not in summary
assert summary["proposal_ids"] == ["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]
def test_mark_original_proposal_applied_rejects_partial_packet(tmp_path: Path):
with pytest.raises(ValueError, match="partial packet"):
packet.build_packet(
_plan_file(tmp_path, blocked=True),
emit_commit_sql=True,
mark_original_proposals_applied=True,
)
def test_mark_original_proposal_applied_for_full_packet(tmp_path: Path):
result = packet.build_packet(
_plan_file(tmp_path, blocked=False),
emit_commit_sql=True,
mark_original_proposals_applied=True,
applied_by_handle="codex-test",
)
assert result["marks_original_proposals_applied"] is True
assert result["applied_by_handle"] == "codex-test"
assert "status = 'applied'" in result["sql"]["apply_commit"]
assert "applied_by_handle = 'codex-test'" in result["sql"]["apply_commit"]
assert "expected 1; original proposals were not all approved" in result["sql"]["apply_commit"]
assert "rollback;" in result["sql"]["apply_rollback_rehearsal"]
assert "from kb_stage.kb_proposals" in result["sql"]["postflight"]
assert "status = 'approved'" in result["sql"]["delete_rollback"]
assert "original proposals were not all applied" in result["sql"]["delete_rollback"]