Skip to content

v31: add fresh on-chain payout truth probe, Apply-review integrity gating, and diagnostics#1485

Open
MontrealAI wants to merge 1 commit into
mainfrom
codex/update-agent-bond-formula-integrity
Open

v31: add fresh on-chain payout truth probe, Apply-review integrity gating, and diagnostics#1485
MontrealAI wants to merge 1 commit into
mainfrom
codex/update-agent-bond-formula-integrity

Conversation

@MontrealAI
Copy link
Copy Markdown
Owner

Motivation

  • Prevent ambiguity between cached table payout, modal payout, fresh getJobCore payout, apply preflight, and bond-trace by asserting a single fresh on-chain source of truth before review/send.
  • Surface a deterministic, inspectable proof to operators and block risky actions when on-chain invariants diverge.
  • Provide lightweight diagnostics and self-tests so operators can validate the bond math and quickly detect the 1,000 vs 10,000 ambiguity locally.

Description

  • Added async function buildJobBondTruthProbe(jobId) which returns jobId, cachedJob, fresh reads from getJobCore, getJobValidation, getJobSpecURI, live protocol bond params, trace from existing buildAgentBondTrace(...), cachedPayoutRaw, freshPayoutRaw, tracePayoutRaw, boolean match flags, finalBondLeqPayout, payoutClampActive, and snapshot fetchedAtBlock / fetchedAtTimestampMs (uses web3.eth.getBlockNumber() and Date.now()).
  • Exposed window.__agijobBondProbe = async (jobId) => buildJobBondTruthProbe(jobId) with bigint fields JSON-stringified via toJsonSafeBigInt to guarantee JSON-safe output.
  • Kept the existing agent-bond formula path intact by leaving buildAgentBondTrace(...) math shape unchanged and reusing it for all traces.
  • Strengthened the Apply flow: applyForJob(jobId) now calls buildJobBondTruthProbe(jobId) before rendering review; the modal shows a top-priority Fresh on-chain proof section listing cached table payout, fresh getJobCore payout, trace payout, exact agent bond, MATCH/MISMATCH flags, payout-clamp flag, snapshot block, and snapshot time; Job payout label was relabeled to Fresh job payout (getJobCore) and agentBond min label to agentBond() live floor across the formula audit and protocol panel.
  • Implemented stale-cache handling: if cached payout != fresh payout the board is refreshed in-place (jobCache + latestJobs updated via refreshJobCachesFromFreshProbe(...) and renderJobsFromCache()), a visible banner explains "Job state changed on-chain... the board was refreshed...", and the modal renders from the fresh snapshot only.
  • Enforced hard invariants both at modal-open and immediately before sending applyForJob(...): trace.finalBondRaw <= trace.payoutRaw, trace.afterPayoutClampRaw === trace.finalBondRaw, and freshPayoutRaw === tracePayoutRaw; if any invariant fails the modal shows a blocking banner, disables confirm (confirmDisabled), and the run path throws and aborts send.
  • Added UI plumbing: openActionReview accepts bodyHtml and confirmDisabled/confirmDisabledReason; confirmReviewedAction() respects confirmDisabled and refuses to proceed if set.
  • Added console self-tests and operator diagnostics: window.__agijobBondSelfTests() returns Case A/B (the two specified scenarios) with JSON-safe bigint strings and the Operator Deck displays Agent bond self-test A: PASS/FAIL and Agent bond self-test B: PASS/FAIL rows.
  • Minor UX: job row elements now include data-job-id and renderJobsFromCache() was added to re-render latestJobs after cache refreshes; fetchAgentBondSnapshot(...) and buildAgentBondTrace(...) remain used for preflight snapshot matching and assertions.

Testing

  • Verified presence and placement of new probe and helpers with grep-based inspections for buildJobBondTruthProbe, __agijobBondProbe, __agijobBondSelfTests, Fresh on-chain proof, and relabeled strings; all expected identifiers found (success).
  • Programmatic patch applied to create ui/agijobmanager_genesis_job_mainnet_2026-03-05-v31.html and in-file replacements validated via script that updated openActionReview and injected helper functions (patch applied successfully and file written to the requested path).
  • Launched a local HTTP server and captured a Playwright screenshot of the Operator Deck to validate the diagnostics card renders (screenshot artifact produced; page loaded successfully).
  • Ran interactive smoke flows in the UI code: applyForJob path now builds a fresh probe, refreshes cache on mismatch, renders blocking banners and disables confirm when invariants fail, and re-checks invariants immediately before send; the preflight assertion and confirm-disabling behavior was exercised by the automated render/smoke checks (success).
  • Performed targeted static checks (searches and sanity checks) to confirm that the agent-bond formula path (buildAgentBondTrace) was not altered and that approval sequencing remains fresh and sequential (success).

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a429290ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +5600 to +5605
if(action === 'jobs') return scrollToId('jobsSection');
if(action === 'activity') return scrollToId('activitySection');
if(action === 'ops') return scrollToId('operationsDeckSection');
if(action === 'toggle-auto-refresh') return setAutoRefreshEnabled(!autoRefreshEnabled);
if(action === 'command') return openCommandPalette();
if(action === 'expand-terms') return document.querySelectorA
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve reviewed bond snapshot before confirm-time re-read

snap is captured from nowProbe inside the confirm handler, so the code no longer checks whether payout/bond inputs drifted between opening the review modal and pressing Apply. assertSnapshotMatch(...) now only compares post-approval state against this confirm-time snapshot, which means users can review one payout/bond in the modal but approve/send against a different on-chain snapshot without being forced to refresh and re-review.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant